我正在使用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