我设置了以下三个任务,它们使用grunt.util.spawn处理各种Git任务:
grunt.registerTask('git-add', function() {
grunt.util.spawn({
cmd : 'git',
args: ['add', '.'],
});
});
grunt.registerTask('git-commit', function(message) {
grunt.util.spawn({
cmd : 'git',
args: ['commit', '-m', message],
});
});
grunt.registerTask('git-push', function(origin, branch) {
grunt.util.spawn({
cmd : 'git',
args: ['push', origin, branch],
});
});运行其中的每一个独立的工作都是有侧重点的,所以通过运行:
$ grunt git-add
$ grunt git-commit:"commit message"
$ grunt git-push:origin:"branch name"我可以成功地提交和推送我的更改。那么,当将这三个任务组合成自己的任务时,为什么只运行第一个任务(git-add)?
var target = grunt.option('target');
grunt.registerTask('push-feature', [
'git-add',
'git-commit:' + target,
'git-push:origin:feature/' + target
]);假设我的分支名为12345,我应该能够运行$ grunt push-feature --target=12345,运行所有这3个任务,但只运行第一个git任务。如果删除git-add任务,则下一个任务(git-commit)是唯一执行的任务。
我错过了什么,才能让这三个任务按顺序运行?
发布于 2016-06-02 14:22:25
这可能是异步故障造成的。
在声明任务时,尝试将任务标记为异步,并使用回调选项进行派生。下面是第一个任务的示例:
grunt.registerTask('git-add', function () {
var done = this.async(); // Set the task as async.
grunt.util.spawn({
cmd: 'git',
args: ['add', '.'] // See comment below about this line
}, done); // Add done as the second argument here.
});还请注意,您有一个额外的逗号,可能会干扰操作:
args: ['add', '.'], // <- this comma should be dropped.https://stackoverflow.com/questions/37593273
复制相似问题