[英]Proper way of using grunt-bump and grunt-ng-constant together
[英]Grunt bump and prompt for commit message
我是Grunt的新手,但是我試圖將grunt-bump與grunt-prompt結合使用,以便提示用戶輸入提交消息,然后將其添加到提交中。
我從這篇文章中基於我的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.
您需要對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.
}
筆記
首先,將您的bump
任務中的commitMessage
屬性值更改為以下內容:
'<%=grunt.config("gitmessage")%>'
prompt.
您當前在grunt模板中擁有的部分已被省略。 它應該是僅在prompt
任務中指定的config
屬性的值。
接下來,注冊一個新任務,我們將其myBump
。 即
grunt.registerTask('myBump', ['prompt:commit', 'bump']);
重要提示:您可以選擇另一種名稱為任務,而不是myBump
,但它不能被命名bump
,因為它會與現有的任務沖突。
此新注冊的任務通過執行以下操作來確保在bump
之前運行prompt:commit
任務:
Alias Tasks prompt
任務的commit
目標 (即prompt:commit
)。
然后為bump
任務添加別名。
運行任務
而不是運行的grunt bump
通過您的CLI,你需要運行; grunt myBump
。
通過CLI運行grunt myBump
將:
首先提示您輸入提交消息。 例如:
Running "prompt:commit" (prompt) task
? Commit Message
? Commit Message
我關於顛簸的消息
隨后運行的bump
任務。 例如::
Running "bump" task
>> Version bumped to 1.0.1 (in package.json)
>> Committed as
我關於凹凸的信息而>> Committed as
>> Tagged as "v1.0.1"
雖然解決方案A可以正常工作,但不能容納所有semver版本。 當前,每次運行grunt myBump
時,它只會增加PATCH
版本。
也許,您的意圖是啟用一種處理各種類型的semver顛簸的方法。 分為以下幾類:
當您進行不兼容的API更改時的主要版本,
MINOR版本,當您以向后兼容的方式添加功能時,
進行向后兼容的錯誤修復時的PATCH版本。
以下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
版本,請運行:
grunt bump-patch
要MINOR
版本,請運行:
grunt bump-minor
要更改MAJOR
版本,請運行:
grunt bump-major
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.