mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Make minify.js support passing minify an array of command-line arguments.
Former-commit-id: fd67d3d6dd8b19c88c74529a33fd50b2fbd0db01
This commit is contained in:
@@ -37,11 +37,32 @@
|
|||||||
* The exposed `minify` function minifies a given Lo-Dash `source` and invokes
|
* The exposed `minify` function minifies a given Lo-Dash `source` and invokes
|
||||||
* the `onComplete` callback when finished.
|
* the `onComplete` callback when finished.
|
||||||
*
|
*
|
||||||
* @param {String} source The source to minify.
|
* @param {Array|String} source The array of command-line arguments or the
|
||||||
|
* source to minify.
|
||||||
* @param {Object} options The options object containing `onComplete`, `silent`,
|
* @param {Object} options The options object containing `onComplete`, `silent`,
|
||||||
* and `workingName`.
|
* and `workingName`.
|
||||||
*/
|
*/
|
||||||
function minify(source, options) {
|
function minify(source, options) {
|
||||||
|
options || (options = {});
|
||||||
|
|
||||||
|
if (Array.isArray(source)) {
|
||||||
|
// convert the command-line arguments to an options object
|
||||||
|
options = source;
|
||||||
|
var filePath = options[options.length - 1],
|
||||||
|
dirPath = path.dirname(filePath),
|
||||||
|
workingName = path.basename(filePath, '.js') + '.min',
|
||||||
|
outputPath = path.join(dirPath, workingName + '.js'),
|
||||||
|
isSilent = options.indexOf('-s') > -1 || options.indexOf('--silent') > -1;
|
||||||
|
|
||||||
|
source = fs.readFileSync(filePath, 'utf8');
|
||||||
|
options = {
|
||||||
|
'silent': isSilent,
|
||||||
|
'workingName': workingName,
|
||||||
|
'onComplete': function(source) {
|
||||||
|
fs.writeFileSync(outputPath, source, 'utf8');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
new Minify(source, options);
|
new Minify(source, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,16 +91,16 @@
|
|||||||
} catch(e) { }
|
} catch(e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
source = preprocess(source);
|
|
||||||
|
|
||||||
this.compiled = {};
|
this.compiled = {};
|
||||||
this.hybrid = {};
|
this.hybrid = {};
|
||||||
this.uglified = {};
|
this.uglified = {};
|
||||||
this.isSilent = !!options.silent;
|
this.isSilent = !!options.silent;
|
||||||
this.onComplete = options.onComplete || function() {};
|
this.onComplete = options.onComplete || function() {};
|
||||||
this.source = source;
|
|
||||||
this.workingName = options.workingName || 'temp';
|
this.workingName = options.workingName || 'temp';
|
||||||
|
|
||||||
|
source = preprocess(source);
|
||||||
|
this.source = source;
|
||||||
|
|
||||||
// begin the minification process
|
// begin the minification process
|
||||||
closureCompile.call(this, source, onClosureCompile.bind(this));
|
closureCompile.call(this, source, onClosureCompile.bind(this));
|
||||||
}
|
}
|
||||||
@@ -358,21 +379,7 @@
|
|||||||
if (options.length < 3) {
|
if (options.length < 3) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
minify(options);
|
||||||
var filePath = options[options.length - 1],
|
|
||||||
dirPath = path.dirname(filePath),
|
|
||||||
workingName = path.basename(filePath, '.js') + '.min',
|
|
||||||
outputPath = path.join(dirPath, workingName + '.js'),
|
|
||||||
isSilent = options.indexOf('-s') > -1 || options.indexOf('--silent') > -1,
|
|
||||||
source = fs.readFileSync(filePath, 'utf8');
|
|
||||||
|
|
||||||
minify(source, {
|
|
||||||
'silent': isSilent,
|
|
||||||
'workingName': workingName,
|
|
||||||
'onComplete': function(source) {
|
|
||||||
fs.writeFileSync(outputPath, source, 'utf8');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user