我正在使用 grunt-shell 并且想知道我是否可以将我的 shell 配置添加到我的另一个任务中?这是我所拥有的:
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 将成为我的 metaRevision 的一部分。
最佳答案
你的问题有点难以理解:-)
你的意思是你想在你的其他任务中使用你的shell命令的执行结果吗?
如果是这样,在您描述的情况下,我会继续使用命令执行的回调,并将文件保存在那里,而无需额外的第二个任务(参见 https://github.com/sindresorhus/grunt-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();
}
}
}
}
});
关于javascript - Grunt Shell 输出到其他任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21167750/