2013-05-10 31 views
5

我想創建一個連續運行3個grunt任務的grunt文件,不管它們是失敗還是通過。如果其中一個咕嚕聲任務失敗,我想返回最後一個錯誤代碼。Gruntfile從程序串行獲取錯誤代碼

我想:

grunt.task.run('task1', 'task2', 'task3'); 

--force選項運行時。

問題是,當指定--force時,無論錯誤如何,它都會返回錯誤代碼0。

感謝

回答

7

使用grunt.util.spawnhttp://gruntjs.com/api/grunt.util#grunt.util.spawn

grunt.registerTask('serial', function() { 
    var done = this.async(); 
    var tasks = {'task1': 0, 'task2': 0, 'task3': 0}; 
    grunt.util.async.forEachSeries(Object.keys(tasks), function(task, next) { 
    grunt.util.spawn({ 
     grunt: true, // use grunt to spawn 
     args: [task], // spawn this task 
     opts: { stdio: 'inherit' }, // print to the same stdout 
    }, function(err, result, code) { 
     tasks[task] = code; 
     next(); 
    }); 
    }, function() { 
    // Do something with tasks now that each 
    // contains their respective error code 
    done(); 
    }); 
}); 
+0

你有一個額外的逗號'選擇採用後:{標準輸入輸出: '繼承'}'而美麗非常感謝! – GTDev 2013-06-04 15:03:04

+0

這是有目的的;)尾節點逗號在節點> = 0.8中很酷。至少我認爲是如此 – 2013-06-04 18:37:06

相關問題