31 lines
3.5 KiB
JavaScript
31 lines
3.5 KiB
JavaScript
"use strict";
|
|
require("typings-global");
|
|
const handlebars = require("handlebars");
|
|
const smartfile = require("smartfile");
|
|
const path = require("path");
|
|
exports.registerPartialDir = (dirPathArg) => {
|
|
smartfile.fs.listFileTree(dirPathArg, '**/*.hbs').then(hbsFileArrayArg => {
|
|
for (let hbsFilePath of hbsFileArrayArg) {
|
|
let parsedPath = path.parse(hbsFilePath);
|
|
let hbsFileString = smartfile.fs.toStringSync(path.join(dirPathArg, hbsFilePath));
|
|
if (parsedPath.dir === '') {
|
|
parsedPath.name = '/' + parsedPath.name;
|
|
}
|
|
let partialName = `partials${parsedPath.dir}${parsedPath.name}`;
|
|
handlebars.registerPartial(partialName, hbsFileString);
|
|
}
|
|
});
|
|
};
|
|
exports.compileDirectory = (originDirPathArg, destinationDirPathArg, dataFileNameArg) => {
|
|
let hbsFilePathArray = smartfile.fs.listFilesSync(originDirPathArg, /.hbs/);
|
|
let data = smartfile.fs.toObjectSync(path.join(originDirPathArg, dataFileNameArg));
|
|
for (let hbsFilePath of hbsFilePathArray) {
|
|
let parsedPath = path.parse(hbsFilePath);
|
|
let hbsFileString = smartfile.fs.toStringSync(path.join(originDirPathArg, hbsFilePath));
|
|
let template = handlebars.compile(hbsFileString);
|
|
let output = template(data);
|
|
console.log('hi ' + output + ' hi');
|
|
smartfile.memory.toFsSync(output, path.join(destinationDirPathArg, parsedPath.name + '.html'));
|
|
}
|
|
};
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLHlDQUF3QztBQUN4Qyx1Q0FBc0M7QUFDdEMsNkJBQTRCO0FBR2pCLFFBQUEsa0JBQWtCLEdBQUcsQ0FBQyxVQUFrQjtJQ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