Permalink
Browse files

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

  • Loading branch information...
1 parent 2f9fb37 commit 587177a499f499603c9a800ea59ea489354b3c24 @jdalton jdalton committed Sep 30, 2012
Showing with 29 additions and 57 deletions.
  1. +0 −1 .gitignore
  2. +0 −1 .jamignore
  3. +0 −1 .npmignore
  4. +7 −8 build.js
  5. +22 −46 build/minify.js
View
1 .gitignore
@@ -1,4 +1,3 @@
*.custom.*
.DS_Store
-dist/
node_modules/
View
1 .jamignore
@@ -1,6 +1,5 @@
*.custom.*
.*
-dist/
doc/*.php
node_modules/
perf/*.sh
View
1 .npmignore
@@ -1,6 +1,5 @@
*.custom.*
.*
-dist/
doc/*.php
node_modules/
perf/*.html
View
15 build.js
@@ -1410,8 +1410,8 @@
/(?:category|exclude|exports|iife|include|minus|plus)=/.test(options) ||
!_.isEqual(exportsOptions, exportsAll);
- // used to name temporary files created in `dist/`
- var workingName = outputPath
+ // used as the basename of the output path
+ var basename = outputPath
? path.basename(outputPath, '.js')
: 'lodash' + (isTemplate ? '.template' : isCustom ? '.custom' : '');
@@ -1424,18 +1424,17 @@
stdout.write(debugSource);
callback(debugSource);
} 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
if (!isDebug) {
- if (!outputPath) {
- workingName += '.min';
- }
+ outputPath || (outputPath = path.join(cwd, basename + '.min.js'));
+
minify(source, {
'isSilent': isSilent,
'isTemplate': isTemplate,
- 'workingName': workingName,
+ 'outputPath': outputPath,
'onComplete': function(source) {
// correct overly aggressive Closure Compiler minification
source = source.replace(/prototype\s*=\s*{\s*valueOf\s*:\s*1\s*}/, 'prototype={valueOf:1,y:1}');
@@ -1448,7 +1447,7 @@
stdout.write(source);
callback(source);
} else {
- callback(source, outputPath || path.join(cwd, workingName + '.js'));
+ callback(source, outputPath);
}
}
});
View
68 build/minify.js
@@ -9,14 +9,11 @@
spawn = require('child_process').spawn;
/** 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 */
var closurePath = path.join(basePath, 'vendor', 'closure-compiler', 'compiler.jar');
- /** The distribution directory */
- var distPath = path.join(basePath, 'dist');
-
/** Load other modules */
var preprocess = require('./pre-compile'),
postprocess = require('./post-compile'),
@@ -48,27 +45,27 @@
if (Array.isArray(source)) {
// convert commands to an options object
options = source;
+
var filePath = options[options.length - 1],
- dirPath = path.dirname(filePath),
isSilent = options.indexOf('-s') > -1 || options.indexOf('--silent') > -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) {
- return /-wn|--working-name/.test(value)
- ? options[index + 1]
- : result;
- }, workingName);
+ outputPath = options.reduce(function(result, value, index) {
+ if (/-o|--output/.test(value)) {
+ result = options[index + 1];
+ result = path.join(fs.realpathSync(path.dirname(result)), path.basename(result));
+ }
+ return result;
+ }, outputPath);
- var outputPath = path.join(dirPath, workingName + '.js');
- source = fs.readFileSync(filePath, 'utf8');
options = {
'isSilent': isSilent,
'isTemplate': isTemplate,
- 'onComplete': function(source) {
- fs.writeFileSync(outputPath, source, 'utf8');
- }
+ 'outputPath': outputPath
};
+
+ source = fs.readFileSync(filePath, 'utf8');
}
new Minify(source, options);
}
@@ -83,29 +80,24 @@
*/
function Minify(source, options) {
// juggle arguments
- if (typeof source != 'string') {
+ if (typeof source == 'object' && source) {
options = source || options;
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.hybrid = {};
this.uglified = {};
this.isSilent = !!options.isSilent;
this.isTemplate = !!options.isTemplate;
- this.onComplete = options.onComplete || function() {};
- this.workingName = options.workingName;
+ this.outputPath = options.outputPath;
source = preprocess(source, options);
this.source = source;
+ this.onComplete = options.onComplete || function(source) {
+ fs.writeFileSync(this.outputPath, source, 'utf8');
+ };
+
// begin the minification process
closureCompile.call(this, source, onClosureCompile.bind(this));
}
@@ -144,7 +136,7 @@
if (!this.isSilent) {
console.log(message == null
- ? 'Compressing ' + this.workingName + ' using the Closure Compiler...'
+ ? 'Compressing ' + path.basename(this.outputPath, '.js') + ' using the Closure Compiler...'
: message
);
}
@@ -197,7 +189,7 @@
if (!this.isSilent) {
console.log(message == null
- ? 'Compressing ' + this.workingName + ' using UglifyJS...'
+ ? 'Compressing ' + path.basename(this.outputPath, '.js') + ' using UglifyJS...'
: message
);
}
@@ -292,7 +284,7 @@
if (!this.isSilent) {
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
this.uglified.gzip = result;
@@ -346,24 +338,8 @@
function onComplete() {
var compiled = this.compiled,
hybrid = this.hybrid,
- name = this.workingName,
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
// official minified release (ties go to Closure Compiler)
var min = Math.min(compiled.gzip.length, hybrid.gzip.length, uglified.gzip.length);

0 comments on commit 587177a

Please sign in to comment.