|
@@ -16,7 +16,7 @@ import {
|
|
|
* Renders a template folder/file to the provided destination,
|
|
* Renders a template folder/file to the provided destination,
|
|
|
* by recursively copying all files under the source directory,
|
|
* by recursively copying all files under the source directory,
|
|
|
* with the following exception:
|
|
* with the following exception:
|
|
|
- * - `_filename` are renamed to `.filename`.
|
|
|
|
|
|
|
+ * - `_.filename` are renamed to `.filename`.
|
|
|
* - `package.json` files are merged.
|
|
* - `package.json` files are merged.
|
|
|
* - `.gitignore` files are concatenated.
|
|
* - `.gitignore` files are concatenated.
|
|
|
* - `.njk` files are rendered as nunjucks templates
|
|
* - `.njk` files are rendered as nunjucks templates
|
|
@@ -40,6 +40,19 @@ export function renderTemplate(ctx: RenderContext, src: string, dest: string) {
|
|
|
|
|
|
|
|
const filename = path.basename(src);
|
|
const filename = path.basename(src);
|
|
|
|
|
|
|
|
|
|
+ // Rename `_.file` to `.file` in the destination.
|
|
|
|
|
+ if (filename.startsWith('_.')) {
|
|
|
|
|
+ dest = path.resolve(path.dirname(dest), filename.replace(/^_./, '.'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Concatenate .gitignore files.
|
|
|
|
|
+ if (filename === '_.gitignore' && fs.existsSync(dest)) {
|
|
|
|
|
+ const existing = fs.readFileSync(dest, 'utf8');
|
|
|
|
|
+ const newGitignore = fs.readFileSync(src, 'utf8');
|
|
|
|
|
+ fs.writeFileSync(dest, existing + '\n' + newGitignore);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Merge package.json files.
|
|
// Merge package.json files.
|
|
|
if (filename === 'package.json' && fs.existsSync(dest)) {
|
|
if (filename === 'package.json' && fs.existsSync(dest)) {
|
|
|
const existing = JSON.parse(fs.readFileSync(dest, 'utf8'));
|
|
const existing = JSON.parse(fs.readFileSync(dest, 'utf8'));
|
|
@@ -49,14 +62,6 @@ export function renderTemplate(ctx: RenderContext, src: string, dest: string) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Append to existing .gitignore.
|
|
|
|
|
- if (filename === '.gitignore' && fs.existsSync(dest)) {
|
|
|
|
|
- const existing = fs.readFileSync(dest, 'utf8');
|
|
|
|
|
- const newGitignore = fs.readFileSync(src, 'utf8');
|
|
|
|
|
- fs.writeFileSync(dest, existing + '\n' + newGitignore);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// Render nunjucks templates.
|
|
// Render nunjucks templates.
|
|
|
if (filename.endsWith('.njk')) {
|
|
if (filename.endsWith('.njk')) {
|
|
|
dest = dest.replace(/\.njk$/, '');
|
|
dest = dest.replace(/\.njk$/, '');
|