mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07: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
|
||||
~~~
|
||||
|
||||
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
|
||||
node build include=each,filter,map,noConflict
|
||||
node build include="each, filter, map, noConflict"
|
||||
node build mobile include=each,filter,map,noConflict
|
||||
node build category=collections,functions
|
||||
node build category="collections, functions"
|
||||
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
|
||||
node build exclude=isNaN,isUndefined,union,zip
|
||||
node build exclude="isNaN, isUndefined, union, zip"
|
||||
node build mobile exclude=isNaN,isUndefined,union,zip
|
||||
node build include=each,filter,map
|
||||
node build include="each, filter, map"
|
||||
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`.
|
||||
|
||||
48
build.js
48
build.js
@@ -60,7 +60,7 @@
|
||||
'after': [],
|
||||
'bind': [],
|
||||
'bindAll': ['bind'],
|
||||
'chain': [],
|
||||
'chain': ['mixin'],
|
||||
'clone': ['extend', 'isArray'],
|
||||
'compact': [],
|
||||
'compose': [],
|
||||
@@ -143,18 +143,38 @@
|
||||
'zip': ['max', 'pluck']
|
||||
};
|
||||
|
||||
/** Names of methods to filter for the build */
|
||||
var filterMethods = Object.keys(dependencyMap);
|
||||
/** Names of all methods */
|
||||
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) {
|
||||
if (!result) {
|
||||
var pair = value.match(/^(exclude|include)=(.*)$/);
|
||||
if (pair) {
|
||||
filterMethods = lodash.intersection(filterMethods, pair[2].split(/, */).map(getRealName));
|
||||
return pair[1];
|
||||
}
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
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) {
|
||||
return source;
|
||||
}
|
||||
|
||||
// remove function
|
||||
source = source.replace(matchFunction(source, funcName), '');
|
||||
|
||||
@@ -361,25 +380,26 @@
|
||||
|
||||
// custom build
|
||||
(function() {
|
||||
// exit early if "exclude" or "include" options aren't specified
|
||||
// exit early if "category", "exclude", or "include" options aren't specified
|
||||
if (!filterType) {
|
||||
return;
|
||||
}
|
||||
// remove the specified functions and their dependants
|
||||
if (filterType == 'exclude') {
|
||||
// remove the specified functions and their dependants
|
||||
filterMethods.forEach(function(funcName) {
|
||||
getDependants(funcName).concat(funcName).forEach(function(otherName) {
|
||||
source = removeFunction(source, otherName);
|
||||
});
|
||||
});
|
||||
}
|
||||
// else remove all but the specified functions and their dependencies
|
||||
else {
|
||||
// add dependencies to `filterMethods`
|
||||
filterMethods = lodash.uniq(filterMethods.reduce(function(result, funcName) {
|
||||
result.push.apply(result, getDependencies(funcName).concat(funcName));
|
||||
return result;
|
||||
}, []));
|
||||
|
||||
// remove methods not included in `filterMethods`
|
||||
lodash.each(dependencyMap, function(dependencies, otherName) {
|
||||
if (filterMethods.indexOf(otherName) < 0) {
|
||||
source = removeFunction(source, otherName);
|
||||
|
||||
Reference in New Issue
Block a user