From 9d2d4f39bc1af93809563a5f5555c6275bcce76a Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 16 Jan 2016 11:18:56 -0800 Subject: [PATCH] Reorg build, fp, and lib files. --- lib/fp/baseConvert.js => fp/_baseConvert.js | 2 +- fp/_convertBrowser.js | 13 +++ lib/fp/mapping.js => fp/_mapping.js | 0 lib/fp/{build.js => build-dist.js} | 6 +- lib/fp/convert.browser.js | 13 --- lib/fp/convert.js | 21 ----- lib/fp/convert.node.js | 16 ---- lib/fp/fp-util.js | 10 --- lib/fp/precompile.js | 95 --------------------- lib/fp/template/_util.jst | 10 +++ lib/fp/template/convert.jst | 16 ++++ lib/main/{build.js => build-dist.js} | 0 package.json | 3 +- 13 files changed, 45 insertions(+), 160 deletions(-) rename lib/fp/baseConvert.js => fp/_baseConvert.js (99%) create mode 100644 fp/_convertBrowser.js rename lib/fp/mapping.js => fp/_mapping.js (100%) rename lib/fp/{build.js => build-dist.js} (87%) delete mode 100644 lib/fp/convert.browser.js delete mode 100644 lib/fp/convert.js delete mode 100644 lib/fp/convert.node.js delete mode 100644 lib/fp/fp-util.js delete mode 100644 lib/fp/precompile.js create mode 100644 lib/fp/template/_util.jst create mode 100644 lib/fp/template/convert.jst rename lib/main/{build.js => build-dist.js} (100%) diff --git a/lib/fp/baseConvert.js b/fp/_baseConvert.js similarity index 99% rename from lib/fp/baseConvert.js rename to fp/_baseConvert.js index 7a187b924..10a7d70bc 100644 --- a/lib/fp/baseConvert.js +++ b/fp/_baseConvert.js @@ -1,4 +1,4 @@ -var mapping = require('./mapping.js'), +var mapping = require('./_mapping'), mutateMap = mapping.mutate, placeholder = {}; diff --git a/fp/_convertBrowser.js b/fp/_convertBrowser.js new file mode 100644 index 000000000..b076778a4 --- /dev/null +++ b/fp/_convertBrowser.js @@ -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; diff --git a/lib/fp/mapping.js b/fp/_mapping.js similarity index 100% rename from lib/fp/mapping.js rename to fp/_mapping.js diff --git a/lib/fp/build.js b/lib/fp/build-dist.js similarity index 87% rename from lib/fp/build.js rename to lib/fp/build-dist.js index db3fbe40b..c88dd4e5c 100644 --- a/lib/fp/build.js +++ b/lib/fp/build-dist.js @@ -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', diff --git a/lib/fp/convert.browser.js b/lib/fp/convert.browser.js deleted file mode 100644 index 6855f34f8..000000000 --- a/lib/fp/convert.browser.js +++ /dev/null @@ -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; diff --git a/lib/fp/convert.js b/lib/fp/convert.js deleted file mode 100644 index baee05bdb..000000000 --- a/lib/fp/convert.js +++ /dev/null @@ -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; diff --git a/lib/fp/convert.node.js b/lib/fp/convert.node.js deleted file mode 100644 index ef26d5cbf..000000000 --- a/lib/fp/convert.node.js +++ /dev/null @@ -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; diff --git a/lib/fp/fp-util.js b/lib/fp/fp-util.js deleted file mode 100644 index 1ba696938..000000000 --- a/lib/fp/fp-util.js +++ /dev/null @@ -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') -}; diff --git a/lib/fp/precompile.js b/lib/fp/precompile.js deleted file mode 100644 index 1923c5fcd..000000000 --- a/lib/fp/precompile.js +++ /dev/null @@ -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; diff --git a/lib/fp/template/_util.jst b/lib/fp/template/_util.jst new file mode 100644 index 000000000..1fb05e435 --- /dev/null +++ b/lib/fp/template/_util.jst @@ -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') +}; diff --git a/lib/fp/template/convert.jst b/lib/fp/template/convert.jst new file mode 100644 index 000000000..85f3b7535 --- /dev/null +++ b/lib/fp/template/convert.jst @@ -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; diff --git a/lib/main/build.js b/lib/main/build-dist.js similarity index 100% rename from lib/main/build.js rename to lib/main/build-dist.js diff --git a/package.json b/package.json index 319a10c58..e832b98b0 100644 --- a/package.json +++ b/package.json @@ -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" }