【发布时间】:2015-06-12 12:49:01
【问题描述】:
使用 Grunt,我正在运行一个任务,它会在我的 package.json 文件中增加我的版本号。但我想提示用户他/她想要更新哪些版本。如果它是正常更新,则运行小增量 (x.+1.x),当它是补丁或修补程序时,它应该运行 (x.x.+1)。为此,我有 2 个繁重的任务:
/*
* Bump the version number to a new version
*/
bump: {
options: {
files: ['package.json'],
updateConfigs: [],
commit: true,
commitMessage: 'Release v<%= pkg.version %>',
commitFiles: ['package.json'],
createTag: true,
tagName: 'v<%= pkg.version %>',
tagMessage: 'Version <%= pkg.version %>',
push: true,
pushTo: '<%= aws.gitUrl %>',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: false,
prereleaseName: false,
regExp: false
}
},
/*
* Prompt to see which bump should happen
*/
prompt: {
bumptype: {
options: {
questions: [
{
config: 'bump.increment',
type: 'list',
message: 'Bump version from ' + '<%= pkg.version %> to:',
choices: [
{
value: 'patch',
name: 'Patch: Backwards-compatible bug fixes.'
},
{
value: 'minor',
name: 'Minor: Add functionality in a backwards-compatible manner.'
},
],
}
],
then: function(results) {
console.log(results['bump.increment']); // this outputs 'minor' and 'patch' to the console
}
}, // options
} // bumptype
}, // prompt
在此之后,我想在这样的自定义任务中运行它:
grunt.registerTask('test', '', function () {
grunt.task.run('prompt:bumptype');
// Maybe a conditional which calls the results of prompt here?
// grunt.task.run('bump'); // this is the bump call which should be infuenced by either 'patch' or 'minor'
});
但是现在当我运行$ grunt test 命令时,我确实会收到提示,然后无论您选择哪个选项,它都会运行小凹凸任务。
grunt bump 选项通常采用以下参数:
$ grunt bump:minor
$ grunt bump:patch
那么您应该在提示选项中还是在 registerTask 命令中运行条件?
【问题讨论】:
标签: gruntjs grunt-prompt