Skip to content

Instantly share code, notes, and snippets.

@nemisj
Last active August 29, 2015 14:19
Show Gist options
  • Save nemisj/a0f7d6f3784f5f53e20c to your computer and use it in GitHub Desktop.
Save nemisj/a0f7d6f3784f5f53e20c to your computer and use it in GitHub Desktop.
postcss-cli with yield-yield
var sync = require('yield-yield');
var processCSS = sync(function* (processor, input, output) {
var result = yield fs.readFile(input, 'utf8', yield);
var css = result[1];
var result = processor.process(css, {
safe: argv.safe,
from: input,
to: output
});
var content;
if (typeof result.then === 'function') {
content = yield result;
} else{
yield process.nextTick(yield);
content = result;
}
if (typeof content.warnings === 'function') {
content.warnings().forEach(console.error);
}
yield fs.writeFile(output, content, yield);
});
sync.run(function* () {
for (var i = 0; i < argv._.length; i++) {
var output = argv.output;
if(!output) {
output = path.join(argv.dir, path.basename(input));
}
var res = yield processCSS(processor, input, output);
if (!res[0]) { continue; }
if (err.message && typeof err.showSourceCode === 'function') {
console.error(err.message, err.showSourceCode());
} else {
console.error(err);
}
process.exit(1);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment