#!/usr/bin/env node var juice = require('..'); var cli = require('../lib/cli'); var xtend = require('deep-extend'); var fs = require('fs'); var path = require('path'); var program = cli.getProgram(); if (program.args < 2) { program.help(); } var inputFile = program.args[0]; var outputFile = program.args[1]; var options = cli.argsToOptions(program); var queue = []; if (options.optionsFile) { var optionsFromFile = require(path.resolve(process.cwd(),options.optionsFile)); options = xtend({}, optionsFromFile, options); } if (options.cssFile) { queue.push(function() { fs.readFile(options.cssFile, function(err, css) { if (handleError(err)) { return; } options.extraCss = css.toString(); next(); }); }); } next(); function doJuice() { delete options.cssFile; delete options.optionsFile; juice.juiceFile(inputFile, options, function(err, html) { if (handleError(err)) { return; } fs.writeFile(outputFile, html, handleError); }); } function next() { if (queue.length) { return queue.pop()(); } doJuice(); } function handleError(err) { if (err) { console.error(err.stack); process.exit(1); } return !!err; }