Skip to content

Commit

Permalink
Added directory walking
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Aug 21, 2012
1 parent adc8d39 commit f9c2ecc
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Options
-m/--modules <module> limit the modules to build (array: -m foo -m bar)
--lint [preferred|defaults|strict] (preferred is the default) lint mode: https://github.com/yui/yui-lint
--strict add "use strict" to module wrapper
--walk Walk the current directory and shift all builds. (cd yui3/src && shifter --walk)

Usage
-----
Expand Down
2 changes: 2 additions & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ var nopt = require('nopt'),
help: Boolean,
strict: Boolean,
modules: Array,
walk: Boolean,
lint: [ 'defaults', 'strict', 'preferred' ]
},
shorts = {
"w": ["--walk"],
"mods" : ["--modules"],
"v" : ["--version"],
"h" : ["--help"],
Expand Down
1 change: 1 addition & 0 deletions lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if (args.help) {
console.log(' -m/--modules <module> limit the modules to build (array: -m foo -m bar)');
console.log(' --lint [preferred|defaults|strict] (preferred is the default) lint mode: https://github.com/yui/yui-lint');
console.log(' --strict add "use strict" to module wrapper');
console.log(' --walk Walk the current directory and shift all builds. (cd yui3/src && shifter --walk)');
}

process.exit(0);
19 changes: 13 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ exports.init = function() {
}

log.info('revving up');
log.info('looking for build.json file');
if (!options.walk) {
log.info('looking for build.json file');
}
var buildFile = path.join(process.cwd(), 'build.json');
exists(buildFile, function(yes) {
if (yes) {
Expand All @@ -40,11 +42,16 @@ exports.init = function() {
log.error('hitting the brakes, your build.json file is invalid, please fix it!');
}
} else {
log.warn('no build.json file, downshifting to convert ant files');
var ant = require('./ant');
ant.process(function() {
exports.init();
});
if (options.walk) {
var walk = require('./walk');
walk.run();
} else {
log.warn('no build.json file, downshifting to convert ant files');
var ant = require('./ant');
ant.process(function() {
exports.init();
});
}
}
});
};
72 changes: 72 additions & 0 deletions lib/walk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

var log = require('./log'),
Stack = require('./stack').Stack,
timer = require('./timer'),
fs = require('fs'),
path = require('path'),
spawn = require('child_process').spawn,
exists = fs.exists || path.exists;

exports.run = function() {
log.info('racing the directories');
var modStack = new Stack(),
start = new Date(),
mods = [];

fs.readdir(process.cwd(), modStack.add(function(err, dirs) {
dirs.forEach(function(mod) {
var p = path.join(process.cwd(), mod);
exists(path.join(p, 'build.json'), modStack.add(function(yes) {
if (yes) {
mods.push(mod);
} else {
exists(path.join(p, 'build.xml'), modStack.add(function(yes) {
if (yes) {
mods.push(mod);
}
}));
}
}));
});
}));

modStack.done(function() {
if (!mods.length) {
log.error('no modules found, hitting the brakes.');
}
log.info('found ' + mods.length + ' modules to race, let\'s do this');
log.warn('this will be quiet, only status will be emitted for speed. failed builds will print after');
var stack = new Stack(),
errors = [];

var run = function() {
var mod = mods.pop();
if (mod) {
var child = spawn('shifter', [], {
cwd: path.join(process.cwd(), mod),
stdio: ['ignore', 'ignore', process.stderr]
});
child.on('exit', stack.add(function(code) {
process.stdout.write((code ? '!'.red : '.'.white));
if (code) {
errors.push(mod);
}
run();
}));
}
};

run();

stack.done(function() {
console.log('');
var end = new Date();
log.info('done racing, the gears are toast');
log.info('finished in ' + timer.calc(start, end) + ', pretty fast huh?');
if (errors.length) {
log.warn('the following builds exited with a 1');
console.log(errors.join(', '));
}
});
});
};

0 comments on commit f9c2ecc

Please sign in to comment.