From 01e13e173d49829b92be42ca49eb065ea1a6304b Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Fri, 2 Jul 2021 10:05:22 +0100 Subject: [PATCH] Scaffolder: add some todos and comments to fetch:template action Co-authored-by: Himanshu Mishra Signed-off-by: Mike Lewis --- .../actions/builtin/fetch/template.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts index 445f36acbc..705f7aa138 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts @@ -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 }, }); }