Skip to content

Commit

Permalink
Revert PR #120 and PR #118 due to issues when using shifter thru yogi
Browse files Browse the repository at this point in the history
This reverts commit 930273f, reversing
changes made to 4199a12.
  • Loading branch information
caridy committed Apr 15, 2014
1 parent 654e4a3 commit 92dd95a
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 427 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ CVS/
*~
.com.apple.timemachine.supported
tests/assets/yql/build/*/*
tests/assets/badmodule/build/*/*
tests/assets/badrollup/build/*/*
tests/assets-global
tests/assets/freestyle/build
coverage
6 changes: 0 additions & 6 deletions conf/docs/index.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,3 @@ I've added a `--lint-stderr` config option which forces all lint output to `stde
<p>
Adding `--recursive` to the `--walk` command will tell `shifter` to walk the directories recursively looking for `build.json` files.
</p>

<h3 id="exp.err.hand.prog">Error handling when shifter is called programmatically</h3>

<p>
When `shifter` is called programmatically, build errors such as UglifyJS parsing errors, are propagated through callback routines. This allows another external build process that uses `shifter` to handle the errors accordingly.
</p>
2 changes: 1 addition & 1 deletion lib/ant.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ exports.process = function (options, callback) {
}
});
} else {
callback('no .properties files located, hit the brakes');
log.error('no .properties files located, hit the brakes');
}

});
Expand Down
34 changes: 9 additions & 25 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var prebuild = function (jobs, options, callback) {
child.on('exit', stack.add(function (code) {
log.info('build for ' + job + ' complete, downshifting');
if (code) {
callback('prebuild ' + job + ' failed, exited with code ' + code + ', hitting the brakes, fix it and try again!');
log.error('prebuild ' + job + ' failed, exited with code ' + code + ', hitting the brakes, fix it and try again!');
}
}));
});
Expand All @@ -81,22 +81,18 @@ exports.start = function (json, options, buildCallback) {
start = new Date(),
hasSkin = false,
buildStat,
end = function (err) {
end = function () {
var end = new Date();
log.info('done racing, the gears are toast');
log.info('finished in ' + timer.calc(start, end) + ', pretty fast huh?');
if (buildCallback) {
buildCallback(err);
buildCallback();
}
},
post = function (json, callback) {
if (json.postbuilds && options.exec) {
log.info('found a postbuild, shifting it');
prebuild(json.postbuilds, options, function (err) {
if (err) {
return buildCallback(err);
}

prebuild(json.postbuilds, options, function () {
delete json.postbuilds;
post(json, callback);
});
Expand All @@ -112,11 +108,7 @@ exports.start = function (json, options, buildCallback) {

if (json.prebuilds && options.exec) {
log.info('found a prebuild, shifting it');
prebuild(json.prebuilds, options, function (err) {
if (err) {
return buildCallback(err);
}

prebuild(json.prebuilds, options, function () {
delete json.prebuilds;
exports.start(json, options, buildCallback);
});
Expand All @@ -137,22 +129,17 @@ exports.start = function (json, options, buildCallback) {
json2 = JSON.parse(fs.readFileSync(options.buildFile, 'utf8'));
} catch (e) {
console.log(e.stack);
buildCallback('hitting the brakes! failed to parse ' + options.buildFileName + ', syntax error?');
log.error('hitting the brakes! failed to parse ' + options.buildFileName + ', syntax error?');
}

if (pack.valid(json2)) {
pack.munge(json2, options, function (err, json2, options) {
pack.munge(json2, options, function (json2, options) {
delete json2.exec;
delete json2.prebuilds;

if (err) {
return buildCallback(err);
}

exports.start(json2, options, buildCallback);
});
} else {
buildCallback('hitting the brakes, your ' + options.buildFileName + ' file is invalid, please fix it!');
log.error('hitting the brakes, your ' + options.buildFileName + ' file is invalid, please fix it!');
}
} else {
exports.start(json, options, buildCallback);
Expand Down Expand Up @@ -181,10 +168,7 @@ exports.start = function (json, options, buildCallback) {
}
});

stack.done(function (err) {
if (err) {
return end(err);
}
stack.done(function () {
var rollups = [];
if (json.rollups) {
log.info('build has rollup builds, shifting them now');
Expand Down
56 changes: 19 additions & 37 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,19 @@ var runQueue = function() {
var item = queue.pop();
if (item) {
buildRunning = true;
exports.init(item.opts, function(err) {
exports.init(item.opts, function() {
buildRunning = false;
if (err) {
return item.callback(err);
}
item.callback();
runQueue();
});
}
}
};

function logAndExit(err) {
if (err) {
log.err(err);
process.exit(1);
}
}

exports.add = function(opts, callback) {
queue.push({
opts: opts,
callback: callback || logAndExit
callback: callback
});
runQueue();
};
Expand All @@ -69,10 +59,6 @@ exports.init = function (opts, initCallback) {

log.reset(options);

if (!initCallback) {
initCallback = logAndExit;
}

if (options.cwd) {
CWD = options.cwd;
}
Expand All @@ -96,15 +82,15 @@ exports.init = function (opts, initCallback) {
require('./help');
return;
}

if (options.quiet) {
log.quiet();
}

if (options.silent) {
log.silent();
}

if (options['global-config']) {
log.info('racing to find the closest .shifter.json file');
find(CWD, '.shifter.json', function(err, file) {
Expand Down Expand Up @@ -143,23 +129,19 @@ exports.init = function (opts, initCallback) {
var json, walk, ant, mods, builder;
if (yes) {
if (options.ant) {
return initCallback('already has a ' + buildFileName + ' file, hitting the brakes');
log.error('already has a ' + buildFileName + ' file, hitting the brakes');
}
log.info('found ' + buildFileName + ' file, shifting');
if (path.extname(buildFileName) === '.json') {
try {
json = require(buildFile);
} catch (e) {
console.log(e.stack);
return initCallback('hitting the brakes! failed to parse ' + buildFileName + ', syntax error?');
log.error('hitting the brakes! failed to parse ' + buildFileName + ', syntax error?');
}
if (pack.valid(json)) {
log.info('putting the hammer down, let\'s build this thing!');
pack.munge(json, options, function (err, json, options) {
if (err) {
return initCallback(err);
}

pack.munge(json, options, function (json, options) {
if (options.list) {
mods = Object.keys(json.builds).sort();
log.info('This module includes these builds:');
Expand All @@ -171,14 +153,16 @@ exports.init = function (opts, initCallback) {
} else {
builder = require('./builder');
builder.reset();
builder.start(json, options, function(err) {
builder.start(json, options, function() {
buildRunning = false;
initCallback(err);
if (initCallback) {
initCallback();
}
});
}
});
} else {
return initCallback('hitting the brakes, your ' + buildFileName + ' file is invalid, please fix it!');
log.error('hitting the brakes, your ' + buildFileName + ' file is invalid, please fix it!');
}
} else if (path.extname(buildFileName) === '.js') {
// probably a row module
Expand All @@ -195,21 +179,23 @@ exports.init = function (opts, initCallback) {
vm.runInContext(fs.readFileSync(buildFile, 'utf8'),
contextForRunInContext, buildFile);
} catch (e) {
return initCallback('hitting the brakes, your ' + buildFileName + ' file is invalid, please fix it!');
log.error('hitting the brakes, your ' + buildFileName + ' file is invalid, please fix it!');
}
if (mods) {
// raw yui module without build.json
builder = require('./builder');
builder.reset();
builder.start({
builds: mods
}, options, function(err) {
}, options, function() {
buildRunning = false;
initCallback(err);
if (initCallback) {
initCallback();
}
});
}
} else {
return initCallback('hitting the brakes, your ' + buildFileName + ' file is invalid, please fix it!');
log.error('hitting the brakes, your ' + buildFileName + ' file is invalid, please fix it!');
}
} else {
if (options.walk) {
Expand All @@ -220,11 +206,7 @@ exports.init = function (opts, initCallback) {
} else {
log.warn('no ' + buildFileName + ' file, downshifting to convert ant files');
ant = require('./ant');
ant.process(options, function (err) {
if (err) {
return initCallback(err);
}

ant.process(options, function () {
if (!options.ant) {
exports.init(options, initCallback);
}
Expand Down
8 changes: 7 additions & 1 deletion lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,19 @@ exports.warn = function (str) {
}
};

exports.error = function (str) {
if (!silent) {
console.error(prefix, exports.color('[error]', 'red'), str);
}
process.exit(1);
};

exports.err = function (str) {
if (!silent) {
console.error(prefix, exports.color('[err]', 'red'), str);
}
};

exports.error = exports.err;

exports.console = {
log: function() {
Expand Down
31 changes: 13 additions & 18 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ var Stack = require('./stack').Stack,
callback: function (e) {
log.err('compression failed');
log.console.log(' ' + String(e.message).trim() + log.color(' // line ' + e.line + ', pos ' + e.col, 'white'));
log.err('dropped the clutch, build failed');
// Not calling back here, the jsminify task will callback with an error, failing the queue
log.error('dropped the clutch, build failed');
}
};
}
Expand Down Expand Up @@ -92,8 +91,7 @@ var Stack = require('./stack').Stack,
}
});
if (lintFail) {
// Return an error to callback with, which should fail the build
return 'lint failed, aborting build';
log.error('lint failed, aborting build');
}
} else {
log.info('css lint passed for ' + file);
Expand Down Expand Up @@ -143,8 +141,7 @@ var Stack = require('./stack').Stack,
}
});
if (lintFail) {
// Return an error to callback with, which should fail the build
return 'lint failed, aborting build';
log.error('lint failed, aborting build');
}
}
}
Expand Down Expand Up @@ -365,13 +362,13 @@ var buildJS = function (mod, name, callback) {
if (err) {
if (/file has not changed/.test(err)) {
log.warn(name + ': ' + err);
} else if (/ENOENT/.test(err)) {
log.err('Failed to open file: ' + err.path);
} else {
if (/ENOENT/.test(err)) {
log.error('Failed to open file: ' + err.path);
}
log.err(name + ': ' + err);
}
}

callback(err, result);
});

Expand Down Expand Up @@ -501,8 +498,7 @@ var buildSkin = function (mod, name, callback) {
fs.readdir(path.join(shifter.cwd(), 'assets', subMod, 'skins'), stack.add(function (err, skins) {
if (err) {
log.console.log(err);
log.err('skin files are not right!');
return;
log.error('skin files are not right!');
}

//Walk the skins and write them out
Expand Down Expand Up @@ -544,8 +540,7 @@ var buildSkin = function (mod, name, callback) {
if (err) {
log.err(err);
if (err.code === 'ENOENT') {
log.err('skin file is missing: ' + err.path);
return;
log.error('skin file is missing: ' + err.path);
}
}

Expand Down Expand Up @@ -743,10 +738,10 @@ var build = function (mod, name, options, callback) {



stack.done(function (errs) {
stack.done(function () {
if (!stack.complete) {
stack.complete = true;
callback(errs);
callback();
}
});
};
Expand Down Expand Up @@ -815,11 +810,11 @@ exports.build = function (mod, name, options, callback) {

mod.buildDir = options['build-dir'];

var end = function (err) {
var end = function () {
if (mod.postexec) {
exec(mod.postexec, name, callback);
} else {
callback(err);
callback();
}
};
if (mod.exec) {
Expand Down Expand Up @@ -884,7 +879,7 @@ var _rollup = function (mod, name, options, callback) {
.write(path.join(mod.buildDir, fileName, fileName + '-min.js'))
.run(function (err) {
if (err) {
return callback(name + ' rollup: ' + err);
log.error(name + ' rollup: ' + err);
}
callback();
});
Expand Down
Loading

0 comments on commit 92dd95a

Please sign in to comment.