mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +00:00
Add category build option.
Former-commit-id: 4adea9367949985a1218cff58ff856184fd11db7
This commit is contained in:
26
README.md
26
README.md
@@ -45,20 +45,28 @@ Mobile builds, with IE bug fixes and method compilation removed, may be created
|
|||||||
node build mobile
|
node build mobile
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
Custom builds may be created in two ways:
|
Custom builds may be created in three ways:
|
||||||
|
|
||||||
1. Use the`include` argument to pass the names of the methods to include in the build.
|
1. Use the `category` argument to pass the categories of methods to include in the build.<br>
|
||||||
|
Valid categories are *"arrays"*, *"chaining"*, *"collections"*, *"functions"*, *"objects"*, and *"utilities"*.
|
||||||
~~~ bash
|
~~~ bash
|
||||||
node build include=each,filter,map,noConflict
|
node build category=collections,functions
|
||||||
node build include="each, filter, map, noConflict"
|
node build category="collections, functions"
|
||||||
node build mobile include=each,filter,map,noConflict
|
node build mobile category=collections,functions
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
2. Use the `exclude` argument to pass the names of the methods to exclude from the build.
|
2. Use the `include` argument to pass the names of the methods to include in the build.
|
||||||
~~~ bash
|
~~~ bash
|
||||||
node build exclude=isNaN,isUndefined,union,zip
|
node build include=each,filter,map
|
||||||
node build exclude="isNaN, isUndefined, union, zip"
|
node build include="each, filter, map"
|
||||||
node build mobile exclude=isNaN,isUndefined,union,zip
|
node build mobile include=each,filter,map
|
||||||
|
~~~
|
||||||
|
|
||||||
|
3. Use the `exclude` argument to pass the names of the methods to exclude from the build.
|
||||||
|
~~~ bash
|
||||||
|
node build exclude=union,uniq,zip
|
||||||
|
node build exclude="union, uniq, zip"
|
||||||
|
node build mobile exclude=union,uniq,zip
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
Custom builds are saved to `lodash.custom.js` and `lodash.custom.min.js`.
|
Custom builds are saved to `lodash.custom.js` and `lodash.custom.min.js`.
|
||||||
|
|||||||
48
build.js
48
build.js
@@ -60,7 +60,7 @@
|
|||||||
'after': [],
|
'after': [],
|
||||||
'bind': [],
|
'bind': [],
|
||||||
'bindAll': ['bind'],
|
'bindAll': ['bind'],
|
||||||
'chain': [],
|
'chain': ['mixin'],
|
||||||
'clone': ['extend', 'isArray'],
|
'clone': ['extend', 'isArray'],
|
||||||
'compact': [],
|
'compact': [],
|
||||||
'compose': [],
|
'compose': [],
|
||||||
@@ -143,18 +143,38 @@
|
|||||||
'zip': ['max', 'pluck']
|
'zip': ['max', 'pluck']
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Names of methods to filter for the build */
|
/** Names of all methods */
|
||||||
var filterMethods = Object.keys(dependencyMap);
|
var allMethods = Object.keys(dependencyMap);
|
||||||
|
|
||||||
/** Used to specify if `filterMethods` should be used for exclusion or inclusion */
|
/** Names of methods to filter for the build */
|
||||||
|
var filterMethods = allMethods;
|
||||||
|
|
||||||
|
/** Used to specify whether `filterMethods` is used for exclusion or inclusion */
|
||||||
var filterType = process.argv.reduce(function(result, value) {
|
var filterType = process.argv.reduce(function(result, value) {
|
||||||
if (!result) {
|
if (result) {
|
||||||
var pair = value.match(/^(exclude|include)=(.*)$/);
|
return result;
|
||||||
if (pair) {
|
|
||||||
filterMethods = lodash.intersection(filterMethods, pair[2].split(/, */).map(getRealName));
|
|
||||||
return pair[1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
var pair = value.match(/^(category|exclude|include)=(.*)$/);
|
||||||
|
if (!pair) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = pair[1];
|
||||||
|
filterMethods = pair[2].split(/, */).map(getRealName);
|
||||||
|
|
||||||
|
if (result == 'category') {
|
||||||
|
// resolve method names belonging to each category
|
||||||
|
filterMethods = filterMethods.reduce(function(result, category) {
|
||||||
|
return result.concat(allMethods.filter(function(funcName) {
|
||||||
|
return RegExp('@category ' + category + '\\b', 'i').test(matchFunction(source, funcName));
|
||||||
|
}));
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// remove nonexistent method names
|
||||||
|
filterMethods = lodash.intersection(allMethods, filterMethods);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}, '');
|
}, '');
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
@@ -295,7 +315,6 @@
|
|||||||
if (!snippet) {
|
if (!snippet) {
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove function
|
// remove function
|
||||||
source = source.replace(matchFunction(source, funcName), '');
|
source = source.replace(matchFunction(source, funcName), '');
|
||||||
|
|
||||||
@@ -361,25 +380,26 @@
|
|||||||
|
|
||||||
// custom build
|
// custom build
|
||||||
(function() {
|
(function() {
|
||||||
// exit early if "exclude" or "include" options aren't specified
|
// exit early if "category", "exclude", or "include" options aren't specified
|
||||||
if (!filterType) {
|
if (!filterType) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// remove the specified functions and their dependants
|
|
||||||
if (filterType == 'exclude') {
|
if (filterType == 'exclude') {
|
||||||
|
// remove the specified functions and their dependants
|
||||||
filterMethods.forEach(function(funcName) {
|
filterMethods.forEach(function(funcName) {
|
||||||
getDependants(funcName).concat(funcName).forEach(function(otherName) {
|
getDependants(funcName).concat(funcName).forEach(function(otherName) {
|
||||||
source = removeFunction(source, otherName);
|
source = removeFunction(source, otherName);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// else remove all but the specified functions and their dependencies
|
|
||||||
else {
|
else {
|
||||||
|
// add dependencies to `filterMethods`
|
||||||
filterMethods = lodash.uniq(filterMethods.reduce(function(result, funcName) {
|
filterMethods = lodash.uniq(filterMethods.reduce(function(result, funcName) {
|
||||||
result.push.apply(result, getDependencies(funcName).concat(funcName));
|
result.push.apply(result, getDependencies(funcName).concat(funcName));
|
||||||
return result;
|
return result;
|
||||||
}, []));
|
}, []));
|
||||||
|
|
||||||
|
// remove methods not included in `filterMethods`
|
||||||
lodash.each(dependencyMap, function(dependencies, otherName) {
|
lodash.each(dependencyMap, function(dependencies, otherName) {
|
||||||
if (filterMethods.indexOf(otherName) < 0) {
|
if (filterMethods.indexOf(otherName) < 0) {
|
||||||
source = removeFunction(source, otherName);
|
source = removeFunction(source, otherName);
|
||||||
|
|||||||
Reference in New Issue
Block a user