前言
上一篇自动生成CHANGELOG,想了一下,还是把release-it完善上去吧。
12、release-it 自动管理版本号
安装release-it相关的插件
// package.json
"release-it": "^15.11.0",
"@release-it/conventional-changelog": "^5.1.1",
根目录添加 .release-it.json 配置文件,可以去release-it明细配置
// .release-it.json
{
"plugins": {
"@release-it/conventional-changelog": {
"preset": {
"name": "conventionalcommits",
"types": [
{ "type": "feat", "section": "✨ Features | 新功能" },
{ "type": "fix", "section": "🐛 Bug Fixes | Bug 修复" },
{ "type": "chore", "section": "🎫 Chores | 其他更新" },
{ "type": "docs", "section": "📝 Documentation | 文档" },
{ "type": "style", "section": "💄 Styles | 风格" },
{ "type": "refactor", "section": "♻ Code Refactoring | 代码重构" },
{ "type": "perf", "section": "⚡ Performance Improvements | 性能优化" },
{ "type": "test", "section": "✅ Tests | 测试" },
{ "type": "revert", "section": "⏪ Reverts | 回退" },
{ "type": "build", "section": "👷 Build System | 构建" },
{ "type": "ci", "section": "🔧 Continuous Integration | CI 配置" },
{ "type": "config", "section": "🔨 CONFIG | 配置" }
]
},
"infile": "CHANGELOG.md",
"ignoreRecommendedBump": true,
"strictSemVer": true
}
},
"git": {
"commitMessage": "chore: release v${version}"
}
}
本文并没有发布到 npm ,需要的可自己配置
package.json 的 scripts 中添加脚本
// package.json
"release": "release-it"
上面命令默认更新次版本号,如果想更新主版本号可以参考下面的脚本
# 更新主版本号
pnpm release major
# 更新次版本号
pnpm release minor
# 更新修订号
pnpm release patch
pnpm commit之后,执行对应的脚本命令更新版本号。
最终效果如上图。
结语
这样就可以妥善更新项目的版本号和changelog文档了。未完待续…