Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove the entire directory when running a clean build with walk #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ exports.init = function (opts, initCallback) {
walk = require('./walk');
// Use the less-processed opts here instead - we don't want the defaults to override the individual
// Shifter configurations.
walk.run(args.baseOptions(opts), initCallback);
// We do also need to pass the full set of options as the logic within walk may require them.
walk.run(args.baseOptions(opts), options, initCallback);
} else {
log.warn('no ' + buildFileName + ' file, downshifting to convert ant files');
ant = require('./ant');
Expand Down
175 changes: 94 additions & 81 deletions lib/walk.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var log = require('./log'),
timer = require('timethat'),
fs = require('fs'),
path = require('path'),
rimraf = require('rimraf'),
shifter = require('./'),
spawn = require('child_process').spawn,
util = require('./util'),
Expand All @@ -14,29 +15,29 @@ var log = require('./log'),
});
};

exports.run = function (options, callback) {
exports.run = function (cliOptions, filledOptions, callback) {
if (!log.isTTY) {
options.progress = false;
cliOptions.progress = false;
}
log.info('racing the directories');
var modStack = new Stack(),
start = new Date(),
mods = [],
excludes = {},
max = options.max || false,
max = cliOptions.max || false,
bar,
ProgressBar,
i,
args = [],
checkDirectory;

if (options.excludes && options.excludes.length) {
options.excludes.forEach(function(mod) {
if (cliOptions.excludes && cliOptions.excludes.length) {
cliOptions.excludes.forEach(function(mod) {
excludes[mod] = mod;
});
}

if (options.progress) {
if (cliOptions.progress) {
ProgressBar = require('progress');
bar = new ProgressBar(log.color(' shifting [', 'magenta') +
log.color(':bar', 'cyan') + log.color(']', 'magenta') +
Expand All @@ -47,56 +48,57 @@ exports.run = function (options, callback) {
incomplete: ' '
});
}
if (options.cssproc) {
if (cliOptions.cssproc) {
args.push('--cssproc');
args.push(options.cssproc);
args.push(cliOptions.cssproc);
}
if (options.compressor) {
if (cliOptions.compressor) {
args.push('--compressor');
}
if (options.clean) {
args.push('--clean');
}
if (options.semi === false) {
if (cliOptions.semi === false) {
args.push('--no-semi');
}
if (options.coverage === false) {
if (cliOptions.coverage === false) {
args.push('--no-coverage');
}
if (options.cache) {
if (cliOptions.cache) {
args.push('--cache');
}
if (options.istanbul) {
if (cliOptions.istanbul) {
args.push('--istanbul');
}
if (options.lint) {
if (cliOptions.lint) {
args.push('--lint');
args.push(options.lint);
args.push(cliOptions.lint);
}
if (options.lint === false) {
if (cliOptions.lint === false) {
args.push('--no-lint');
}
if (options.csslint === false) {
if (cliOptions.csslint === false) {
args.push('--no-csslint');
}
if (options['lint-stderr']) {
if (cliOptions['lint-stderr']) {
args.push('--lint-stderr');
}
if (options.strict) {
if (cliOptions.strict) {
args.push('--strict');
}
if (options.assets === false) {
if (cliOptions.assets === false) {
args.push('--no-assets');
}

if (options['build-dir']) {
if (cliOptions['build-dir']) {
args.push('--build-dir');
args.push(options['build-dir']);
args.push(cliOptions['build-dir']);
}

Object.keys(options).forEach(function (k) {
// Ensure that the clean option is undefined - this should only affect
// the walk, not the shifts within it
args.push('--no-clean');

Object.keys(cliOptions).forEach(function (k) {
if (k.indexOf('replace-') === 0) {
args.push('--' + k + '=' + options[k]);
args.push('--' + k + '=' + cliOptions[k]);
}
});

Expand All @@ -114,11 +116,11 @@ exports.run = function (options, callback) {
exists(path.join(p, 'build.json'), modStack.add(function (yes) {
var relative, stat;
if (yes) {
if (!options.modules || has(options.modules, mod)) {
if (!cliOptions.modules || has(cliOptions.modules, mod)) {
relative = workingdir.replace(startdir, '');
mods.push(path.join(relative, mod));
}
} else if (options.recursive) {
} else if (cliOptions.recursive) {
stat = fs.statSync(p);
if (stat.isDirectory()) {
checkDirectory(startdir, p);
Expand All @@ -128,64 +130,75 @@ exports.run = function (options, callback) {
}
});
}));
};

checkDirectory(shifter.cwd(), shifter.cwd());
modStack.done(function () {
if (!mods.length) {
return callback('no modules found, hitting the brakes.');
}
if (bar) {
bar.total = mods.length - 1;
}
log.info('found ' + mods.length + ' modules to race' + ((max) ? ' (' + max + ' at a time)' : '') + ', 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 = [],
run = function () {
var mod = mods.pop(), child;
if (mod) {
child = spawn(process.execPath, args, {
cwd: path.join(shifter.cwd(), mod),
stdio: [process.stdin, 'ignore', process.stderr]
});
child.on('exit', stack.add(function (code) {
if (cliOptions.progress) {
bar.tick();
} else {
process.stdout.write((code ? log.color('!', 'red') : log.color('.', 'white')));
}
if (code) {
errors.push(mod);
}
run();
}));
}
};

modStack.done(function () {
if (!mods.length) {
return callback('no modules found, hitting the brakes.');
}
if (bar) {
bar.total = mods.length - 1;
}
log.info('found ' + mods.length + ' modules to race' + ((max) ? ' (' + max + ' at a time)' : '') + ', 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 = [],
run = function () {
var mod = mods.pop(), child;
if (mod) {
child = spawn(process.execPath, args, {
cwd: path.join(shifter.cwd(), mod),
stdio: [process.stdin, 'ignore', process.stderr]
});
child.on('exit', stack.add(function (code) {
if (options.progress) {
bar.tick();
} else {
process.stdout.write((code ? log.color('!', 'red') : log.color('.', 'white')));
}
if (code) {
errors.push(mod);
}
run();
}));
if (max) {
for (i = 0; i < max; i = i + 1) {
run();
}
};

if (max) {
for (i = 0; i < max; i = i + 1) {
} else {
run();
}
} else {
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');
errors.forEach(function (mod) {
console.log(' ', log.color(mod, 'red'));
});
callback('Walk failed, ' + errors.length + ' builds exited with a 1');
} else if (typeof callback === 'function') {
callback();
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');
errors.forEach(function (mod) {
console.log(' ', log.color(mod, 'red'));
});
callback('Walk failed, ' + errors.length + ' builds exited with a 1');
} else if (typeof callback === 'function') {
callback();
}
});
});
};

if (filledOptions.clean) {
log.info('deleting build dir: ' + path.join(filledOptions['build-dir']));
rimraf(path.join(filledOptions['build-dir']), function(err) {
if (err) {
return callback(err);
} else {
checkDirectory(shifter.cwd(), shifter.cwd());
}
});
});
} else {
checkDirectory(shifter.cwd(), shifter.cwd());
}
};