我正在使用Grunt和Grunt-shell来构建/部署我的Javascript项目。Grunt-shell保存命令输出作为变量
我想获得最新的git-commit号码并将它作为一个变量存储,但不能想象如何。 我试过了回调并设置了一个全局变量。这个变量是在函数中使用,但不包括从其它块中似乎
grunt.initConfig({
...
shell: {
getGitCommitNo: {
command: 'git rev-parse --short HEAD',
options: {
callback: function (err, stdout, stderr, cb) {
global['gitCommitNo'] = stdout;
grunt.log.ok(global.gitCommitNo);
cb();
}
}
},
philTest: {
command: 'echo Git Commit No: ' + global.gitCommitNo
},
...
}
输出:
>> Starting deployment process for version 1.1 in dev environment
Running "shell:getGitCommitNo" (shell) task
bfc82a9
>> bfc82a9
Running "shell:printTest" (shell) task
Git Commit No: undefined
Done, without errors.
任何人都可以建议我怎么可能挽救一个命令行变量的输出,可用请?
不知道你可以用'shell'插件做到这一点,但你可以写一个简单的自定义模块,如果有必要去做。 – jakerella 2015-02-10 18:38:48