38 lines
907 B
JavaScript
38 lines
907 B
JavaScript
// var dust = require("dustjs-linkedin");
|
|
var dust = require("dustjs-helpers");
|
|
var fs = require("fs");
|
|
const path = require("path");
|
|
|
|
var argv = process.argv.slice(2);
|
|
if (argv.length < 1) {
|
|
console.error("Expecting only 1 argument (a path to a template)");
|
|
process.exit(1);
|
|
}
|
|
var context = JSON.parse(fs.readFileSync(0, "utf-8"));
|
|
var main_template = path.parse(argv[0])["name"];
|
|
|
|
for (var i = 0, len = argv.length; i < len; ++i) {
|
|
var filename = path.parse(argv[i])["name"];
|
|
|
|
try {
|
|
var template_source = fs.readFileSync(argv[i], "utf-8");
|
|
} catch (err) {
|
|
console.error(err);
|
|
process.exit(1);
|
|
}
|
|
|
|
var compiled_template = dust.compile(template_source, filename);
|
|
dust.loadSource(compiled_template);
|
|
|
|
}
|
|
|
|
dust.render(main_template, context, function(err, out) {
|
|
if(err) {
|
|
console.error(err);
|
|
process.exit(1);
|
|
} else {
|
|
console.log(out);
|
|
process.exit(0);
|
|
}
|
|
});
|