Spawn a child process using co. Kind of like exec, except you can write to stdin and there aren't as many options like timeout or encoding.
Minify a Javascript in a child process. Useful when the JS files are large and you don't want uglifyjs blocking the event loop.
varfs=require('fs')varco=require('co')varspawn=require('co-child-process')// resolve the location of the binaryvaruglifyjs=require.resolve('uglify-js/bin/uglifyjs')co(function*(){varstream=fs.createReadStream(__filename)varminified=yieldspawn(uglifyjs,['-'// tells uglifyjs to check for `stdin`]).pump(stream)// since you can't pipe into the generator})()A wrapper around child_process.spawn. The arguments are simply passed and are not touched.
Output is always a string, for now.
Pump a stream into the child process' stdin. Kind of like .pipe() but in the opposite direction.
Must be called on the same tick.
Write a buffer or string body to stdin.
varout=yieldspawn(uglifyjs,['-']).end('var a = 1;')Must be called on the same tick.