2014-01-16 39 views
1

我正在使用grunt-shell並想知道我是否可以將我的配置用於shell並添加到其他任務中?以下是我有:Grunt 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() 
    })); 
}); 

感謝您的任何幫助,這在試圖找出我需要做的,所以我混帳SHA-1將成爲我的metaRevision的一部分。

回答

3

你的問題是有點難以理解:-)

你的意思是你想在你的其他任務使用你的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(); 
       } 
      } 
     } 
    } 
});