From ef07bce298a1fbf8ece1b27635fa9c8504561ca6 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Mon, 5 Jul 2021 18:10:58 +0100 Subject: [PATCH] scaffolder: improve logging in fetch:template Signed-off-by: Mike Lewis --- .../actions/builtin/fetch/template.ts | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 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 54e9888184..0c9b997746 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts @@ -128,18 +128,14 @@ export function createFetchTemplateAction(options: { outputPath: templateDir, }); - ctx.logger.info( - 'Fetched template, beginning templating process with values', - ctx.input.values, - ); - - // Grab some files + ctx.logger.info('Listing files and directories in template'); const allEntriesInTemplate = await globby(`**/*`, { cwd: templateDir, dot: true, onlyFiles: false, markDirectories: true, }); + const nonTemplatedEntries = new Set( ( await Promise.all( @@ -155,15 +151,13 @@ export function createFetchTemplateAction(options: { ).flat(), ); - ctx.logger.info(allEntriesInTemplate); - // Create a templater const templater = nunjucks.configure({ - // TODO(mtlewis/orkohunter): Document Why we are changing the literals? Not here, but on scaffolder docs. ADR? ...(ctx.input.cookiecutterCompat ? {} : { tags: { + // TODO(mtlewis/orkohunter): Document Why we are changing the literals? Not here, but on scaffolder docs. ADR? variableStart: '${{', variableEnd: '}}', }, @@ -195,6 +189,11 @@ export function createFetchTemplateAction(options: { ? { cookiecutter: ctx.input.values } : ctx.input.values; + ctx.logger.info( + `Processing ${allEntriesInTemplate.length} template files/directories with input values`, + ctx.input.values, + ); + for (const location of allEntriesInTemplate) { const isTemplated = !nonTemplatedEntries.has(location); const outputPath = resolvePath( @@ -202,6 +201,12 @@ export function createFetchTemplateAction(options: { isTemplated ? templater.renderString(location, parameters) : location, ); + ctx.logger.info( + `Writing${isTemplated ? ' ' : ' un-templated '}${ + location.endsWith('/') ? 'directory' : 'file' + } ${location} to template output path`, + ); + if (location.endsWith('/')) { await fs.ensureDir(outputPath); } else { @@ -218,6 +223,8 @@ export function createFetchTemplateAction(options: { ); } } + + ctx.logger.info(`Template result written to ${outputDir}`); }, }); }