Skip to content

Commit 92dd95a

Browse files
committed
Revert PR #120 and PR #118 due to issues when using shifter thru yogi
This reverts commit 930273f, reversing changes made to 4199a12.
1 parent 654e4a3 commit 92dd95a

22 files changed

+109
-427
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ CVS/
99
*~
1010
.com.apple.timemachine.supported
1111
tests/assets/yql/build/*/*
12-
tests/assets/badmodule/build/*/*
13-
tests/assets/badrollup/build/*/*
1412
tests/assets-global
1513
tests/assets/freestyle/build
1614
coverage

conf/docs/index.mustache

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,3 @@ I've added a `--lint-stderr` config option which forces all lint output to `stde
485485
<p>
486486
Adding `--recursive` to the `--walk` command will tell `shifter` to walk the directories recursively looking for `build.json` files.
487487
</p>
488-
489-
<h3 id="exp.err.hand.prog">Error handling when shifter is called programmatically</h3>
490-
491-
<p>
492-
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.
493-
</p>

lib/ant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ exports.process = function (options, callback) {
137137
}
138138
});
139139
} else {
140-
callback('no .properties files located, hit the brakes');
140+
log.error('no .properties files located, hit the brakes');
141141
}
142142

143143
});

lib/builder.js

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var prebuild = function (jobs, options, callback) {
6767
child.on('exit', stack.add(function (code) {
6868
log.info('build for ' + job + ' complete, downshifting');
6969
if (code) {
70-
callback('prebuild ' + job + ' failed, exited with code ' + code + ', hitting the brakes, fix it and try again!');
70+
log.error('prebuild ' + job + ' failed, exited with code ' + code + ', hitting the brakes, fix it and try again!');
7171
}
7272
}));
7373
});
@@ -81,22 +81,18 @@ exports.start = function (json, options, buildCallback) {
8181
start = new Date(),
8282
hasSkin = false,
8383
buildStat,
84-
end = function (err) {
84+
end = function () {
8585
var end = new Date();
8686
log.info('done racing, the gears are toast');
8787
log.info('finished in ' + timer.calc(start, end) + ', pretty fast huh?');
8888
if (buildCallback) {
89-
buildCallback(err);
89+
buildCallback();
9090
}
9191
},
9292
post = function (json, callback) {
9393
if (json.postbuilds && options.exec) {
9494
log.info('found a postbuild, shifting it');
95-
prebuild(json.postbuilds, options, function (err) {
96-
if (err) {
97-
return buildCallback(err);
98-
}
99-
95+
prebuild(json.postbuilds, options, function () {
10096
delete json.postbuilds;
10197
post(json, callback);
10298
});
@@ -112,11 +108,7 @@ exports.start = function (json, options, buildCallback) {
112108

113109
if (json.prebuilds && options.exec) {
114110
log.info('found a prebuild, shifting it');
115-
prebuild(json.prebuilds, options, function (err) {
116-
if (err) {
117-
return buildCallback(err);
118-
}
119-
111+
prebuild(json.prebuilds, options, function () {
120112
delete json.prebuilds;
121113
exports.start(json, options, buildCallback);
122114
});
@@ -137,22 +129,17 @@ exports.start = function (json, options, buildCallback) {
137129
json2 = JSON.parse(fs.readFileSync(options.buildFile, 'utf8'));
138130
} catch (e) {
139131
console.log(e.stack);
140-
buildCallback('hitting the brakes! failed to parse ' + options.buildFileName + ', syntax error?');
132+
log.error('hitting the brakes! failed to parse ' + options.buildFileName + ', syntax error?');
141133
}
142134

143135
if (pack.valid(json2)) {
144-
pack.munge(json2, options, function (err, json2, options) {
136+
pack.munge(json2, options, function (json2, options) {
145137
delete json2.exec;
146138
delete json2.prebuilds;
147-
148-
if (err) {
149-
return buildCallback(err);
150-
}
151-
152139
exports.start(json2, options, buildCallback);
153140
});
154141
} else {
155-
buildCallback('hitting the brakes, your ' + options.buildFileName + ' file is invalid, please fix it!');
142+
log.error('hitting the brakes, your ' + options.buildFileName + ' file is invalid, please fix it!');
156143
}
157144
} else {
158145
exports.start(json, options, buildCallback);
@@ -181,10 +168,7 @@ exports.start = function (json, options, buildCallback) {
181168
}
182169
});
183170

184-
stack.done(function (err) {
185-
if (err) {
186-
return end(err);
187-
}
171+
stack.done(function () {
188172
var rollups = [];
189173
if (json.rollups) {
190174
log.info('build has rollup builds, shifting them now');

lib/index.js

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,19 @@ var runQueue = function() {
3434
var item = queue.pop();
3535
if (item) {
3636
buildRunning = true;
37-
exports.init(item.opts, function(err) {
37+
exports.init(item.opts, function() {
3838
buildRunning = false;
39-
if (err) {
40-
return item.callback(err);
41-
}
4239
item.callback();
4340
runQueue();
4441
});
4542
}
4643
}
4744
};
4845

49-
function logAndExit(err) {
50-
if (err) {
51-
log.err(err);
52-
process.exit(1);
53-
}
54-
}
55-
5646
exports.add = function(opts, callback) {
5747
queue.push({
5848
opts: opts,
59-
callback: callback || logAndExit
49+
callback: callback
6050
});
6151
runQueue();
6252
};
@@ -69,10 +59,6 @@ exports.init = function (opts, initCallback) {
6959

7060
log.reset(options);
7161

72-
if (!initCallback) {
73-
initCallback = logAndExit;
74-
}
75-
7662
if (options.cwd) {
7763
CWD = options.cwd;
7864
}
@@ -96,15 +82,15 @@ exports.init = function (opts, initCallback) {
9682
require('./help');
9783
return;
9884
}
99-
85+
10086
if (options.quiet) {
10187
log.quiet();
10288
}
10389

10490
if (options.silent) {
10591
log.silent();
10692
}
107-
93+
10894
if (options['global-config']) {
10995
log.info('racing to find the closest .shifter.json file');
11096
find(CWD, '.shifter.json', function(err, file) {
@@ -143,23 +129,19 @@ exports.init = function (opts, initCallback) {
143129
var json, walk, ant, mods, builder;
144130
if (yes) {
145131
if (options.ant) {
146-
return initCallback('already has a ' + buildFileName + ' file, hitting the brakes');
132+
log.error('already has a ' + buildFileName + ' file, hitting the brakes');
147133
}
148134
log.info('found ' + buildFileName + ' file, shifting');
149135
if (path.extname(buildFileName) === '.json') {
150136
try {
151137
json = require(buildFile);
152138
} catch (e) {
153139
console.log(e.stack);
154-
return initCallback('hitting the brakes! failed to parse ' + buildFileName + ', syntax error?');
140+
log.error('hitting the brakes! failed to parse ' + buildFileName + ', syntax error?');
155141
}
156142
if (pack.valid(json)) {
157143
log.info('putting the hammer down, let\'s build this thing!');
158-
pack.munge(json, options, function (err, json, options) {
159-
if (err) {
160-
return initCallback(err);
161-
}
162-
144+
pack.munge(json, options, function (json, options) {
163145
if (options.list) {
164146
mods = Object.keys(json.builds).sort();
165147
log.info('This module includes these builds:');
@@ -171,14 +153,16 @@ exports.init = function (opts, initCallback) {
171153
} else {
172154
builder = require('./builder');
173155
builder.reset();
174-
builder.start(json, options, function(err) {
156+
builder.start(json, options, function() {
175157
buildRunning = false;
176-
initCallback(err);
158+
if (initCallback) {
159+
initCallback();
160+
}
177161
});
178162
}
179163
});
180164
} else {
181-
return initCallback('hitting the brakes, your ' + buildFileName + ' file is invalid, please fix it!');
165+
log.error('hitting the brakes, your ' + buildFileName + ' file is invalid, please fix it!');
182166
}
183167
} else if (path.extname(buildFileName) === '.js') {
184168
// probably a row module
@@ -195,21 +179,23 @@ exports.init = function (opts, initCallback) {
195179
vm.runInContext(fs.readFileSync(buildFile, 'utf8'),
196180
contextForRunInContext, buildFile);
197181
} catch (e) {
198-
return initCallback('hitting the brakes, your ' + buildFileName + ' file is invalid, please fix it!');
182+
log.error('hitting the brakes, your ' + buildFileName + ' file is invalid, please fix it!');
199183
}
200184
if (mods) {
201185
// raw yui module without build.json
202186
builder = require('./builder');
203187
builder.reset();
204188
builder.start({
205189
builds: mods
206-
}, options, function(err) {
190+
}, options, function() {
207191
buildRunning = false;
208-
initCallback(err);
192+
if (initCallback) {
193+
initCallback();
194+
}
209195
});
210196
}
211197
} else {
212-
return initCallback('hitting the brakes, your ' + buildFileName + ' file is invalid, please fix it!');
198+
log.error('hitting the brakes, your ' + buildFileName + ' file is invalid, please fix it!');
213199
}
214200
} else {
215201
if (options.walk) {
@@ -220,11 +206,7 @@ exports.init = function (opts, initCallback) {
220206
} else {
221207
log.warn('no ' + buildFileName + ' file, downshifting to convert ant files');
222208
ant = require('./ant');
223-
ant.process(options, function (err) {
224-
if (err) {
225-
return initCallback(err);
226-
}
227-
209+
ant.process(options, function () {
228210
if (!options.ant) {
229211
exports.init(options, initCallback);
230212
}

lib/log.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,19 @@ exports.warn = function (str) {
5757
}
5858
};
5959

60+
exports.error = function (str) {
61+
if (!silent) {
62+
console.error(prefix, exports.color('[error]', 'red'), str);
63+
}
64+
process.exit(1);
65+
};
66+
6067
exports.err = function (str) {
6168
if (!silent) {
6269
console.error(prefix, exports.color('[err]', 'red'), str);
6370
}
6471
};
6572

66-
exports.error = exports.err;
6773

6874
exports.console = {
6975
log: function() {

lib/module.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ var Stack = require('./stack').Stack,
5555
callback: function (e) {
5656
log.err('compression failed');
5757
log.console.log(' ' + String(e.message).trim() + log.color(' // line ' + e.line + ', pos ' + e.col, 'white'));
58-
log.err('dropped the clutch, build failed');
59-
// Not calling back here, the jsminify task will callback with an error, failing the queue
58+
log.error('dropped the clutch, build failed');
6059
}
6160
};
6261
}
@@ -92,8 +91,7 @@ var Stack = require('./stack').Stack,
9291
}
9392
});
9493
if (lintFail) {
95-
// Return an error to callback with, which should fail the build
96-
return 'lint failed, aborting build';
94+
log.error('lint failed, aborting build');
9795
}
9896
} else {
9997
log.info('css lint passed for ' + file);
@@ -143,8 +141,7 @@ var Stack = require('./stack').Stack,
143141
}
144142
});
145143
if (lintFail) {
146-
// Return an error to callback with, which should fail the build
147-
return 'lint failed, aborting build';
144+
log.error('lint failed, aborting build');
148145
}
149146
}
150147
}
@@ -365,13 +362,13 @@ var buildJS = function (mod, name, callback) {
365362
if (err) {
366363
if (/file has not changed/.test(err)) {
367364
log.warn(name + ': ' + err);
368-
} else if (/ENOENT/.test(err)) {
369-
log.err('Failed to open file: ' + err.path);
370365
} else {
366+
if (/ENOENT/.test(err)) {
367+
log.error('Failed to open file: ' + err.path);
368+
}
371369
log.err(name + ': ' + err);
372370
}
373371
}
374-
375372
callback(err, result);
376373
});
377374

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

508504
//Walk the skins and write them out
@@ -544,8 +540,7 @@ var buildSkin = function (mod, name, callback) {
544540
if (err) {
545541
log.err(err);
546542
if (err.code === 'ENOENT') {
547-
log.err('skin file is missing: ' + err.path);
548-
return;
543+
log.error('skin file is missing: ' + err.path);
549544
}
550545
}
551546

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

744739

745740

746-
stack.done(function (errs) {
741+
stack.done(function () {
747742
if (!stack.complete) {
748743
stack.complete = true;
749-
callback(errs);
744+
callback();
750745
}
751746
});
752747
};
@@ -815,11 +810,11 @@ exports.build = function (mod, name, options, callback) {
815810

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

818-
var end = function (err) {
813+
var end = function () {
819814
if (mod.postexec) {
820815
exec(mod.postexec, name, callback);
821816
} else {
822-
callback(err);
817+
callback();
823818
}
824819
};
825820
if (mod.exec) {
@@ -884,7 +879,7 @@ var _rollup = function (mod, name, options, callback) {
884879
.write(path.join(mod.buildDir, fileName, fileName + '-min.js'))
885880
.run(function (err) {
886881
if (err) {
887-
return callback(name + ' rollup: ' + err);
882+
log.error(name + ' rollup: ' + err);
888883
}
889884
callback();
890885
});

0 commit comments

Comments
 (0)