2020-05-10 17:43:32 +00:00
|
|
|
// var dust = require("dustjs-linkedin");
|
|
|
|
var dust = require("dustjs-helpers");
|
|
|
|
var fs = require("fs");
|
|
|
|
const path = require("path");
|
2020-04-04 22:49:17 +00:00
|
|
|
|
|
|
|
var argv = process.argv.slice(2);
|
2020-04-10 23:07:02 +00:00
|
|
|
if (argv.length < 1) {
|
2020-04-04 22:49:17 +00:00
|
|
|
console.error("Expecting only 1 argument (a path to a template)");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2020-05-10 17:43:32 +00:00
|
|
|
var context = JSON.parse(fs.readFileSync(0, "utf-8"));
|
2020-04-10 23:07:02 +00:00
|
|
|
var main_template = path.parse(argv[0])["name"];
|
2020-04-04 22:49:17 +00:00
|
|
|
|
2020-04-10 23:07:02 +00:00
|
|
|
for (var i = 0, len = argv.length; i < len; ++i) {
|
|
|
|
var filename = path.parse(argv[i])["name"];
|
|
|
|
|
|
|
|
try {
|
2020-05-10 17:43:32 +00:00
|
|
|
var template_source = fs.readFileSync(argv[i], "utf-8");
|
2020-04-10 23:07:02 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2020-04-04 22:49:17 +00:00
|
|
|
|
2020-04-10 23:07:02 +00:00
|
|
|
var compiled_template = dust.compile(template_source, filename);
|
|
|
|
dust.loadSource(compiled_template);
|
|
|
|
|
|
|
|
}
|
2020-04-04 22:49:17 +00:00
|
|
|
|
2020-04-10 23:07:02 +00:00
|
|
|
dust.render(main_template, context, function(err, out) {
|
2020-04-04 22:49:17 +00:00
|
|
|
if(err) {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
} else {
|
|
|
|
console.log(out);
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
});
|