mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 12:27:49 +00:00
lodash: Cleanup build scripts and add @kitcambridge as a contributor. [jddalton]
Former-commit-id: 8e37a98f155b8b2bd8ed35a993d83022ac610620
This commit is contained in:
@@ -2,41 +2,49 @@
|
||||
;(function() {
|
||||
'use strict';
|
||||
|
||||
/* Post-processes a compressed `src` string. */
|
||||
var postprocess = module.exports = function postprocess(src) {
|
||||
/** The minimal license/copyright header */
|
||||
var license =
|
||||
'/*!\n' +
|
||||
' Lo-Dash @VERSION github.com/bestiejs/lodash/blob/master/LICENSE.txt\n' +
|
||||
' Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE\n' +
|
||||
'*/';
|
||||
/** The Node filesystem module */
|
||||
var fs = require('fs');
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
// set the version
|
||||
license = license.replace('@VERSION', (/VERSION:([\'"])(.*?)\1/).exec(src).pop());
|
||||
|
||||
// move vars exposed by Closure Compiler into the IIFE
|
||||
src = src.replace(/^([^(\n]+)\s*(\(function[^)]+\){)/, '$2$1');
|
||||
|
||||
// use double quotes consistently
|
||||
src = src.replace(/'use strict'/, '"use strict"');
|
||||
|
||||
// add license
|
||||
return license + '\n;' + src;
|
||||
};
|
||||
/** The minimal license/copyright template */
|
||||
var licenseTemplate =
|
||||
'/*!\n' +
|
||||
' Lo-Dash @VERSION github.com/bestiejs/lodash/blob/master/LICENSE.txt\n' +
|
||||
' Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE\n' +
|
||||
'*/';
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/** The filesystem module */
|
||||
var fs = require('fs'), src;
|
||||
|
||||
if (module == require.main) {
|
||||
// read the JavaScript source file from the first argument if the script
|
||||
// was invoked directly (i.e., `node post-compile.js source.js`)
|
||||
src = fs.readFileSync(process.argv[2], 'utf8');
|
||||
|
||||
// write to the same file
|
||||
fs.writeFileSync(process.argv[2], postprocess(src), 'utf8');
|
||||
/**
|
||||
* Post-process a given minified JavaScript `source`, preparing it for
|
||||
* deployment.
|
||||
*
|
||||
* @private
|
||||
* @param {String} source The source to process.
|
||||
* @returns {String} Returns the processed source.
|
||||
*/
|
||||
function postprocess(source) {
|
||||
// set the version
|
||||
var license = licenseTemplate.replace('@VERSION', (/VERSION:([\'"])(.*?)\1/).exec(source).pop());
|
||||
// move vars exposed by Closure Compiler into the IIFE
|
||||
source = source.replace(/^([^(\n]+)\s*(\(function[^)]+\){)/, '$2$1');
|
||||
// use double quotes consistently
|
||||
source = source.replace(/'use strict'/, '"use strict"');
|
||||
// add license
|
||||
return license + '\n;' + source;
|
||||
}
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
// expose `postprocess`
|
||||
if (module != require.main) {
|
||||
module.exports = postprocess;
|
||||
} else {
|
||||
// Read the JavaScript source file from the first argument if the script
|
||||
// was invoked directly (e.g. `node post-compile.js source.js`) and write to
|
||||
// the same file.
|
||||
(function() {
|
||||
var source = fs.readFileSync(process.argv[2], 'utf8');
|
||||
fs.writeFileSync(process.argv[2], postprocess(source), 'utf8');
|
||||
}());
|
||||
}
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user