簡體   English   中英

Grunt Shell輸出到其他任務

[英]Grunt Shell output to other task

我正在使用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();
              }
            }
        }
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM