Scaffolder: add some todos and comments to fetch:template action
Co-authored-by: Himanshu Mishra <himanshu@orkohunter.net> Signed-off-by: Mike Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
committed by
Himanshu Mishra
parent
9b3c9c16d5
commit
01e13e173d
@@ -52,7 +52,7 @@ export function createFetchTemplateAction(options: {
|
||||
targetPath: {
|
||||
title: 'Target Path',
|
||||
description:
|
||||
'Target path within the working directory to download the contents to.',
|
||||
'Target path within the working directory to download the contents to. Defaults to the working directory root.',
|
||||
type: 'string',
|
||||
},
|
||||
values: {
|
||||
@@ -60,6 +60,10 @@ export function createFetchTemplateAction(options: {
|
||||
description: 'Values to pass on to the templating engine',
|
||||
type: 'object',
|
||||
},
|
||||
// TODO(mtlewis/orkohunter): add copyWithoutRender support
|
||||
//
|
||||
// TODO(mtlewis/orkohunter): do we need to replicate the template extensions support
|
||||
// from fetch:cookiecutter?
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -85,15 +89,21 @@ export function createFetchTemplateAction(options: {
|
||||
outputPath: templateDir,
|
||||
});
|
||||
|
||||
// at this point the templateDir contains the unprocessed contents of the skeleton directory
|
||||
|
||||
ctx.logger.info(
|
||||
'Fetched template, beginning templating process with values',
|
||||
ctx.input.values,
|
||||
);
|
||||
|
||||
// Grab some files
|
||||
//
|
||||
// TODO(mtlewis/orkohunter) handle subdirectories
|
||||
const allFilesInTemplates = await globby(`*`, { cwd: templateDir });
|
||||
|
||||
// Nice for Cookiecutter compat
|
||||
//
|
||||
// TODO(mtlewis/orkohunter): parameterize all jinja2/cookiecutter compat
|
||||
nunjucks.installJinjaCompat();
|
||||
|
||||
// Create a templater
|
||||
@@ -105,11 +115,14 @@ export function createFetchTemplateAction(options: {
|
||||
autoescape: false,
|
||||
});
|
||||
|
||||
// Need to work out how to autoescape but not this
|
||||
// TODO(mtlewis/orkohunter) Need to work out how to autoescape but not this
|
||||
templater.addFilter('jsonify', s => JSON.stringify(s));
|
||||
|
||||
for (const location of allFilesInTemplates) {
|
||||
// handle variables in filenames
|
||||
const filepath = templater.renderString(location, ctx.input.values);
|
||||
|
||||
// write file
|
||||
await fs.writeFile(
|
||||
resolvePath(outputPath, filepath),
|
||||
templater.renderString(
|
||||
@@ -118,6 +131,8 @@ export function createFetchTemplateAction(options: {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// TODO(mtlewis/orkohunter) log success
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user