No longer create/use the dist/ folder during the build process.

Former-commit-id: d8d298d5ce21032542d21c4d4fbc7e0112f6ad65
This commit is contained in:
John-David Dalton
2012-09-30 15:05:17 -07:00
parent 06f4743f51
commit 0f66d763e0
5 changed files with 29 additions and 57 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,3 @@
*.custom.* *.custom.*
.DS_Store .DS_Store
dist/
node_modules/ node_modules/

View File

@@ -1,6 +1,5 @@
*.custom.* *.custom.*
.* .*
dist/
doc/*.php doc/*.php
node_modules/ node_modules/
perf/*.sh perf/*.sh

View File

@@ -1,6 +1,5 @@
*.custom.* *.custom.*
.* .*
dist/
doc/*.php doc/*.php
node_modules/ node_modules/
perf/*.html perf/*.html

View File

@@ -1410,8 +1410,8 @@
/(?:category|exclude|exports|iife|include|minus|plus)=/.test(options) || /(?:category|exclude|exports|iife|include|minus|plus)=/.test(options) ||
!_.isEqual(exportsOptions, exportsAll); !_.isEqual(exportsOptions, exportsAll);
// used to name temporary files created in `dist/` // used as the basename of the output path
var workingName = outputPath var basename = outputPath
? path.basename(outputPath, '.js') ? path.basename(outputPath, '.js')
: 'lodash' + (isTemplate ? '.template' : isCustom ? '.custom' : ''); : 'lodash' + (isTemplate ? '.template' : isCustom ? '.custom' : '');
@@ -1424,18 +1424,17 @@
stdout.write(debugSource); stdout.write(debugSource);
callback(debugSource); callback(debugSource);
} else if (!isStdOut) { } else if (!isStdOut) {
callback(debugSource, (isDebug && outputPath) || path.join(cwd, workingName + '.js')); callback(debugSource, (isDebug && outputPath) || path.join(cwd, basename + '.js'));
} }
} }
// begin the minification process // begin the minification process
if (!isDebug) { if (!isDebug) {
if (!outputPath) { outputPath || (outputPath = path.join(cwd, basename + '.min.js'));
workingName += '.min';
}
minify(source, { minify(source, {
'isSilent': isSilent, 'isSilent': isSilent,
'isTemplate': isTemplate, 'isTemplate': isTemplate,
'workingName': workingName, 'outputPath': outputPath,
'onComplete': function(source) { 'onComplete': function(source) {
// correct overly aggressive Closure Compiler minification // correct overly aggressive Closure Compiler minification
source = source.replace(/prototype\s*=\s*{\s*valueOf\s*:\s*1\s*}/, 'prototype={valueOf:1,y:1}'); source = source.replace(/prototype\s*=\s*{\s*valueOf\s*:\s*1\s*}/, 'prototype={valueOf:1,y:1}');
@@ -1448,7 +1447,7 @@
stdout.write(source); stdout.write(source);
callback(source); callback(source);
} else { } else {
callback(source, outputPath || path.join(cwd, workingName + '.js')); callback(source, outputPath);
} }
} }
}); });

View File

@@ -9,14 +9,11 @@
spawn = require('child_process').spawn; spawn = require('child_process').spawn;
/** The directory that is the base of the repository */ /** The directory that is the base of the repository */
var basePath = fs.realpathSync(path.join(__dirname, '../')); var basePath = fs.realpathSync(path.join(__dirname, '..'));
/** The directory where the Closure Compiler is located */ /** The directory where the Closure Compiler is located */
var closurePath = path.join(basePath, 'vendor', 'closure-compiler', 'compiler.jar'); var closurePath = path.join(basePath, 'vendor', 'closure-compiler', 'compiler.jar');
/** The distribution directory */
var distPath = path.join(basePath, 'dist');
/** Load other modules */ /** Load other modules */
var preprocess = require('./pre-compile'), var preprocess = require('./pre-compile'),
postprocess = require('./post-compile'), postprocess = require('./post-compile'),
@@ -48,27 +45,27 @@
if (Array.isArray(source)) { if (Array.isArray(source)) {
// convert commands to an options object // convert commands to an options object
options = source; options = source;
var filePath = options[options.length - 1], var filePath = options[options.length - 1],
dirPath = path.dirname(filePath),
isSilent = options.indexOf('-s') > -1 || options.indexOf('--silent') > -1, isSilent = options.indexOf('-s') > -1 || options.indexOf('--silent') > -1,
isTemplate = options.indexOf('-t') > -1 || options.indexOf('--template') > -1, isTemplate = options.indexOf('-t') > -1 || options.indexOf('--template') > -1,
workingName = path.basename(filePath, '.js') + '.min'; outputPath = path.join(path.dirname(filePath), path.basename(filePath, '.js') + '.min.js');
workingName = options.reduce(function(result, value, index) { outputPath = options.reduce(function(result, value, index) {
return /-wn|--working-name/.test(value) if (/-o|--output/.test(value)) {
? options[index + 1] result = options[index + 1];
: result; result = path.join(fs.realpathSync(path.dirname(result)), path.basename(result));
}, workingName); }
return result;
}, outputPath);
var outputPath = path.join(dirPath, workingName + '.js');
source = fs.readFileSync(filePath, 'utf8');
options = { options = {
'isSilent': isSilent, 'isSilent': isSilent,
'isTemplate': isTemplate, 'isTemplate': isTemplate,
'onComplete': function(source) { 'outputPath': outputPath
fs.writeFileSync(outputPath, source, 'utf8');
}
}; };
source = fs.readFileSync(filePath, 'utf8');
} }
new Minify(source, options); new Minify(source, options);
} }
@@ -83,29 +80,24 @@
*/ */
function Minify(source, options) { function Minify(source, options) {
// juggle arguments // juggle arguments
if (typeof source != 'string') { if (typeof source == 'object' && source) {
options = source || options; options = source || options;
source = options.source || ''; source = options.source || '';
} }
// create the destination directory if it doesn't exist
if (!fs.existsSync(distPath)) {
// avoid errors when called as a npm executable
try {
fs.mkdirSync(distPath);
} catch(e) { }
}
this.compiled = {}; this.compiled = {};
this.hybrid = {}; this.hybrid = {};
this.uglified = {}; this.uglified = {};
this.isSilent = !!options.isSilent; this.isSilent = !!options.isSilent;
this.isTemplate = !!options.isTemplate; this.isTemplate = !!options.isTemplate;
this.onComplete = options.onComplete || function() {}; this.outputPath = options.outputPath;
this.workingName = options.workingName;
source = preprocess(source, options); source = preprocess(source, options);
this.source = source; this.source = source;
this.onComplete = options.onComplete || function(source) {
fs.writeFileSync(this.outputPath, source, 'utf8');
};
// begin the minification process // begin the minification process
closureCompile.call(this, source, onClosureCompile.bind(this)); closureCompile.call(this, source, onClosureCompile.bind(this));
} }
@@ -144,7 +136,7 @@
if (!this.isSilent) { if (!this.isSilent) {
console.log(message == null console.log(message == null
? 'Compressing ' + this.workingName + ' using the Closure Compiler...' ? 'Compressing ' + path.basename(this.outputPath, '.js') + ' using the Closure Compiler...'
: message : message
); );
} }
@@ -197,7 +189,7 @@
if (!this.isSilent) { if (!this.isSilent) {
console.log(message == null console.log(message == null
? 'Compressing ' + this.workingName + ' using UglifyJS...' ? 'Compressing ' + path.basename(this.outputPath, '.js') + ' using UglifyJS...'
: message : message
); );
} }
@@ -292,7 +284,7 @@
if (!this.isSilent) { if (!this.isSilent) {
console.log('Done. Size: %d bytes.', result.length); console.log('Done. Size: %d bytes.', result.length);
} }
var message = 'Compressing ' + this.workingName + ' using hybrid minification...'; var message = 'Compressing ' + path.basename(this.outputPath, '.js') + ' using hybrid minification...';
// store the gzipped result and report the size // store the gzipped result and report the size
this.uglified.gzip = result; this.uglified.gzip = result;
@@ -346,24 +338,8 @@
function onComplete() { function onComplete() {
var compiled = this.compiled, var compiled = this.compiled,
hybrid = this.hybrid, hybrid = this.hybrid,
name = this.workingName,
uglified = this.uglified; uglified = this.uglified;
// avoid errors when called as a npm executable
try {
// save the Closure Compiled version to disk
fs.writeFileSync(path.join(distPath, name + '.compiler.js'), compiled.source);
fs.writeFileSync(path.join(distPath, name + '.compiler.js.gz'), compiled.gzip);
// save the Uglified version to disk
fs.writeFileSync(path.join(distPath, name + '.uglify.js'), uglified.source);
fs.writeFileSync(path.join(distPath, name + '.uglify.js.gz'), uglified.gzip);
// save the hybrid minified version to disk
fs.writeFileSync(path.join(distPath, name + '.hybrid.js'), hybrid.source);
fs.writeFileSync(path.join(distPath, name + '.hybrid.js.gz'), hybrid.gzip);
} catch(e) { }
// select the smallest gzipped file and use its minified counterpart as the // select the smallest gzipped file and use its minified counterpart as the
// official minified release (ties go to Closure Compiler) // official minified release (ties go to Closure Compiler)
var min = Math.min(compiled.gzip.length, hybrid.gzip.length, uglified.gzip.length); var min = Math.min(compiled.gzip.length, hybrid.gzip.length, uglified.gzip.length);