You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
955 B

/* eslint-disable no-param-reassign */
const extend = require('deep-extend');
const ejs = require('ejs');
const { isBinaryFileSync } = require('isbinaryfile');
function render(contents, filename, context, tplSettings) {
let result;
const contentsBuffer = Buffer.from(contents, 'binary');
if (isBinaryFileSync(contentsBuffer, contentsBuffer.length)) {
result = contentsBuffer;
} else {
result = ejs.render(
contents.toString(),
context,
// Setting filename by default allow including partials.
extend({ filename }, tplSettings),
);
}
return result;
}
module.exports = function copyTpl(from, to, context, tplSettings, options) {
context = context || {};
tplSettings = tplSettings || {};
this.copy(
from,
to,
extend(options || {}, {
process(contents, filename) {
return render(contents, filename, context, tplSettings);
},
}),
context,
tplSettings,
);
};