From 9cc11b8774a9af83650c9cf4d83e45f26b7ef428 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 30 Sep 2012 01:55:26 -0700 Subject: [PATCH] Cleanup build files. Former-commit-id: d19939a34688a8a63979f84eb1a5c5f9c926897b --- build.js | 2 +- build/minify.js | 22 +++++++++------------- build/post-compile.js | 6 +++++- build/pre-compile.js | 14 ++++++++++---- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/build.js b/build.js index 8bfd4b24d..d6ae3204f 100755 --- a/build.js +++ b/build.js @@ -811,7 +811,7 @@ * Creates a debug and minified build, executing the `callback` for each. * The `callback` is invoked with 2 arguments; (filePath, source) * - * @param {Array} [options=[]] The build options array. + * @param {Array} [options=[]] An array of commands. * @param {Function} callback The function called per build. */ function build(options, callback) { diff --git a/build/minify.js b/build/minify.js index bba7047e9..fc3a304b5 100755 --- a/build/minify.js +++ b/build/minify.js @@ -37,16 +37,16 @@ * The exposed `minify` function minifies a given Lo-Dash `source` and invokes * the `onComplete` callback when finished. * - * @param {Array|String} source The array of command-line arguments or the - * source to minify. - * @param {Object} options The options object containing `onComplete`, - * `silent`, and `workingName`. + * @param {Array|String} [source=''] THe source to minify or array of commands. + * @param {Object} [options={}] The options object. */ function minify(source, options) { + source || (source = ''); options || (options = {}); + // juggle arguments if (Array.isArray(source)) { - // convert the command-line arguments to an options object + // convert commands to an options object options = source; var filePath = options[options.length - 1], dirPath = path.dirname(filePath), @@ -62,7 +62,6 @@ var outputPath = path.join(dirPath, workingName + '.js'); source = fs.readFileSync(filePath, 'utf8'); - options = { 'isSilent': isSilent, 'isTemplate': isTemplate, @@ -79,14 +78,11 @@ * * @private * @constructor - * @param {String} [source=''] The source to minify. - * @param {Object} [options={}] The options object containing `onComplete`, - * `silent`, and `workingName`. + * @param {String} source The source to minify. + * @param {Object} options The options object. */ function Minify(source, options) { - source || (source = ''); - options || (options = {}); - + // juggle arguments if (typeof source != 'string') { options = source || options; source = options.source || ''; @@ -105,7 +101,7 @@ this.isSilent = !!options.isSilent; this.isTemplate = !!options.isTemplate; this.onComplete = options.onComplete || function() {}; - this.workingName = options.workingName || 'temp'; + this.workingName = options.workingName; source = preprocess(source, options); this.source = source; diff --git a/build/post-compile.js b/build/post-compile.js index dc40ac2db..477fa6fd1 100644 --- a/build/post-compile.js +++ b/build/post-compile.js @@ -62,7 +62,11 @@ // was invoked directly (e.g. `node post-compile.js source.js`) and write to // the same file (function() { - var filePath = process.argv[2], + var options = process.argv; + if (options.length < 3) { + return; + } + var filePath = options[options.length - 1], source = fs.readFileSync(filePath, 'utf8'); fs.writeFileSync(filePath, postprocess(source), 'utf8'); diff --git a/build/pre-compile.js b/build/pre-compile.js index d990f0e3f..924f684f9 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -245,11 +245,12 @@ /** * Pre-process a given Lo-Dash `source`, preparing it for minification. * - * @param {String} source The source to process. + * @param {String} [source=''] The source to process. * @param {Object} [options={}] The options object. * @returns {String} Returns the processed source. */ function preprocess(source, options) { + source || (source = ''); options || (options = {}); // remove unrecognized JSDoc tags so Closure Compiler won't complain @@ -446,12 +447,17 @@ // was invoked directly (e.g. `node pre-compile.js source.js`) and write to // the same file (function() { - var options = process.argv, - filePath = options[options.length - 1], + var options = process.argv; + if (options.length < 3) { + return; + } + var filePath = options[options.length - 1], isTemplate = options.indexOf('-t') > -1 || options.indexOf('--template') > -1, source = fs.readFileSync(filePath, 'utf8'); - fs.writeFileSync(filePath, preprocess(source, { 'isTemplate': isTemplate }), 'utf8'); + fs.writeFileSync(filePath, preprocess(source, { + 'isTemplate': isTemplate + }), 'utf8'); }()); } }());