Javascript Grunt Shell输出到其他任务
我正在使用grunt shell,我想知道是否可以将我的shell配置添加到我的另一个任务中?以下是我所拥有的:Javascript Grunt Shell输出到其他任务,javascript,node.js,gruntjs,Javascript,Node.js,Gruntjs,我正在使用grunt shell,我想知道是否可以将我的shell配置添加到我的另一个任务中?以下是我所拥有的: shell: { gitlog: { command: 'git log -1 --pretty=format:%h', options: { stdout: true } } } 对于我的任务: grunt.registerTask('build-version', 'Set the information about th
shell: {
gitlog: {
command: 'git log -1 --pretty=format:%h',
options: {
stdout: true
}
}
}
对于我的任务:
grunt.registerTask('build-version', 'Set the information about the version', function() {
grunt.file.write('version.json', JSON.stringify({
version: pkg['version'],
metaRevision: shell.gitlog,
date: grunt.template.today()
}));
});
感谢您在此方面提供的帮助,帮助我了解需要做什么,以便我的git sha-1将成为元修订版的一部分。您的问题有点难以理解:-) 您的意思是希望在其他任务中使用shell命令的执行结果吗 如果是这样,在您描述的情况下,我将继续使用命令执行中的回调,并将文件保存在那里,而不需要额外的第二个任务(请参阅):
grunt.initConfig({
shell: {
gitlog: {
command: 'git log -1 --pretty=format:%h',
options: {
callback: function log(err, stdout, stderr, cb) {
grunt.file.write('version.json', JSON.stringify({
version: pkg['version'],
metaRevision: stdout,
date: grunt.template.today()
}));
cb();
}
}
}
}
});