diff --git a/build.js b/build.js index 4ddd662cb..302837fb4 100755 --- a/build.js +++ b/build.js @@ -40,59 +40,6 @@ /*--------------------------------------------------------------------------*/ - /** - * Invokes a process with the given `name`, `parameters`, and `source` (used as - * the standard input). Yields the result to a `callback` function. The optional - * `encoding` argument specifies the output stream encoding. - * - * @private - * @param {String} name The name of the process. - * @param {Array} parameters An array of arguments to proxy to the process. - * @param {String} source The standard input to proxy to the process. - * @param {String} [encoding] The expected encoding of the output stream. - * @param {Function} callback The function to call once the process completes. - */ - function invoke(name, parameters, source, encoding, callback) { - // the standard error stream, standard output stream, and process instance - var error = '', - output = '', - process = spawn(name, parameters); - - // juggle arguments - if (typeof encoding == 'string') { - // explicitly set the encoding of the output stream if one is specified - process.stdout.setEncoding(encoding); - } else { - callback = encoding; - encoding = null; - } - - process.stdout.on('data', function(data) { - // append the data to the output stream - output += data; - }); - - process.stderr.on('data', function(data) { - // append the error message to the error stream - error += data; - }); - - process.on('exit', function(status) { - var exception = null; - // `status` contains the process exit code - if (status) { - exception = new Error(error); - exception.status = status; - } - callback(exception, output); - }); - - // proxy the standard input to the process - process.stdin.end(source); - } - - /*--------------------------------------------------------------------------*/ - /** * Compresses a `source` string using the Closure Compiler. Yields the * minified result, and any exceptions encountered, to a `callback` function. @@ -103,7 +50,34 @@ */ function closureCompile(source, callback) { console.log('Compressing lodash.js using the Closure Compiler...'); - invoke('java', ['-jar', closurePath].concat(closureOptions), source, callback); + + // the standard error stream, standard output stream, and Closure Compiler process + var error = '', + output = '', + compiler = spawn('java', ['-jar', closurePath].concat(closureOptions)); + + compiler.stdout.on('data', function(data) { + // append the data to the output stream + output += data; + }); + + compiler.stderr.on('data', function(data) { + // append the error message to the error stream + error += data; + }); + + compiler.on('exit', function(status) { + var exception = null; + // `status` contains the process exit code + if (status) { + exception = new Error(error); + exception.status = status; + } + callback(exception, output); + }); + + // proxy the standard input to the Closure Compiler + compiler.stdin.end(source); } /**