enb-bemify-templates
Version:
The ENB tech which compiles BH and BEMXJST templates to the javascript
32 lines (25 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _fs = require("fs");
var fs = _interopRequireWildcard(_fs);
var _mustache = require("mustache");
var _buildFlow = require("enb/lib/build-flow");
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
exports.default = (0, _buildFlow.create)().name("bemify-templates").defineRequiredOption("type").defineRequiredOption("exportName").target("target", "?.templates.js").useFileList(["bh.js", "bemhtml.js", "bemtree.js"]).builder(function (files) {
if (["BH", "BEMHTML", "BEMTREE"].indexOf(this._type) == -1) {
throw new TypeError("Unknown template name");
} else {
var templatePath = "./templates/template.".concat(this._type.toLowerCase()),
template = require(templatePath),
view = {
exportName: this._exportName,
content: files.map(function (file) {
return fs.readFileSync(file.fullname, "utf8");
}).join("\n").replace(/\n/g, "\n ")
};
return (0, _mustache.render)(template, view);
}
}).createTech();
module.exports = exports["default"];