mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +00:00
Reorg build, fp, and lib files.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
var mapping = require('./mapping.js'),
|
||||
var mapping = require('./_mapping'),
|
||||
mutateMap = mapping.mutate,
|
||||
placeholder = {};
|
||||
|
||||
13
fp/_convertBrowser.js
Normal file
13
fp/_convertBrowser.js
Normal file
@@ -0,0 +1,13 @@
|
||||
var baseConvert = require('./_baseConvert');
|
||||
|
||||
/**
|
||||
* Converts `lodash` to an immutable auto-curried iteratee-first data-last version.
|
||||
*
|
||||
* @param {Function} lodash The lodash function.
|
||||
* @returns {Function} Returns the converted `lodash`.
|
||||
*/
|
||||
function browserConvert(lodash) {
|
||||
return baseConvert(lodash, lodash);
|
||||
}
|
||||
|
||||
module.exports = browserConvert;
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
var _ = require('lodash'),
|
||||
async = require('async'),
|
||||
fs = require('fs-extra'),
|
||||
path = require('path'),
|
||||
webpack = require('webpack');
|
||||
|
||||
@@ -10,10 +9,11 @@ var minify = require('../common/minify.js');
|
||||
|
||||
var basePath = path.join(__dirname, '..', '..'),
|
||||
distPath = path.join(basePath, 'dist'),
|
||||
fpPath = path.join(basePath, 'fp'),
|
||||
filename = 'lodash.fp.js';
|
||||
|
||||
var fpConfig = {
|
||||
'entry': path.join(__dirname, 'convert.browser.js'),
|
||||
'entry': path.join(fpPath, '_convertBrowser.js'),
|
||||
'output': {
|
||||
'path': distPath,
|
||||
'filename': filename,
|
||||
@@ -27,7 +27,7 @@ var fpConfig = {
|
||||
};
|
||||
|
||||
var mappingConfig = {
|
||||
'entry': path.join(__dirname, 'mapping.js'),
|
||||
'entry': path.join(fpPath, '_mapping.js'),
|
||||
'output': {
|
||||
'path': distPath,
|
||||
'filename': 'mapping.fp.js',
|
||||
@@ -1,13 +0,0 @@
|
||||
var baseConvert = require('./baseConvert.js');
|
||||
|
||||
/**
|
||||
* Converts `lodash` to an auto-curried iteratee-first data-last version.
|
||||
*
|
||||
* @param {Function} lodash The lodash function.
|
||||
* @returns {Function} Returns the converted lodash function.
|
||||
*/
|
||||
function browserConvert(lodash) {
|
||||
return baseConvert(lodash, lodash);
|
||||
}
|
||||
|
||||
module.exports = browserConvert;
|
||||
@@ -1,21 +0,0 @@
|
||||
var _ = require('lodash'),
|
||||
baseConvert = require('./baseConvert.js'),
|
||||
util = require('./fp-util.js');
|
||||
|
||||
/**
|
||||
* Converts `func` of `name` to an auto-curried iteratee-first data-last version.
|
||||
* If `name` is an object, the methods on it will be converted and the object returned.
|
||||
*
|
||||
* @param {string} [name] The name of the function to wrap.
|
||||
* @param {Function} [func] The function to wrap.
|
||||
* @returns {Function|Object} Returns the converted function or object.
|
||||
*/
|
||||
function convert() {
|
||||
var args = arguments,
|
||||
name = args.length ? args[0] : _.noConflict().runInContext(),
|
||||
func = args[1];
|
||||
|
||||
return baseConvert(util, name, func);
|
||||
}
|
||||
|
||||
module.exports = convert;
|
||||
@@ -1,16 +0,0 @@
|
||||
var baseConvert = require('./baseConvert.js'),
|
||||
util = require('./util.js');
|
||||
|
||||
/**
|
||||
* Converts `func` of `name` to an auto-curried iteratee-first data-last version.
|
||||
* If `name` is an object, the methods on it will be converted and the object returned.
|
||||
*
|
||||
* @param {string} name The name of the function to wrap.
|
||||
* @param {Function} func The function to wrap.
|
||||
* @returns {Function|Object} Returns the converted function or object.
|
||||
*/
|
||||
function nodeConvert(name, func) {
|
||||
return baseConvert(util, name, func);
|
||||
}
|
||||
|
||||
module.exports = nodeConvert;
|
||||
@@ -1,10 +0,0 @@
|
||||
module.exports = {
|
||||
'ary': require('lodash/ary'),
|
||||
'cloneDeep': require('lodash/cloneDeep'),
|
||||
'curry': require('lodash/curry'),
|
||||
'forEach': require('lodash/internal/arrayEach'),
|
||||
'isFunction': require('lodash/isFunction'),
|
||||
'iteratee': require('lodash/iteratee'),
|
||||
'keys': require('lodash/internal/baseKeys'),
|
||||
'rearg': require('lodash/rearg')
|
||||
};
|
||||
@@ -1,95 +0,0 @@
|
||||
var path = require('path');
|
||||
var Module = require('module');
|
||||
var _ = require('lodash/fp');
|
||||
var mutatingAssign = require('lodash').assign;
|
||||
var fs = require('fs');
|
||||
|
||||
var collectionModules = [
|
||||
'array.js',
|
||||
'collection.js',
|
||||
'date.js',
|
||||
'function.js',
|
||||
'lang.js',
|
||||
'math.js',
|
||||
'number.js',
|
||||
'object.js',
|
||||
'string.js',
|
||||
'util.js'
|
||||
];
|
||||
|
||||
var utilityModules = [
|
||||
'util.js', // XXX: Remove! Not actually an utility but a collection module but it interferes testing with the current releases...
|
||||
'lodash.js',
|
||||
'fp.js',
|
||||
'chain.js'
|
||||
];
|
||||
|
||||
var lodashPath = path.dirname(Module._resolveFilename('lodash', mutatingAssign(new Module, {
|
||||
'paths': Module._nodeModulePaths(process.cwd())
|
||||
})));
|
||||
|
||||
var mapping = require(lodashPath + '/fp/mapping');
|
||||
var singleArgFns = mapping.aryMethod[1];
|
||||
|
||||
var extPattern = /\.js$/;
|
||||
var isJSfile = extPattern.test.bind(extPattern);
|
||||
|
||||
var removeJSExt = function(filename) {
|
||||
return filename.replace(extPattern, '');
|
||||
};
|
||||
|
||||
var isCollectionModule = _.includes(_, collectionModules);
|
||||
var isNotUtilityModule = _.negate(_.includes(_, utilityModules));
|
||||
var isSingleArgFn = _.includes(_, singleArgFns);
|
||||
|
||||
var lodashModules = fs.readdirSync(lodashPath)
|
||||
.filter(isJSfile)
|
||||
.filter(isNotUtilityModule)
|
||||
.map(removeJSExt);
|
||||
|
||||
var convertTemplate = _.template(
|
||||
"var convert = require('./convert');\n" +
|
||||
"module.exports = convert('<%= name %>', require('../<%= name %>'));\n"
|
||||
);
|
||||
|
||||
var collectionTemplate = _.template(
|
||||
"var convert = require('./convert');\n" +
|
||||
"module.exports = convert(require('../<%= name %>'));\n"
|
||||
);
|
||||
|
||||
var passThroughTemplate = _.template(
|
||||
"module.exports = require('../<%= name %>');\n"
|
||||
);
|
||||
|
||||
var moduleTemplate = function(name) {
|
||||
var context = {name: name};
|
||||
|
||||
if (isCollectionModule(name + '.js')) {
|
||||
return collectionTemplate(context);
|
||||
}
|
||||
if (isSingleArgFn(name)) {
|
||||
return passThroughTemplate(context);
|
||||
}
|
||||
|
||||
return convertTemplate(context);
|
||||
};
|
||||
|
||||
function precompileFpWrappers(target) {
|
||||
_.forEach(function(moduleName) {
|
||||
fs.writeFileSync(
|
||||
path.join(target, moduleName + '.js'),
|
||||
moduleTemplate(moduleName)
|
||||
);
|
||||
}, lodashModules);
|
||||
|
||||
_.forEach(function(aliases, origName) {
|
||||
_.forEach(function aliasName() {
|
||||
fs.writeFileSync(
|
||||
path.join(target, aliasName + '.js'),
|
||||
moduleTemplate(origName)
|
||||
);
|
||||
}, aliases);
|
||||
}, mapping.alias);
|
||||
}
|
||||
|
||||
module.exports = precompileFpWrappers;
|
||||
10
lib/fp/template/_util.jst
Normal file
10
lib/fp/template/_util.jst
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
'ary': require('../ary'),
|
||||
'cloneDeep': require('../cloneDeep'),
|
||||
'curry': require('../curry'),
|
||||
'forEach': require('../internal/arrayEach'),
|
||||
'isFunction': require('../isFunction'),
|
||||
'iteratee': require('../iteratee'),
|
||||
'keys': require('../internal/baseKeys'),
|
||||
'rearg': require('../rearg')
|
||||
};
|
||||
16
lib/fp/template/convert.jst
Normal file
16
lib/fp/template/convert.jst
Normal file
@@ -0,0 +1,16 @@
|
||||
var baseConvert = require('./_baseConvert'),
|
||||
util = require('./_util');
|
||||
|
||||
/**
|
||||
* Converts `func` of `name` to an immutable auto-curried iteratee-first data-last
|
||||
* version. If `name` is an object its methods will be converted.
|
||||
*
|
||||
* @param {string} name The name of the function to wrap.
|
||||
* @param {Function} [func] The function to wrap.
|
||||
* @returns {Function|Object} Returns the converted function or object.
|
||||
*/
|
||||
function convert(name, func) {
|
||||
return baseConvert(util, name, func);
|
||||
}
|
||||
|
||||
module.exports = convert;
|
||||
@@ -13,6 +13,7 @@
|
||||
"dojo": "^1.10.4",
|
||||
"ecstatic": "^1.4.0",
|
||||
"fs-extra": "~0.26.4",
|
||||
"glob": "^6.0.4",
|
||||
"istanbul": "0.4.2",
|
||||
"jquery": "^2.2.0",
|
||||
"jscs": "^2.8.0",
|
||||
@@ -27,7 +28,7 @@
|
||||
"webpack": "^1.12.11"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node lib/main/build.js && node lib/fp/build.js",
|
||||
"build": "node lib/main/build-dist.js && node lib/fp/build-dist.js",
|
||||
"style": "jscs lodash.js lib/**/*.js",
|
||||
"test": "npm run build && node test/test && node test/test-fp"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user