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.
40 lines
949 B
40 lines
949 B
'use strict';
|
|
|
|
var extend = require('deep-extend');
|
|
var ejs = require('ejs');
|
|
var isBinaryFileSync = require('isbinaryfile').isBinaryFileSync;
|
|
|
|
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: filename}, tplSettings)
|
|
);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
module.exports = function (from, to, context, tplSettings, options) {
|
|
context = context || {};
|
|
tplSettings = tplSettings || {};
|
|
|
|
this.copy(
|
|
from,
|
|
to,
|
|
extend(options || {}, {
|
|
process: function (contents, filename) {
|
|
return render(contents, filename, context, tplSettings);
|
|
}
|
|
}),
|
|
context,
|
|
tplSettings
|
|
);
|
|
};
|
|
|