const Handlebars = require("handlebars"); const handlebarsCompiler = Handlebars.compile; function compileTemplates(config, item) { return new Promise(function(resolve) { resolve({ ...item, template: handlebarsCompiler(item.content) }); }); } compileTemplates.withConfig = function(config) { if (config.helpers) { console.log("Helpers:", config.helpers); config.helpers.map(helper => { console.log("helper:", eval(helper.content.toString())); const evalledhelper = require("../../" + helper.path); Handlebars.registerHelper(helper.name, eval(helper.content.toString())); }); } if (config.partials) { config.partials.map(partial => Handlebars.registerPartial(partial.name, partial.content) ); } return item => compileTemplates(config, item); }; module.exports = compileTemplates;