2017-02-19 03:12:17 +00:00
|
|
|
"use strict";
|
2017-02-26 01:08:25 +00:00
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
2017-02-19 03:12:17 +00:00
|
|
|
require("typings-global");
|
|
|
|
const handlebars = require("handlebars");
|
|
|
|
const smartfile = require("smartfile");
|
|
|
|
const path = require("path");
|
2017-02-26 01:08:25 +00:00
|
|
|
/**
|
|
|
|
* registers a directory of partials to make them available within handlebars compilation
|
|
|
|
*/
|
2017-02-19 03:12:17 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2017-02-26 01:08:25 +00:00
|
|
|
/**
|
|
|
|
* compiles a directory and outputs it
|
|
|
|
*/
|
|
|
|
exports.compileDirectory = (originDirPathArg, destinationDirPathArg, dataFileNameArg) => __awaiter(this, void 0, void 0, function* () {
|
2017-02-19 03:12:17 +00:00
|
|
|
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'));
|
|
|
|
}
|
2017-02-26 01:08:25 +00:00
|
|
|
});
|
|
|
|
/**
|
|
|
|
* get a template for a file on disk
|
|
|
|
*/
|
|
|
|
exports.getTemplateForFile = (filePathArg) => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
let filePathAbsolute = path.resolve(filePathArg);
|
|
|
|
return handlebars.compile(smartfile.fs.toStringSync(filePathAbsolute));
|
|
|
|
});
|
2017-02-26 01:09:41 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSwwQkFBdUI7QUFDdkIseUNBQXdDO0FBQ3hDLHVDQUFzQztBQUN0Qyw2QkFBNEI7QUFHNUI7O0dBRUc7QUFDUSxRQUFBLGtCQUFrQixHQUFHLENBQUMsVUFBa0I7SUFDakQsU0FBUyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsVUFBVSxFQUFFLFVBQVUsQ0FBQyxDQUFDLElBQUksQ0FBQyxlQUFlO1FBQ3BFLEdBQUcsQ0FBQyxDQUFDLElBQUksV0FBVyxJQUFJLGVBQWUsQ0FBQyxDQUFDLENBQUM7WUFDeEMsS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