我是Grunt新手,但我尝试将咕噜声与咕噜声结合起来,以便提示用户输入提交消息,然后将其添加到提交中。
我在Gruntfile.js中使用了来自这个职位的代码,但是提示元素不起作用。知道我做错什么了吗?
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-prompt');
grunt.initConfig({
prompt: {
commit: {
options: {
questions: [{
config: 'gitmessage',
type: 'input',
message: 'Commit Message'
}]
}
}
},
bump: {
options: {
files: ['package.json'],
updateConfigs: [],
commit: true,
commitMessage: '<%=grunt.config("prompt.gitmessage")%>',
commitFiles: ['package.json'],
createTag: true,
tagName: 'v%VERSION%',
tagMessage: 'Version %VERSION%',
push: true,
pushTo: 'origin',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: false,
prereleaseName: false,
metadata: '',
regExp: false
}
},
});
};这是终端输出:
$ grunt bump
Running "bump" task
>> Version bumped to 7.0.39 (in package.json)
>> Committed as " v7.0.39"
>> Tagged as "v7.0.39"
>> Pushed to origin
Done.发布于 2018-04-05 14:34:51
解决方案A:
您需要对您的Gruntfile.js进行一些更改,如下面的示例所示(参见注释1和2)
Gruntfile.js
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-prompt');
grunt.initConfig({
prompt: {
commit: {
options: {
questions: [{
config: 'gitmessage',
type: 'input',
message: 'Commit Message'
}]
}
}
},
bump: {
options: {
files: ['package.json'],
updateConfigs: [],
commit: true,
commitMessage: '<%=grunt.config("gitmessage")%>',// 1) Change this.
commitFiles: ['package.json'],
createTag: true,
tagName: 'v%VERSION%',
tagMessage: 'Version %VERSION%',
push: true,
pushTo: 'origin',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: false,
prereleaseName: false,
metadata: '',
regExp: false
}
}
});
grunt.registerTask('myBump', ['prompt:commit', 'bump']);// 2) Register new task.
}Notes
commitMessage属性在bump任务中的值更改为:
'<%=grunt.config("gitmessage")%>‘
您当前在prompt.中的光栅模板部分被省略了。它应该是仅在config任务中指定的prompt属性的值。myBump。也就是说。
grunt.registerTask('myBump','prompt:commit','bump');
重要:您可以为任务选择另一个名称,而不是myBump__,但是它不能被命名为bump,因为它将与现有任务发生冲突。
通过执行以下操作,这个新注册的任务确保prompt:commit任务在bump之前运行:- [Alias Tasks](https://gruntjs.com/creating-tasks#alias-tasks) the `commit` [Target](https://gruntjs.com/configuring-tasks#task-configuration-and-targets) of your `prompt` task (i.e. `prompt:commit`).
- Then aliases the `bump` task.
运行任务
而不是通过CLI运行grunt bump,而是需要运行;grunt myBump。
通过您的CLI运行grunt myBump将:
Running "prompt:commit" (prompt) task
? Commit Message,,我的关于颠簸的消息bump任务。例如:
Running "bump" task
>> Version bumped to 1.0.1 (in package.json)
>> Committed as,,我的关于颠簸的消息
>> Tagged as "v1.0.1"解决方案B:
虽然解决方案A工作得很好,但它不适合所有的符号学版本。目前,每次运行PATCH时,它只会弹出grunt myBump版本。
也许,您的意图是启用一种处理各种类型的流量凸起的方法。其分类如下:
下面的Gruntfile.js显示了处理上面列出的任何一个版本类型的配置。
Gruntfile.js
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-prompt');
grunt.initConfig({
prompt: {
patch: {
options: {
questions: [{
config: 'gitmessage',
type: 'input',
message: 'Commit message for PATCH version bump:'
}]
}
},
minor: {
options: {
questions: [{
config: 'gitmessage',
type: 'input',
message: 'Commit message for MINOR version bump:'
}]
}
},
major: {
options: {
questions: [{
config: 'gitmessage',
type: 'input',
message: 'Commit message for MAJOR version bump:'
}]
}
}
},
bump: {
options: {
files: ['package.json'],
updateConfigs: [],
commit: true,
commitMessage: '<%=grunt.config("gitmessage")%>',
commitFiles: ['package.json'],
createTag: true,
tagName: 'v%VERSION%',
tagMessage: 'Version %VERSION%',
push: true,
pushTo: 'origin',
gitDescribeOptions: '--tags --always --abbrev=1 --dirty=-d',
globalReplace: false,
prereleaseName: false,
metadata: '',
regExp: false
}
}
});
grunt.registerTask('bump-patch', ['prompt:patch', 'bump:patch']);
grunt.registerTask('bump-minor', ['prompt:minor', 'bump:minor']);
grunt.registerTask('bump-major', ['prompt:major', 'bump:major']);
}运行
使用上面所示的配置,您可以酌情通过CLI运行以下命令:
PATCH版本,请运行:
凹凸补片MINOR版本,请运行:
凹凸小调MAJOR版本,请运行:
咕噜颠簸https://stackoverflow.com/questions/49601623
复制相似问题