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,
);
+5
View File
@@ -15996,6 +15996,11 @@ isarray@^2.0.5:
resolved "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz#8af1e4c1221244cc62459faf38940d4e644a5723"
integrity sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==
isbinaryfile@^4.0.8:
version "4.0.8"
resolved "https://registry.npmjs.org/isbinaryfile/-/isbinaryfile-4.0.8.tgz#5d34b94865bd4946633ecc78a026fc76c5b11fcf"
integrity sha512-53h6XFniq77YdW+spoRrebh0mnmTxRPTlcuIArO57lmMdq4uBKFKaeTjnb92oYWrSn/LVL+LT+Hap2tFQj8V+w==
isexe@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"