fetch:template - skip running templater on binary files

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 13:51:59 +02:00
parent ef07bce298
commit a8c83700eb
3 changed files with 16 additions and 1 deletions
+1
View File
@@ -52,6 +52,7 @@
"globby": "^11.0.0",
"handlebars": "^4.7.6",
"helmet": "^4.0.0",
"isbinaryfile": "^4.0.8",
"isomorphic-git": "^1.8.0",
"jsonschema": "^1.2.6",
"knex": "^0.95.1",
@@ -23,6 +23,7 @@ import { createTemplateAction } from '../../createTemplateAction';
import globby from 'globby';
import nunjucks from 'nunjucks';
import fs from 'fs-extra';
import { isBinaryFile } from 'isbinaryfile';
/*
* Maximise compatibility with Jinja (and therefore cookiecutter)
@@ -196,6 +197,7 @@ export function createFetchTemplateAction(options: {
for (const location of allEntriesInTemplate) {
const isTemplated = !nonTemplatedEntries.has(location);
const outputPath = resolvePath(
outputDir,
isTemplated ? templater.renderString(location, parameters) : location,
@@ -215,9 +217,16 @@ export function createFetchTemplateAction(options: {
'utf-8',
);
const isBinary = await isBinaryFile(Buffer.from(inputFileContents));
if (isBinary) {
ctx.logger.info(
`Not running templater on contents of ${location} since it is a binary file.`,
);
}
await fs.outputFile(
outputPath,
isTemplated
isTemplated && !isBinary
? templater.renderString(inputFileContents, parameters)
: inputFileContents,
);