Last active
August 29, 2015 14:19
-
-
Save nemisj/a0f7d6f3784f5f53e20c to your computer and use it in GitHub Desktop.
postcss-cli with yield-yield
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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