From 77cf88a3bf11aa6766cb02d5768513bbf3010340 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 30 May 2016 08:04:00 -0700 Subject: [PATCH] Add `util.pitch`. --- lib/common/util.js | 15 ++++++++++- lib/fp/build-dist.js | 16 ++++++------ lib/fp/build-doc.js | 18 +++---------- lib/fp/build-modules.js | 54 +++++++++++++++++++++++++++++---------- lib/main/build-dist.js | 16 ++++++------ lib/main/build-doc.js | 25 +++++++++++------- lib/main/build-modules.js | 16 ++++++------ 7 files changed, 98 insertions(+), 62 deletions(-) diff --git a/lib/common/util.js b/lib/common/util.js index aadbf8412..977fc1bfc 100644 --- a/lib/common/util.js +++ b/lib/common/util.js @@ -22,6 +22,19 @@ function Hash(properties) { Hash.prototype = Object.create(null); +/** + * A method that throws any error it receives. + * + * @memberOf util + * @param {Object} [error] The error object. + */ +function pitch(error) { + if (error != null) { + throw error; + } +} + module.exports = { - 'Hash': Hash + 'Hash': Hash, + 'pitch': pitch }; diff --git a/lib/fp/build-dist.js b/lib/fp/build-dist.js index bad62d2eb..6c68c9923 100644 --- a/lib/fp/build-dist.js +++ b/lib/fp/build-dist.js @@ -5,7 +5,8 @@ var _ = require('lodash'), path = require('path'), webpack = require('webpack'); -var file = require('../common/file'); +var file = require('../common/file'), + util = require('../common/util'); var basePath = path.join(__dirname, '..', '..'), distPath = path.join(basePath, 'dist'), @@ -38,18 +39,17 @@ var mappingConfig = { /*----------------------------------------------------------------------------*/ -function onComplete(error) { - if (error) { - throw error; - } -} - +/** + * Creates browser builds of the FP converter and mappings at the `target` path. + * + * @param {string} target The output directory path. + */ function build() { async.series([ _.partial(webpack, mappingConfig), _.partial(webpack, fpConfig), file.min(path.join(distPath, filename)) - ], onComplete); + ], util.pitch); } build(); diff --git a/lib/fp/build-doc.js b/lib/fp/build-doc.js index 302d2462e..ff151ecd8 100644 --- a/lib/fp/build-doc.js +++ b/lib/fp/build-doc.js @@ -5,7 +5,8 @@ var _ = require('lodash'), path = require('path'); var file = require('../common/file'), - mapping = require('../common/mapping'); + mapping = require('../common/mapping'), + util = require('../common/util'); var templatePath = path.join(__dirname, 'template/doc'), template = file.globTemplate(path.join(templatePath, '*.jst')); @@ -34,7 +35,7 @@ function toArgOrder(indexes) { } /** - * Converts `funcNames` into a backticked chunked list string representation. + * Converts `funcNames` into a chunked list string representation. * * @param {string[]} funcNames The function names. * @returns {string} Returns the function list string. @@ -64,17 +65,6 @@ function toFuncList(funcNames) { /*----------------------------------------------------------------------------*/ -/** - * A no-frills callback that throws any error it receives. - * - * @param {Object} [error] The error object. - */ -function onComplete(error) { - if (error) { - throw error; - } -} - /** * Creates the FP-Guide wiki at the `target` path. * @@ -82,7 +72,7 @@ function onComplete(error) { */ function build(target) { target = path.resolve(target); - fs.writeFile(target, template.wiki(templateData), onComplete); + fs.writeFile(target, template.wiki(templateData), util.pitch); } build(_.last(process.argv)); diff --git a/lib/fp/build-modules.js b/lib/fp/build-modules.js index 43902e01c..597273b67 100644 --- a/lib/fp/build-modules.js +++ b/lib/fp/build-modules.js @@ -6,7 +6,8 @@ var _ = require('lodash'), path = require('path'); var file = require('../common/file'), - mapping = require('../common/mapping'); + mapping = require('../common/mapping'), + util = require('../common/util'); var templatePath = path.join(__dirname, 'template/modules'), template = file.globTemplate(path.join(templatePath, '*.jst')); @@ -42,18 +43,44 @@ var ignored = [ 'lodash.min.js' ]; -function isAlias(funcName) { - return _.has(mapping.aliasToReal, funcName); +/** + * Checks if `name` is a method alias. + * + * @param {string} name The name to check. + * @returns {boolean} Returns `true` if `name` is a method alias, else `false`. + */ +function isAlias(name) { + return _.has(mapping.aliasToReal, name); } -function isCategory(funcName) { - return _.includes(categories, funcName); +/** + * Checks if `name` is a category name. + * + * @param {string} name The name to check. + * @returns {boolean} Returns `true` if `name` is a category name, else `false`. + */ +function isCategory(name) { + return _.includes(categories, name); } -function isThru(funcName) { - return !_.includes(aryMethods, funcName); +/** + * Checks if `name` belongs to a method that's passed thru and not wrapped. + * + * @param {string} name The name to check. + * @returns {boolean} Returns `true` if `name` is of a pass thru method, + * else `false`. + */ +function isThru(name) { + return !_.includes(aryMethods, name); } +/** + * Gets metadata for `func`. + * + * @private + * @param {Function} func The function to query. + * @returns {*} Returns the metadata for `func`. + */ function getTemplate(moduleName) { var data = { 'name': _.result(mapping.aliasToReal, moduleName, moduleName), @@ -74,12 +101,11 @@ function getTemplate(moduleName) { /*----------------------------------------------------------------------------*/ -function onComplete(error) { - if (error) { - throw error; - } -} - +/** + * Creates FP modules at the `target` path. + * + * @param {string} target The output directory path. + */ function build(target) { target = path.resolve(target); @@ -114,7 +140,7 @@ function build(target) { actions.push(file.write(path.join(target, 'fp.js'), template.fp())); actions.push(file.write(path.join(fpPath, 'convert.js'), template.convert())); - async.series(actions, onComplete); + async.series(actions, util.pitch); } build(_.last(process.argv)); diff --git a/lib/main/build-dist.js b/lib/main/build-dist.js index 14b3fd3ce..b91f1474c 100644 --- a/lib/main/build-dist.js +++ b/lib/main/build-dist.js @@ -3,7 +3,8 @@ var async = require('async'), path = require('path'); -var file = require('../common/file'); +var file = require('../common/file'), + util = require('../common/util'); var basePath = path.join(__dirname, '..', '..'), distPath = path.join(basePath, 'dist'), @@ -14,17 +15,16 @@ var baseLodash = path.join(basePath, filename), /*----------------------------------------------------------------------------*/ -function onComplete(error) { - if (error) { - throw error; - } -} - +/** + * Creates browser builds of Lodash at the `target` path. + * + * @param {string} target The output directory path. + */ function build() { async.series([ file.copy(baseLodash, distLodash), file.min(distLodash) - ], onComplete); + ], util.pitch); } build(); diff --git a/lib/main/build-doc.js b/lib/main/build-doc.js index 6c5f22b57..1b857ed10 100644 --- a/lib/main/build-doc.js +++ b/lib/main/build-doc.js @@ -5,6 +5,8 @@ var _ = require('lodash'), fs = require('fs-extra'), path = require('path'); +var util = require('../common/util'); + var basePath = path.join(__dirname, '..', '..'), docPath = path.join(basePath, 'doc'), readmePath = path.join(docPath, 'README.md'); @@ -32,24 +34,29 @@ var config = { } }; -function postprocess(string) { +/** + * Post-process `markdown` to make adjustments. + * + * @param {string} markdown The markdown to process. + * @returns {string} Returns the processed markdown. + */ +function postprocess(markdown) { // Wrap symbol property identifiers in brackets. - return string.replace(/\.(Symbol\.(?:[a-z]+[A-Z]?)+)/g, '[$1]'); + return markdown.replace(/\.(Symbol\.(?:[a-z]+[A-Z]?)+)/g, '[$1]'); } /*----------------------------------------------------------------------------*/ -function onComplete(error) { - if (error) { - throw error; - } -} - +/** + * Creates the documentation markdown formatted for 'github' or 'site'. + * + * @param {string} type The format type. + */ function build(type) { var options = _.defaults({}, config.base, config[type]), markdown = docdown(options); - fs.writeFile(readmePath, postprocess(markdown), onComplete); + fs.writeFile(readmePath, postprocess(markdown), util.pitch); } build(_.last(process.argv)); diff --git a/lib/main/build-modules.js b/lib/main/build-modules.js index 5d89e0dc2..284b3ae23 100644 --- a/lib/main/build-modules.js +++ b/lib/main/build-modules.js @@ -4,7 +4,8 @@ var _ = require('lodash'), async = require('async'), path = require('path'); -var file = require('../common/file'); +var file = require('../common/file'), + util = require('../common/util'); var basePath = path.join(__dirname, '..', '..'), distPath = path.join(basePath, 'dist'); @@ -17,18 +18,17 @@ var filePairs = [ /*----------------------------------------------------------------------------*/ -function onComplete(error) { - if (error) { - throw error; - } -} - +/** + * Creates supplementary Lodash modules at the `target` path. + * + * @param {string} target The output directory path. + */ function build(target) { var actions = _.map(filePairs, function(pair) { return file.copy(pair[0], path.join(target, pair[1])); }); - async.series(actions, onComplete); + async.series(actions, util.pitch); } build(_.last(process.argv));