问题
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