Rework build.js to work as a module and add a "silent" mode to minify.js.

Former-commit-id: cf62532b957d37da77a2d64aa64d2d388e6382ae
This commit is contained in:
John-David Dalton
2012-09-06 22:04:24 -07:00
parent e3ec76418b
commit fa9df75cf7
2 changed files with 76 additions and 32 deletions

View File

@@ -265,6 +265,7 @@
' Options:',
'',
' -h, --help Display help information',
' -s, --silent Skip printing status updates to the console',
' -V, --version Output current version of Lo-Dash',
''
].join('\n'));
@@ -664,6 +665,9 @@
// flag used to specify a mobile build
var isMobile = !isLegacy && (isCSP || isUnderscore || options.indexOf('mobile') > -1);
// flag used to specify skipping status updates to the console
var isSilent = options.indexOf('-s') > -1 || options.indexOf('--silent') > -1;
// flag used to specify `_.bindAll`, `_.extend`, and `_.defaults` are
// constructed using the "use strict" directive
var isStrict = options.indexOf('strict') > -1;
@@ -1200,17 +1204,25 @@
if (filterType || isBackbone || isLegacy || isMobile || isStrict || isUnderscore) {
callback(path.join(cwd, 'lodash.custom.js'), debugSource);
minify(source, 'lodash.custom.min', function(source) {
if (isStrict) {
// inject "use strict" directive
source = source.replace(/^(\/\*![\s\S]+?\*\/\n;\(function[^)]+\){)([^'"])/, '$1"use strict";$2');
minify(source, {
'silent': isSilent,
'workingName': 'lodash.custom.min',
'onComplete': function(source) {
if (isStrict) {
// inject "use strict" directive
source = source.replace(/^(\/\*![\s\S]+?\*\/\n;\(function[^)]+\){)([^'"])/, '$1"use strict";$2');
}
callback(path.join(cwd, 'lodash.custom.min.js'), postMinify(source));
}
callback(path.join(cwd, 'lodash.custom.min.js'), postMinify(source));
});
}
else {
minify(source, 'lodash.min', function(source) {
callback(path.join(cwd, 'lodash.min.js'), postMinify(source));
minify(source, {
'silent': isSilent,
'workingName': 'lodash.min',
'onComplete': function(source) {
callback(path.join(cwd, 'lodash.min.js'), postMinify(source));
}
});
}
}
@@ -1224,7 +1236,7 @@
else {
// or invoked directly
build(process.argv.slice(2), function(filepath, source) {
fs.writeFileSync(filepath, source);
fs.writeFileSync(filepath, source, 'utf8');
});
}
}());