mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Cleanup build files and add build/util.js.
Former-commit-id: 67e5564a17ec4a438e3d0768e8963a1384d4ce98
This commit is contained in:
32
build.js
32
build.js
@@ -3,17 +3,16 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/** Load Node.js modules */
|
/** Load Node.js modules */
|
||||||
var fs = require('fs'),
|
var vm = require('vm');
|
||||||
path = require('path'),
|
|
||||||
vm = require('vm');
|
|
||||||
|
|
||||||
/** Load other modules */
|
/** Load other modules */
|
||||||
var _ = require(path.join(__dirname, 'lodash.js')),
|
var _ = require('./lodash.js'),
|
||||||
minify = require(path.join(__dirname, 'build', 'minify.js')),
|
minify = require('./build/minify.js'),
|
||||||
mkdirpSync = require(path.join(__dirname, 'build', 'mkdirp-sync.js'));
|
util = require('./build/util.js');
|
||||||
|
|
||||||
/** Add `path.sep` for older versions of Node.js */
|
/** Module shortcuts */
|
||||||
path.sep || (path.sep = process.platform == 'win32' ? '\\' : '/');
|
var fs = util.fs,
|
||||||
|
path = util.path;
|
||||||
|
|
||||||
/** The current working directory */
|
/** The current working directory */
|
||||||
var cwd = process.cwd();
|
var cwd = process.cwd();
|
||||||
@@ -25,7 +24,7 @@
|
|||||||
var push = arrayRef.push;
|
var push = arrayRef.push;
|
||||||
|
|
||||||
/** Used to detect the Node.js executable in command-line arguments */
|
/** Used to detect the Node.js executable in command-line arguments */
|
||||||
var reNode = RegExp('(?:^|' + path.sep.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')node(?:\\.exe)?$');
|
var reNode = RegExp('(?:^|' + path.sepEscaped + ')node(?:\\.exe)?$');
|
||||||
|
|
||||||
/** Shortcut used to convert array-like objects to arrays */
|
/** Shortcut used to convert array-like objects to arrays */
|
||||||
var slice = arrayRef.slice;
|
var slice = arrayRef.slice;
|
||||||
@@ -1640,7 +1639,7 @@
|
|||||||
if (/-o|--output/.test(value)) {
|
if (/-o|--output/.test(value)) {
|
||||||
result = options[index + 1];
|
result = options[index + 1];
|
||||||
var dirname = path.dirname(result);
|
var dirname = path.dirname(result);
|
||||||
mkdirpSync(dirname);
|
fs.mkdirpSync(dirname);
|
||||||
result = path.join(fs.realpathSync(dirname), path.basename(result));
|
result = path.join(fs.realpathSync(dirname), path.basename(result));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -1829,12 +1828,6 @@
|
|||||||
|
|
||||||
// load customized Lo-Dash module
|
// load customized Lo-Dash module
|
||||||
var lodash = !isTemplate && (function() {
|
var lodash = !isTemplate && (function() {
|
||||||
var context = vm.createContext({
|
|
||||||
'clearTimeout': clearTimeout,
|
|
||||||
'console': console,
|
|
||||||
'setTimeout': setTimeout
|
|
||||||
});
|
|
||||||
|
|
||||||
source = setUseStrictOption(source, isStrict);
|
source = setUseStrictOption(source, isStrict);
|
||||||
|
|
||||||
if (isLegacy) {
|
if (isLegacy) {
|
||||||
@@ -2499,6 +2492,13 @@
|
|||||||
.replace(/\beach(?=\(collection)/g, 'forOwn')
|
.replace(/\beach(?=\(collection)/g, 'forOwn')
|
||||||
.replace(/\beach(?=\(\[)/g, 'forEach');
|
.replace(/\beach(?=\(\[)/g, 'forEach');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var context = vm.createContext({
|
||||||
|
'clearTimeout': clearTimeout,
|
||||||
|
'console': console,
|
||||||
|
'setTimeout': setTimeout
|
||||||
|
});
|
||||||
|
|
||||||
vm.runInContext(source, context);
|
vm.runInContext(source, context);
|
||||||
return context._;
|
return context._;
|
||||||
}());
|
}());
|
||||||
|
|||||||
@@ -3,24 +3,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/** Load Node.js modules */
|
/** Load Node.js modules */
|
||||||
var fs = require('fs'),
|
var https = require('https'),
|
||||||
https = require('https'),
|
|
||||||
path = require('path'),
|
|
||||||
spawn = require('child_process').spawn,
|
spawn = require('child_process').spawn,
|
||||||
zlib = require('zlib');
|
zlib = require('zlib');
|
||||||
|
|
||||||
/** Load other modules */
|
/** Load other modules */
|
||||||
var _ = require('../lodash.js'),
|
var _ = require('../lodash.js'),
|
||||||
mkdirpSync = require('./mkdirp-sync.js'),
|
|
||||||
preprocess = require('./pre-compile.js'),
|
preprocess = require('./pre-compile.js'),
|
||||||
postprocess = require('./post-compile.js'),
|
postprocess = require('./post-compile.js'),
|
||||||
tar = require('../vendor/tar/tar.js');
|
tar = require('../vendor/tar/tar.js'),
|
||||||
|
util = require('./util.js');
|
||||||
|
|
||||||
/** Add `fs.existsSync` for older versions of Node.js */
|
/** Module shortcuts */
|
||||||
fs.existsSync || (fs.existsSync = path.existsSync);
|
var fs = util.fs,
|
||||||
|
path = util.path;
|
||||||
/** Add `path.sep` for older versions of Node.js */
|
|
||||||
path.sep || (path.sep = process.platform == 'win32' ? '\\' : '/');
|
|
||||||
|
|
||||||
/** The Git object ID of `closure-compiler.tar.gz` */
|
/** The Git object ID of `closure-compiler.tar.gz` */
|
||||||
var closureId = 'a95a8007892aa824ce90c6aa3d3abb0489bf0fff';
|
var closureId = 'a95a8007892aa824ce90c6aa3d3abb0489bf0fff';
|
||||||
@@ -47,7 +43,7 @@
|
|||||||
var mediaType = 'application/vnd.github.v3.raw';
|
var mediaType = 'application/vnd.github.v3.raw';
|
||||||
|
|
||||||
/** Used to detect the Node.js executable in command-line arguments */
|
/** Used to detect the Node.js executable in command-line arguments */
|
||||||
var reNode = RegExp('(?:^|' + path.sep.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')node(?:\\.exe)?$');
|
var reNode = RegExp('(?:^|' + path.sepEscaped + ')node(?:\\.exe)?$');
|
||||||
|
|
||||||
/** Used to reference parts of the blob href */
|
/** Used to reference parts of the blob href */
|
||||||
var location = (function() {
|
var location = (function() {
|
||||||
@@ -146,7 +142,7 @@
|
|||||||
if (/-o|--output/.test(value)) {
|
if (/-o|--output/.test(value)) {
|
||||||
result = options[index + 1];
|
result = options[index + 1];
|
||||||
var dirname = path.dirname(result);
|
var dirname = path.dirname(result);
|
||||||
mkdirpSync(dirname);
|
fs.mkdirpSync(dirname);
|
||||||
result = path.join(fs.realpathSync(dirname), path.basename(result));
|
result = path.join(fs.realpathSync(dirname), path.basename(result));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
;(function() {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/** Load Node.js modules */
|
|
||||||
var fs = require('fs'),
|
|
||||||
path = require('path');
|
|
||||||
|
|
||||||
/** Add `path.sep` for older versions of Node.js */
|
|
||||||
path.sep || (path.sep = process.platform == 'win32' ? '\\' : '/');
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes the given `dirname` directory, without throwing errors for existing
|
|
||||||
* directories and making parent directories as needed.
|
|
||||||
*
|
|
||||||
* @param {String} dirname The path of the directory.
|
|
||||||
* @param {Number|String} [mode='0777'] The permission mode.
|
|
||||||
*/
|
|
||||||
function mkdirpSync(dirname, mode) {
|
|
||||||
var sep = path.sep;
|
|
||||||
|
|
||||||
// ensure relative paths are prefixed with `./`
|
|
||||||
if (!RegExp('^\\.?' + sep.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).test(dirname)) {
|
|
||||||
dirname = '.' + sep + dirname;
|
|
||||||
}
|
|
||||||
dirname.split(sep).reduce(function(currPath, segment) {
|
|
||||||
currPath += sep + segment;
|
|
||||||
try {
|
|
||||||
currPath = fs.realpathSync(currPath);
|
|
||||||
} catch(e) {
|
|
||||||
fs.mkdirSync(currPath, mode);
|
|
||||||
}
|
|
||||||
return currPath;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
// expose
|
|
||||||
module.exports = mkdirpSync;
|
|
||||||
}());
|
|
||||||
92
build/util.js
Executable file
92
build/util.js
Executable file
@@ -0,0 +1,92 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
;(function() {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/** Load Node.js modules */
|
||||||
|
var fs = require('fs'),
|
||||||
|
path = require('path');
|
||||||
|
|
||||||
|
/** Load other modules */
|
||||||
|
var _ = require('../lodash.js');
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The path separator.
|
||||||
|
*
|
||||||
|
* @memberOf util.path
|
||||||
|
* @type String
|
||||||
|
*/
|
||||||
|
var sep = path.sep || (process.platform == 'win32' ? '\\' : '/');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The escaped path separator used for inclusion in RegExp strings.
|
||||||
|
*
|
||||||
|
* @memberOf util.path
|
||||||
|
* @type String
|
||||||
|
*/
|
||||||
|
var sepEscaped = sep.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes the given `dirname` directory, without throwing errors for existing
|
||||||
|
* directories and making parent directories as needed.
|
||||||
|
*
|
||||||
|
* @memberOf util.fs
|
||||||
|
* @param {String} dirname The path of the directory.
|
||||||
|
* @param {Number|String} [mode='0777'] The permission mode.
|
||||||
|
*/
|
||||||
|
function mkdirpSync(dirname, mode) {
|
||||||
|
// ensure relative paths are prefixed with `./`
|
||||||
|
if (!RegExp('^\\.?' + sepEscaped).test(dirname)) {
|
||||||
|
dirname = '.' + sep + dirname;
|
||||||
|
}
|
||||||
|
dirname.split(sep).reduce(function(currPath, segment) {
|
||||||
|
currPath += sep + segment;
|
||||||
|
try {
|
||||||
|
currPath = fs.realpathSync(currPath);
|
||||||
|
} catch(e) {
|
||||||
|
fs.mkdirSync(currPath, mode);
|
||||||
|
}
|
||||||
|
return currPath;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The utility object.
|
||||||
|
*
|
||||||
|
* @type Object
|
||||||
|
*/
|
||||||
|
var util = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The file system object.
|
||||||
|
*
|
||||||
|
* @memberOf util
|
||||||
|
* @type Object
|
||||||
|
*/
|
||||||
|
'fs': _.defaults({}, fs, {
|
||||||
|
'existsSync': fs.existsSync || path.existsSync,
|
||||||
|
'mkdirpSync': mkdirpSync
|
||||||
|
}),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The path object.
|
||||||
|
*
|
||||||
|
* @memberOf util
|
||||||
|
* @type Object
|
||||||
|
*/
|
||||||
|
'path': _.defaults({}, path, {
|
||||||
|
'sep': sep,
|
||||||
|
'sepEscaped': sepEscaped
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// expose
|
||||||
|
module.exports = util;
|
||||||
|
}());
|
||||||
@@ -3,21 +3,21 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/** Load Node.js modules */
|
/** Load Node.js modules */
|
||||||
var fs = require('fs'),
|
var vm = require('vm');
|
||||||
path = require('path'),
|
|
||||||
vm = require('vm');
|
|
||||||
|
|
||||||
/** Load other modules */
|
/** Load other modules */
|
||||||
var build = require('../build.js'),
|
var _ = require('../lodash.js'),
|
||||||
minify = require('../build/minify'),
|
build = require('../build.js'),
|
||||||
_ = require('../lodash.js');
|
minify = require('../build/minify.js'),
|
||||||
|
util = require('../build/util.js');
|
||||||
|
|
||||||
|
/** Module shortcuts */
|
||||||
|
var fs = util.fs,
|
||||||
|
path = util.path;
|
||||||
|
|
||||||
/** Used to avoid `noglobal` false positives caused by `errno` leaked in Node.js */
|
/** Used to avoid `noglobal` false positives caused by `errno` leaked in Node.js */
|
||||||
global.errno = true;
|
global.errno = true;
|
||||||
|
|
||||||
/** Add `path.sep` for older versions of Node.js */
|
|
||||||
path.sep || (path.sep = process.platform == 'win32' ? '\\' : '/');
|
|
||||||
|
|
||||||
/** The current working directory */
|
/** The current working directory */
|
||||||
var cwd = process.cwd();
|
var cwd = process.cwd();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user