fetch:template - rename isTemplated to shouldCopyWithoutRender

(fix logging bug) and add test todo

Co-authored-by: Mike Lewis <mtlewis@users.noreply.github.com>
Signed-off-by: Himanshu Mishra <himanshu@orkohunter.net>
This commit is contained in:
Himanshu Mishra
2021-07-06 14:51:58 +02:00
parent 5f7e7db19d
commit f6eff971cb
2 changed files with 10 additions and 6 deletions
@@ -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(),
}));
@@ -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),
);
}
}