Better logging and exit codes.

This commit is contained in:
Matt Swensen 2017-01-04 22:20:04 -07:00
parent 5c9a1b9e7c
commit 849b1fc857

@ -51,12 +51,23 @@ const flatten = arr => [].concat.apply([], arr);
mkdirp.sync(path.resolve(args.out));
console.log('resolving packages...');
Promise.all([args.colors, ...args.template].map(resolvePackage))
.then(requireables => {
const colors = require(requireables[0]).colors;
const templates = requireables.slice(1).map(require);
console.log('rendering templates...');
return Promise.all(flatten(templates.map(template => template.render(colors, args))));
})
.then(files => Promise.all(files.map(file => fs.writeFile(path.resolve(args.out, file.name), file.contents).then(() => console.log(`...${file.name}`)))))
.then(() => console.log('Done!'))
.catch(e => console.error(e));
.then(files => {
console.log('writing files...');
return Promise.all(files.map(file => fs.writeFile(path.resolve(args.out, file.name), file.contents)));
})
.then(() => {
console.log('Done!');
process.exit(0);
})
.catch(e => {
console.error(e);
process.exit(1);
});