Cleanup build files and add build/util.js.

Former-commit-id: 67e5564a17ec4a438e3d0768e8963a1384d4ce98
This commit is contained in:
John-David Dalton
2013-04-09 12:58:17 -07:00
parent 76aae8ce42
commit a8b6fa413e
5 changed files with 125 additions and 80 deletions

View File

@@ -3,17 +3,16 @@
'use strict';
/** Load Node.js modules */
var fs = require('fs'),
path = require('path'),
vm = require('vm');
var vm = require('vm');
/** Load other modules */
var _ = require(path.join(__dirname, 'lodash.js')),
minify = require(path.join(__dirname, 'build', 'minify.js')),
mkdirpSync = require(path.join(__dirname, 'build', 'mkdirp-sync.js'));
var _ = require('./lodash.js'),
minify = require('./build/minify.js'),
util = require('./build/util.js');
/** Add `path.sep` for older versions of Node.js */
path.sep || (path.sep = process.platform == 'win32' ? '\\' : '/');
/** Module shortcuts */
var fs = util.fs,
path = util.path;
/** The current working directory */
var cwd = process.cwd();
@@ -25,7 +24,7 @@
var push = arrayRef.push;
/** 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 */
var slice = arrayRef.slice;
@@ -1640,7 +1639,7 @@
if (/-o|--output/.test(value)) {
result = options[index + 1];
var dirname = path.dirname(result);
mkdirpSync(dirname);
fs.mkdirpSync(dirname);
result = path.join(fs.realpathSync(dirname), path.basename(result));
}
return result;
@@ -1829,12 +1828,6 @@
// load customized Lo-Dash module
var lodash = !isTemplate && (function() {
var context = vm.createContext({
'clearTimeout': clearTimeout,
'console': console,
'setTimeout': setTimeout
});
source = setUseStrictOption(source, isStrict);
if (isLegacy) {
@@ -2499,6 +2492,13 @@
.replace(/\beach(?=\(collection)/g, 'forOwn')
.replace(/\beach(?=\(\[)/g, 'forEach');
}
var context = vm.createContext({
'clearTimeout': clearTimeout,
'console': console,
'setTimeout': setTimeout
});
vm.runInContext(source, context);
return context._;
}());

View File

@@ -3,24 +3,20 @@
'use strict';
/** Load Node.js modules */
var fs = require('fs'),
https = require('https'),
path = require('path'),
var https = require('https'),
spawn = require('child_process').spawn,
zlib = require('zlib');
/** Load other modules */
var _ = require('../lodash.js'),
mkdirpSync = require('./mkdirp-sync.js'),
preprocess = require('./pre-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 */
fs.existsSync || (fs.existsSync = path.existsSync);
/** Add `path.sep` for older versions of Node.js */
path.sep || (path.sep = process.platform == 'win32' ? '\\' : '/');
/** Module shortcuts */
var fs = util.fs,
path = util.path;
/** The Git object ID of `closure-compiler.tar.gz` */
var closureId = 'a95a8007892aa824ce90c6aa3d3abb0489bf0fff';
@@ -47,7 +43,7 @@
var mediaType = 'application/vnd.github.v3.raw';
/** 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 */
var location = (function() {
@@ -146,7 +142,7 @@
if (/-o|--output/.test(value)) {
result = options[index + 1];
var dirname = path.dirname(result);
mkdirpSync(dirname);
fs.mkdirpSync(dirname);
result = path.join(fs.realpathSync(dirname), path.basename(result));
}
return result;

View File

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

View File

@@ -3,21 +3,21 @@
'use strict';
/** Load Node.js modules */
var fs = require('fs'),
path = require('path'),
vm = require('vm');
var vm = require('vm');
/** Load other modules */
var build = require('../build.js'),
minify = require('../build/minify'),
_ = require('../lodash.js');
var _ = require('../lodash.js'),
build = require('../build.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 */
global.errno = true;
/** Add `path.sep` for older versions of Node.js */
path.sep || (path.sep = process.platform == 'win32' ? '\\' : '/');
/** The current working directory */
var cwd = process.cwd();