st-bundle
Version:
CLI for watching and bundling SpringType projects.
28 lines (27 loc) • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function pluginConsolidate(engine, options) {
return async (ctx) => {
if (!ctx.isInstalled('consolidate')) {
ctx.fatal(`Fatal error when trying to use pluginConsolidate`, [
'Module "consolidate" is required, Please install it using the following command',
'npm install consolidate --save-dev',
]);
}
const consolidate = require('consolidate');
ctx.ict.waitFor('before_webindex_write', async (props) => {
if (typeof consolidate[engine] !== 'function') {
ctx.fatal(`The template engine you selected is not available in consolidate: ${engine}`);
}
try {
const processedTemplate = await consolidate[engine](props.filePath, Object.assign(Object.assign({}, options), { bundles: props.bundles }));
props.fileContents = processedTemplate;
}
catch (e) {
ctx.fatal('Error processing the web-index template using consolidate.', [e.message]);
}
return props;
});
};
}
exports.pluginConsolidate = pluginConsolidate;