mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-14 12:47:49 +00:00
Add "underscore" build.
Former-commit-id: 44e9f4543631cbf342ae7571cf540214623352db
This commit is contained in:
49
build.js
49
build.js
@@ -11,7 +11,7 @@
|
|||||||
/** The current working directory */
|
/** The current working directory */
|
||||||
var cwd = process.cwd();
|
var cwd = process.cwd();
|
||||||
|
|
||||||
/** Flag used to specify a backbone build */
|
/** Flag used to specify a Backbone build */
|
||||||
var isBackbone = process.argv.indexOf('backbone') > -1;
|
var isBackbone = process.argv.indexOf('backbone') > -1;
|
||||||
|
|
||||||
/** Flag used to specify a legacy build */
|
/** Flag used to specify a legacy build */
|
||||||
@@ -26,6 +26,9 @@
|
|||||||
*/
|
*/
|
||||||
var isStrict = process.argv.indexOf('strict') > -1;
|
var isStrict = process.argv.indexOf('strict') > -1;
|
||||||
|
|
||||||
|
/** Flag used to specify an Underscore build */
|
||||||
|
var isUnderscore = process.argv.indexOf('underscore') > -1;
|
||||||
|
|
||||||
/** Flag used to specify if the build should include the "use strict" directive */
|
/** Flag used to specify if the build should include the "use strict" directive */
|
||||||
var useStrict = isStrict || !(isLegacy || isMobile);
|
var useStrict = isStrict || !(isLegacy || isMobile);
|
||||||
|
|
||||||
@@ -256,6 +259,13 @@
|
|||||||
includeMethods,
|
includeMethods,
|
||||||
allMethods = Object.keys(dependencyMap);
|
allMethods = Object.keys(dependencyMap);
|
||||||
|
|
||||||
|
var underscoreMethods = lodash.without.apply(lodash, [allMethods].concat([
|
||||||
|
'drop',
|
||||||
|
'forIn',
|
||||||
|
'forOwn',
|
||||||
|
'partial'
|
||||||
|
]));
|
||||||
|
|
||||||
/** Used to specify whether filtering is for exclusion or inclusion */
|
/** Used to specify whether filtering is for exclusion or inclusion */
|
||||||
var filterType = process.argv.reduce(function(result, value) {
|
var filterType = process.argv.reduce(function(result, value) {
|
||||||
if (result) {
|
if (result) {
|
||||||
@@ -293,11 +303,13 @@
|
|||||||
' lodash legacy Build tailored for older browsers without ES5 support',
|
' lodash legacy Build tailored for older browsers without ES5 support',
|
||||||
' lodash mobile Build with IE < 9 bug fixes and method compilation removed',
|
' lodash mobile Build with IE < 9 bug fixes and method compilation removed',
|
||||||
' lodash strict Build with `_.bindAll`, `_.defaults`, and `_.extend` in strict mode',
|
' lodash strict Build with `_.bindAll`, `_.defaults`, and `_.extend` in strict mode',
|
||||||
|
' lodash underscore Build containing only methods included in Underscore',
|
||||||
' lodash category=... Comma separated categories of methods to include in the build',
|
' lodash category=... Comma separated categories of methods to include in the build',
|
||||||
' lodash exclude=... Comma separated names of methods to exclude from the build',
|
' lodash exclude=... Comma separated names of methods to exclude from the build',
|
||||||
' lodash include=... Comma separated names of methods to include in the build',
|
' lodash include=... Comma separated names of methods to include in the build',
|
||||||
'',
|
'',
|
||||||
' All arguments, except `exclude` with `include` and `legacy` with `mobile`, may be combined.',
|
' All arguments, except `backbone` with `underscore`, `exclude` with `include`,',
|
||||||
|
' and `legacy` with `mobile`, may be combined.',
|
||||||
'',
|
'',
|
||||||
' Options:',
|
' Options:',
|
||||||
'',
|
'',
|
||||||
@@ -630,25 +642,36 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// Backbone build
|
// add methods required by Backbone or Underscore
|
||||||
if (isBackbone) {
|
[
|
||||||
|
{ 'flag': isBackbone, 'methodNames': backboneDependencies },
|
||||||
|
{ 'flag': isUnderscore, 'methodNames': underscoreMethods }
|
||||||
|
]
|
||||||
|
.some(function(data) {
|
||||||
|
var flag = data.flag,
|
||||||
|
methodNames = data.methodNames;
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// add any additional sub-dependencies
|
// add any additional sub-dependencies
|
||||||
backboneDependencies = getDependencies(backboneDependencies);
|
methodNames = getDependencies(methodNames);
|
||||||
|
|
||||||
if (filterType == 'exclude') {
|
if (filterType == 'exclude') {
|
||||||
// remove excluded methods from `backboneDependencies`
|
// remove excluded methods from `methodNames`
|
||||||
includeMethods = lodash.without.apply(lodash, [backboneDependencies].concat(excludeMethods));
|
includeMethods = lodash.without.apply(lodash, [methodNames].concat(excludeMethods));
|
||||||
}
|
}
|
||||||
else if (filterType) {
|
else if (filterType) {
|
||||||
// merge backbone dependencies into `includeMethods`
|
// merge `methodNames` into `includeMethods`
|
||||||
includeMethods = lodash.union(includeMethods, backboneDependencies);
|
includeMethods = lodash.union(includeMethods, methodNames);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// include only the Backbone dependencies
|
// include only the `methodNames`
|
||||||
includeMethods = backboneDependencies;
|
includeMethods = methodNames;
|
||||||
}
|
}
|
||||||
filterType = 'include';
|
filterType = 'include';
|
||||||
}
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -988,7 +1011,7 @@
|
|||||||
source = source.replace(/^ *;\n/gm, '');
|
source = source.replace(/^ *;\n/gm, '');
|
||||||
|
|
||||||
// begin the minification process
|
// begin the minification process
|
||||||
if (filterType || isBackbone || isLegacy || isMobile || isStrict) {
|
if (filterType || isBackbone || isLegacy || isMobile || isStrict || isUnderscore) {
|
||||||
fs.writeFileSync(path.join(cwd, 'lodash.custom.js'), source);
|
fs.writeFileSync(path.join(cwd, 'lodash.custom.js'), source);
|
||||||
|
|
||||||
minify(source, 'lodash.custom.min', function(result) {
|
minify(source, 'lodash.custom.min', function(result) {
|
||||||
|
|||||||
Reference in New Issue
Block a user