From f6eff971cb04972723453cfcbf2754e8373216b6 Mon Sep 17 00:00:00 2001 From: Himanshu Mishra Date: Tue, 6 Jul 2021 14:51:58 +0200 Subject: [PATCH] fetch:template - rename isTemplated to shouldCopyWithoutRender (fix logging bug) and add test todo Co-authored-by: Mike Lewis Signed-off-by: Himanshu Mishra --- .../actions/builtin/fetch/template.test.ts | 2 ++ .../scaffolder/actions/builtin/fetch/template.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts index 48dcb8a06a..179626581a 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts @@ -24,6 +24,8 @@ import { fetchContents } from './helpers'; import { ActionContext, TemplateAction } from '../../types'; import { createFetchTemplateAction, FetchTemplateInput } from './template'; +// TODO(mtlewis/orkohunter): Test handling binary files + jest.mock('./helpers', () => ({ fetchContents: jest.fn(), })); 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 fd2aeac70e..cbe74dc472 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.ts @@ -196,14 +196,16 @@ export function createFetchTemplateAction(options: { ); for (const location of allEntriesInTemplate) { - const isTemplated = !nonTemplatedEntries.has(location); + const shouldCopyWithoutRender = nonTemplatedEntries.has(location); const outputPath = resolvePath( outputDir, - isTemplated ? templater.renderString(location, parameters) : location, + shouldCopyWithoutRender + ? location + : templater.renderString(location, parameters), ); - if (isTemplated) { + if (shouldCopyWithoutRender) { ctx.logger.info( `Copying file/directory ${location} without processing since it matches a pattern in "copyWithoutRender".`, ); @@ -229,9 +231,9 @@ export function createFetchTemplateAction(options: { const inputFileContents = await fs.readFile(inputFilePath, 'utf-8'); await fs.outputFile( outputPath, - isTemplated - ? templater.renderString(inputFileContents, parameters) - : inputFileContents, + shouldCopyWithoutRender + ? inputFileContents + : templater.renderString(inputFileContents, parameters), ); } }