Permalink
Browse files

grunt can abort task now

  • Loading branch information...
Hsiaoming Yang
Hsiaoming Yang committed Mar 26, 2013
1 parent 994268e commit 7bd898274398c4bbb57700a80446331eefb6cec5
Showing with 25 additions and 3 deletions.
  1. +25 −3 lib/sdk/grunt.js
View
@@ -70,6 +70,10 @@ grunt.log.warn = function(msg) {
log.warn('warn', msg || '');
return grunt.log;
};
+grunt.log.error = function(msg) {
+ log.error('error', msg || '');
+ return grunt.log;
+};
grunt.log.verbose.warn = function(msg) {
log.debug('warn', msg || '');
return grunt.log;
@@ -184,9 +188,27 @@ function runCli(name, gruntfile) {
grunt.option('gruntfile', gruntfile);
grunt.option('base', process.cwd());
- grunt.task.init([name]);
- grunt.task.run(name);
- grunt.task.start();
+ var task = grunt.task;
+ var fail = grunt.fail;
+
+ var uncaughtHandler = function(e) {
+ fail.fatal(e, fail.code.TASK_FAILURE);
+ };
+ process.on('uncaughtException', uncaughtHandler);
+
+ task.options({
+ error: function(e) {
+ fail.warn(e, fail.code.TASK_FAILURE);
+ },
+ done: function() {
+ process.removeListener('uncaughtException', uncaughtHandler);
+ fail.report();
+ process.exit(0);
+ }
+ });
+ task.init([name]);
+ task.run(name);
+ task.start();
return true;
}
}

0 comments on commit 7bd8982

Please sign in to comment.