Grunt Shell output to other task

谁都会走 提交于 2019-12-23 03:33:14

问题


I am using grunt-shell and was wondering if I could take my config for shell and add to another task I have? 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.


回答1:


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?

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):

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


来源:https://stackoverflow.com/questions/21167750/grunt-shell-output-to-other-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!