我有两个Grunt任务:A和B。A的执行时间是5秒。执行时间B为10秒。
我在预提交脚本中运行这两个任务。这两个任务都是同步的,所以预提交脚本的执行时间是15。我想以某种方式将这两个任务组合在一起,并异步运行它们。因此,执行预提交只需10秒。
有可能吗?
这地狱是行不通的
grunt.registerTask('pre-commit', 'Run sonar and jscs async', function() {
var done = this.async(),
_counter = 0,
asyncTasksCounter = 2,
asyncHelper = function (foo) {
setTimeout(function () {
foo();
_counter++;
if (_counter === asyncTasksCounter) {
done();
}
}, 16.66)
};
asyncHelper(function () {
grunt.task.run('A');
});
asyncHelper(function () {
grunt.task.run('B');
});
});发布于 2016-04-02 16:48:39
我不会用Grunt来做这个的。假设您使用的是npm,我将分别定义这些任务,然后使用npm来运行它们,比如使用shell-executor (Windows和Mac)。
安装后,将任务添加到脚本部分 of package.json,然后使用npm run [scriptname]运行脚本,如npm run prepublish。
scripts: {
"precommit": "shell-exec \"grunt sonar\" \"grunt jscs\"",
}有一个类似的脚本concurrently,它可以很好地处理并发任务。
之所以需要这些模块,是因为变化的OSes处理& (并行)和&& (并发)的方式不同,否则您可以:
"precommit": "grunt sonar & grunt jscs",https://stackoverflow.com/questions/36375885
复制相似问题