From c6420a910d7e2d3ced3e80485e351d6c2e0c90cb Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 21 May 2013 09:14:37 -0700 Subject: [PATCH] Cleanup `getJavaOptions` in build/minify.js. Former-commit-id: 74a6ddf40eadcfd66c0da243d2496b45bc89d8a1 --- build/minify.js | 57 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/build/minify.js b/build/minify.js index 4d9c8997f..b6c5d7654 100755 --- a/build/minify.js +++ b/build/minify.js @@ -59,32 +59,6 @@ }; }()); - /** - * Retrieves the Java command-line options used for faster minification by - * the Closure Compiler, invoking the `callback` when finished. Subsequent - * invocations will lazily return the original options. The callback is - * invoked with one argument: `(javaOptions)`. - * - * See https://code.google.com/p/closure-compiler/wiki/FAQ#What_are_the_recommended_Java_VM_command-line_options?. - * - * @param {Function} callback The function called once the options have - * been retrieved. - */ - function getJavaOptions(callback) { - var javaOptions = []; - cp.exec('java -version -client -d32', function(error) { - if (!error && process.platform != 'win32') { - javaOptions.push('-client', '-d32'); - } - getJavaOptions = function getJavaOptions(callback) { - process.nextTick(function () { - callback(javaOptions); - }); - }; - callback(javaOptions); - }); - } - /** The Closure Compiler optimization modes */ var optimizationModes = { 'simple': 'SIMPLE_OPTIMIZATIONS', @@ -350,6 +324,30 @@ }); } + /** + * Retrieves the Java command-line options used for faster minification by + * the Closure Compiler, invoking the `callback` when finished. Subsequent + * calls will lazily return the previously retrieved options. The `callback` + * is invoked with one argument; (options). + * + * See https://code.google.com/p/closure-compiler/wiki/FAQ#What_are_the_recommended_Java_VM_command-line_options?. + * + * @private + * @param {Function} callback The function called once the options have been retrieved. + */ + function getJavaOptions(callback) { + var result = []; + cp.exec('java -version -client -d32', function(error) { + if (!error && process.platform != 'win32') { + result.push('-client', '-d32'); + } + getJavaOptions = function(callback) { + _.defer(callback, result); + }; + callback(result); + }); + } + /** * Resolves the source map path from the given output path. * @@ -376,6 +374,7 @@ var filePath = this.filePath, isAdvanced = mode == 'advanced', isMapped = this.isMapped, + isSilent = this.isSilent, options = closureOptions.slice(), outputPath = this.outputPath, mapPath = getMapPath(outputPath), @@ -402,9 +401,9 @@ options.push('--create_source_map=' + mapPath, '--source_map_format=V3'); } - getJavaOptions(function onJavaOptions(javaOptions) { + getJavaOptions(function(javaOptions) { var compiler = cp.spawn('java', javaOptions.concat('-jar', closurePath, options)); - if (!this.isSilent) { + if (!isSilent) { console.log('Compressing ' + path.basename(outputPath, '.js') + ' using the Closure Compiler (' + mode + ')...'); } @@ -454,7 +453,7 @@ // proxy the standard input to the Closure Compiler compiler.stdin.end(source); - }.bind(this)); + }); } /**