Add util.pitch.

This commit is contained in:
John-David Dalton
2016-05-30 08:04:00 -07:00
parent 695d74d7c5
commit 77cf88a3bf
7 changed files with 98 additions and 62 deletions

View File

@@ -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
};

View File

@@ -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();

View File

@@ -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));

View File

@@ -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));

View File

@@ -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();

View File

@@ -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));

View File

@@ -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));