Grunt Shell输出到其他任务
我正在使用grunt-shell,并想知道我是否可以将我的configuration文件join到我的另一个任务中? 这是我有什么:
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命令的结果吗?
如果是这样,在你描述的情况下,我将使用命令执行的callback,并保存文件,而不需要额外的第二个任务(请参阅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(); } } } } });