From 20fcede4406ea29f29c8d2ad7b18180151231da5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 9 Sep 2012 17:26:30 -0700 Subject: [PATCH] Add "-o" and "--output" build options. Former-commit-id: 154c0a6b749ff2439c024602fb9ec781e293f511 --- build.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/build.js b/build.js index 1166c88cc..1fdbcaa72 100755 --- a/build.js +++ b/build.js @@ -746,8 +746,9 @@ }, ''); // used to report invalid command-line arguments - var invalidArgs = _.reject(options.slice(options[0] == 'node' ? 2 : 0), function(value, index) { - if (/^(?:category|exclude|exports|include)=.*$/.test(value)) { + var invalidArgs = _.reject(options.slice(options[0] == 'node' ? 2 : 0), function(value, index, options) { + if (/^(?:-o|--output)$/.test(options[index - 1]) || + /^(?:category|exclude|exports|include)=.*$/.test(value)) { return true; } return [ @@ -765,6 +766,11 @@ ].indexOf(value) > -1; }); + // used to specify the output path for built files + var outputPath = options.reduce(function(result, value, index) { + return result || (/^(?:-o|--output)$/.test(value) ? options[index + 1] : result); + }, ''); + // load customized Lo-Dash module var lodash = (function() { var context = vm.createContext({ @@ -1275,7 +1281,7 @@ // begin the minification process if (!_.isEqual(exportsOptions, exportsAll) || filterType || isBackbone || isLegacy || isMobile || isStrict || isUnderscore) { // output debug build - if (!isStdOut) { + if (!outputPath && !isStdOut) { callback(path.join(cwd, 'lodash.custom.js'), debugSource); } minify(source, { @@ -1290,7 +1296,7 @@ if (isStdOut) { console.log(source); } else { - callback(path.join(cwd, 'lodash.custom.min.js'), source); + callback(outputPath || path.join(cwd, 'lodash.custom.min.js'), source); } } }); @@ -1304,7 +1310,7 @@ if (isStdOut) { console.log(source); } else { - callback(path.join(cwd, 'lodash.min.js'), source); + callback(outputPath || path.join(cwd, 'lodash.min.js'), source); } } });