使用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命令中运行条件吗?
答案 0 :(得分:2)
您可以将参数发送到registerTask,就像这样
grunt.registerTask('test', function (bumptype) {
if(bumptype)
grunt.task.run('bumpup:' + bumptype);
});
这样你可以做到
$ grunt test minor
$ grunt test patch
答案 1 :(得分:1)
可以将grunt任务添加到grunt-prompt的'then'属性中:
then: function(results) {
// console.log(results['bump.increment']);
// run the correct bump version based on answer
if (results['bump.increment'] === 'patch') {
grunt.task.run('bump:patch');
} else {
grunt.task.run('bump:minor');
}
}