Skip to content

Instantly share code, notes, and snippets.

@apaleslimghost
Last active August 14, 2016 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apaleslimghost/17eea45ca987fd2acb3ea0cc3eba663b to your computer and use it in GitHub Desktop.
Save apaleslimghost/17eea45ca987fd2acb3ea0cc3eba663b to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const handlebars = require('handlebars');
const hjson = require('hjson');
const minimist = require('minimist');
const fs = require('fs');
const argv = minimist(process.argv.slice(2));
console.assert(argv.t, '-t path/to/template.hbs is required');
const template = fs.readFileSync(argv.t, 'utf8');
const data = (argv.f ? [].concat(argv.f).map(f => fs.readFileSync(f, 'utf8')) : [].concat(argv._ || [])).reduce(
(data, src) => Object.assign(data, hjson.parse(src)),
{}
);
const output = argv.o ? fs.createWriteStream(argv.o) : process.stdout;
output.write(handlebars.compile(template)(data));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment