UNPKG

1.31 kBJavaScriptView Raw
1"use strict";
2var handlebars = require("handlebars");
3var fs = require("fs");
4var templates_1 = require("./templates");
5exports.loadFromPath = function (filePath) {
6 if (fs.existsSync(filePath)) {
7 return fs.readFileSync(filePath, 'utf8');
8 }
9 else {
10 throw new Error("Template file " + filePath + " does not exists!");
11 }
12};
13var getGeneratorTemplate = function (templateName) {
14 return templates_1.getGenerators().find(function (item) { return (item.aliases || []).indexOf(templateName.toLowerCase()) > -1; });
15};
16exports.getTemplateGenerator = function (template) {
17 return new Promise(function (resolve, reject) {
18 var generatorTemplate = getGeneratorTemplate(template);
19 if (generatorTemplate) {
20 resolve(generatorTemplate);
21 }
22 else {
23 var allowedTemplates = templates_1.getGenerators().map(function (item) { return item.aliases; }).reduce(function (a, b) { return a.concat(b); }).join(', ');
24 reject("Unknown template language specified: " + template + ", available are: " + allowedTemplates);
25 }
26 });
27};
28exports.compileTemplate = function (compileContext, templatePath) {
29 return handlebars.compile(exports.loadFromPath(templatePath))(compileContext);
30};
31//# sourceMappingURL=template-loader.js.map
\No newline at end of file