Add defaultBuildCallback to build.js.

Former-commit-id: a7823682374b90bef1ea4f34bed883318fe48ca2
This commit is contained in:
John-David Dalton
2013-06-20 00:42:15 -07:00
parent 73913f450b
commit 83c2420038

View File

@@ -728,6 +728,28 @@
.replace(/\n{3,}/g, '\n\n'); .replace(/\n{3,}/g, '\n\n');
} }
/**
* The default callback used for `build` invocations.
*
* @private
* @param {Object} data The data for the given build.
* gzip - The gzipped output of the built source
* outputPath - The path where the built source is to be written
* source - The built source output
* sourceMap - The source map output
*/
function defaultBuildCallback(data) {
var outputPath = data.outputPath,
sourceMap = data.sourceMap;
if (outputPath) {
fs.writeFileSync(outputPath, data.source, 'utf8');
if (sourceMap) {
fs.writeFileSync(path.join(path.dirname(outputPath), path.basename(outputPath, '.js') + '.map'), sourceMap, 'utf8');
}
}
}
/** /**
* Writes the help message to standard output. * Writes the help message to standard output.
* *
@@ -1292,10 +1314,12 @@
function removeFunction(source, funcName) { function removeFunction(source, funcName) {
var snippet; var snippet;
// remove function // defer to specialized removal functions
if (funcName == 'runInContext') { if (funcName == 'runInContext') {
source = removeRunInContext(source, funcName); return removeRunInContext(source, funcName);
} else if ((snippet = matchFunction(source, funcName))) { }
// remove function
if ((snippet = matchFunction(source, funcName))) {
source = source.replace(snippet, ''); source = source.replace(snippet, '');
} }
@@ -1886,15 +1910,16 @@
/** /**
* Creates a debug and/or minified build, executing the `callback` for each. * Creates a debug and/or minified build, executing the `callback` for each.
* The `callback` is invoked with two arguments; (filePath, outputSource). * The `callback` is invoked with one argument; (data).
* *
* Note: For a list of commands see `displayHelp()` or run `lodash --help`. * Note: For a list of commands see `displayHelp()` or run `lodash --help`.
* *
* @param {Array} [options=[]] An array of commands. * @param {Array} [options=[]] An array of commands.
* @param {Function} callback The function called per build. * @param {Function} [callback=defaultBuildCallback] The function called per build.
*/ */
function build(options, callback) { function build(options, callback) {
options || (options = []); options || (options = []);
callback || (callback = defaultBuildCallback);
// the debug version of `source` // the debug version of `source`
var debugSource; var debugSource;
@@ -3745,16 +3770,6 @@
} }
else { else {
// or invoked directly // or invoked directly
build(process.argv, function(data) { build(process.argv);
var outputPath = data.outputPath,
sourceMap = data.sourceMap;
if (outputPath) {
fs.writeFileSync(outputPath, data.source, 'utf8');
if (sourceMap) {
fs.writeFileSync(path.join(path.dirname(outputPath), path.basename(outputPath, '.js') + '.map'), sourceMap, 'utf8');
}
}
});
} }
}()); }());