mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Extract the preprocess and postprocess functions into build/pre-compile.js and build/post-compile.js, respectively. Clean up build.js.
Former-commit-id: 18c47305b304cca41f00d994138f5b067def1b07
This commit is contained in:
42
build/post-compile.js
Normal file
42
build/post-compile.js
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env node
|
||||
;(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' +
|
||||
'*/';
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
// 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 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');
|
||||
}
|
||||
}());
|
||||
Reference in New Issue
Block a user