简体   繁体   English

Grunt Shell输出到其他任务

[英]Grunt Shell output to other task

I am using grunt-shell and was wondering if I could take my config for shell and add to another task I have? 我正在使用grunt-shell并且想知道我是否可以将我的配置用于shell并添加到我的另一个任务中? Here is what I have: 这是我有的:

shell: {
  gitlog: {
    command: 'git log -1 --pretty=format:%h',
      options: {
        stdout: true
      }
  }
}

And then for my task: 然后我的任务:

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()
    }));
});

Thank you for any help with this in trying to figure out what I need to do so my git sha-1 will be part of my metaRevision. 感谢您在尝试弄清楚我需要做什么的任何帮助,所以我的git sha-1将成为我的metaRevision的一部分。

Your question is a bit hard to understand :-) 你的问题有点难以理解:-)

Do you mean you want to use the result of the execution of your shell command in your other task? 您是否想要在其他任务中使用shell命令的执行结果?

If so, in the case you describe, I would go with using the callback from the command execution, and save the file there, without the additional second task (see https://github.com/sindresorhus/grunt-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