Add back fp build-modules files.

This commit is contained in:
John-David Dalton
2016-01-25 00:16:23 -08:00
parent 258ad020ed
commit c49ace5587
12 changed files with 172 additions and 43 deletions

View File

@@ -215,7 +215,7 @@ function baseConvert(util, name, func) {
// Wrap the lodash method and its aliases. // Wrap the lodash method and its aliases.
each(keys(_), function(key) { each(keys(_), function(key) {
each(mapping.alias[key] || [], function(alias) { each(mapping.realToAlias[key] || [], function(alias) {
_[alias] = _[key]; _[alias] = _[key];
}); });
}); });

View File

@@ -1,36 +1,5 @@
module.exports = { module.exports = {
/** Used to map method names to their aliases. */
'alias': {
'ary': ['nAry'],
'assignIn': ['extend'],
'assignInWith': ['extendWith'],
'filter': ['whereEq'],
'flatten': ['unnest'],
'flow': ['pipe'],
'flowRight': ['compose'],
'forEach': ['each'],
'forEachRight': ['eachRight'],
'get': ['path', 'prop'],
'getOr': ['pathOr', 'propOr'],
'head': ['first'],
'includes': ['contains'],
'initial': ['init'],
'isEqual': ['equals'],
'mapValues': ['mapObj'],
'matchesProperty': ['pathEq'],
'omit': ['dissoc', 'omitAll'],
'overArgs': ['useWith'],
'overEvery': ['allPass'],
'overSome': ['somePass'],
'pick': ['pickAll'],
'propertyOf': ['propOf'],
'rest': ['unapply'],
'some': ['all'],
'spread': ['apply'],
'zipObject': ['zipObj']
},
/** Used to map method names to their iteratee ary. */ /** Used to map method names to their iteratee ary. */
'aryIteratee': { 'aryIteratee': {
'assignWith': 2, 'assignWith': 2,
@@ -183,6 +152,37 @@ module.exports = {
'partialRight': true 'partialRight': true
}, },
/** Used to map real names to their aliases. */
'realToAlias': {
'ary': ['nAry'],
'assignIn': ['extend'],
'assignInWith': ['extendWith'],
'filter': ['whereEq'],
'flatten': ['unnest'],
'flow': ['pipe'],
'flowRight': ['compose'],
'forEach': ['each'],
'forEachRight': ['eachRight'],
'get': ['path', 'prop'],
'getOr': ['pathOr', 'propOr'],
'head': ['first'],
'includes': ['contains'],
'initial': ['init'],
'isEqual': ['equals'],
'mapValues': ['mapObj'],
'matchesProperty': ['pathEq'],
'omit': ['dissoc', 'omitAll'],
'overArgs': ['useWith'],
'overEvery': ['allPass'],
'overSome': ['somePass'],
'pick': ['pickAll'],
'propertyOf': ['propOf'],
'rest': ['unapply'],
'some': ['all'],
'spread': ['apply'],
'zipObject': ['zipObj']
},
/** Used to track methods that skip `_.rearg`. */ /** Used to track methods that skip `_.rearg`. */
'skipRearg': { 'skipRearg': {
'assign': true, 'assign': true,

View File

@@ -44,8 +44,12 @@ function onComplete(error) {
} }
} }
async.series([ function build() {
_.partial(webpack, mappingConfig), async.series([
_.partial(webpack, fpConfig), _.partial(webpack, mappingConfig),
_.partial(minify, path.join(distPath, filename)) _.partial(webpack, fpConfig),
], onComplete); _.partial(minify, path.join(distPath, filename))
], onComplete);
}
build();

112
lib/fp/build-modules.js Normal file
View File

@@ -0,0 +1,112 @@
'use strict';
var _ = require('lodash'),
async = require('async'),
fs = require('fs-extra'),
glob = require('glob'),
Module = require('module'),
path = require('path');
var mapping = require('../../fp/_mapping');
var templatePath = path.join(__dirname, 'template');
var aliasToReal = _.transform(mapping.realToAlias, function(result, aliases, realName) {
_.each(aliases, function(alias) {
result[alias] = realName;
});
});
var template = _.transform(glob.sync(path.join(templatePath, '*.jst')), function(result, filePath) {
result[path.basename(filePath, '.jst')] = _.template(fs.readFileSync(filePath));
}, {});
var aryMethods = _.union(
mapping.aryMethod[1],
mapping.aryMethod[2],
mapping.aryMethod[3],
mapping.aryMethod[4]
);
var categories = [
'array',
'collection',
'date',
'function',
'lang',
'math',
'number',
'object',
'seq',
'string',
'util'
];
function isAlias(funcName) {
return _.has(aliasToReal, funcName);
}
function isCategory(funcName) {
return _.includes(categories, funcName);
}
function isThru(funcName) {
return !_.includes(aryMethods, funcName);
}
function getTemplate(moduleName) {
var data = {
'key': mapping.key,
'name': _.result(aliasToReal, moduleName, moduleName)
};
if (isAlias(moduleName)) {
return template.alias(data);
}
if (isCategory(moduleName)) {
return template.category(data);
}
if (isThru(moduleName)) {
return template.thru(data);
}
return template.module(data);
}
/*----------------------------------------------------------------------------*/
function onComplete(error) {
if (error) {
throw error;
}
}
function build(target) {
var fpPath = path.join(target, 'fp');
// Glob existing lodash module paths.
var modulePaths = glob.sync(path.join(target, '*.js'), {
'nodir': true,
'ignore': path.join(target, '_*.js')
});
// Add FP alias module paths.
_.forOwn(aliasToReal, function(realName, alias) {
modulePaths.push(path.join(target, alias + '.js'));
});
modulePaths = _.uniq(modulePaths);
var actions = modulePaths.map(function(modulePath) {
var moduleName = path.basename(modulePath, '.js');
return _.partial(fs.writeFile, path.join(fpPath, moduleName + '.js'), getTemplate(moduleName));
})
actions.unshift(_.partial(fs.copy, path.join(__dirname, '../../fp'), fpPath));
actions.push(_.partial(fs.writeFile, path.join(target, 'fp.js'), template.fp()));
actions.push(_.partial(fs.writeFile, path.join(fpPath, 'convert.js'), template.convert()));
actions.push(_.partial(fs.writeFile, path.join(fpPath, '_util.js'), template._util()));
async.series(actions, onComplete);
}
build(_.last(process.argv));

View File

@@ -2,9 +2,9 @@ module.exports = {
'ary': require('../ary'), 'ary': require('../ary'),
'cloneDeep': require('../cloneDeep'), 'cloneDeep': require('../cloneDeep'),
'curry': require('../curry'), 'curry': require('../curry'),
'forEach': require('../internal/arrayEach'), 'forEach': require('../_arrayEach'),
'isFunction': require('../isFunction'), 'isFunction': require('../isFunction'),
'iteratee': require('../iteratee'), 'iteratee': require('../iteratee'),
'keys': require('../internal/baseKeys'), 'keys': require('../_baseKeys'),
'rearg': require('../rearg') 'rearg': require('../rearg')
}; };

View File

@@ -0,0 +1 @@
module.exports = require('./<%= name %>');

View File

@@ -0,0 +1,2 @@
var convert = require('./convert');
module.exports = convert(require('../<%= name %>'));

2
lib/fp/template/fp.jst Normal file
View File

@@ -0,0 +1,2 @@
var _ = require('./lodash').noConflict().runInContext();
module.exports = require('./fp/convert')(_);

View File

@@ -0,0 +1,2 @@
var convert = require('./convert');
module.exports = convert('<%= name %>', require('../<%= _.result(key, name, name) %>'));

1
lib/fp/template/thru.jst Normal file
View File

@@ -0,0 +1 @@
module.exports = require('../<%= name %>');

View File

@@ -22,7 +22,11 @@ function onComplete(error) {
} }
} }
async.series([ function build() {
_.partial(fs.copy, baseLodash, distLodash), async.series([
_.partial(minify, distLodash) _.partial(fs.copy, baseLodash, distLodash),
], onComplete); _.partial(minify, distLodash)
], onComplete);
}
build();

View File

@@ -29,6 +29,7 @@
}, },
"scripts": { "scripts": {
"build": "node lib/main/build-dist.js && node lib/fp/build-dist.js", "build": "node lib/main/build-dist.js && node lib/fp/build-dist.js",
"build-fp": "node lib/fp/build-modules.js",
"style": "jscs lodash.js lib/**/*.js", "style": "jscs lodash.js lib/**/*.js",
"test": "npm run build && node test/test && node test/test-fp" "test": "npm run build && node test/test && node test/test-fp"
} }