standard-version
是一个自动对项目更新版本号、生成日志、版本标记的工具。
笔者以standard-version@^9.5.0为例进行调试。
1.使用步骤
安装并直接执行
standard-version
。
上述命令默认会执行 4
个阶段:
bump
自动升级版本号(fix
升级patch
,feat
升级minor
)changelog
根据Conventional Commits Specification
生成新版本的日志文件commit
提交本地更改tag
生成版本标记
2.参数详解
除了上述的自动版本升级,也可以使用如下指令:
shell
# 首次发布版本
standard-version --first-release
shell
# 手动指定发布版本
standard-version --release-as <major|minor|patch>
更多参数可以使用 standard-version -h
查看:
3.配置文件
我们可以在项目根目录下定义一个 .versionrc.js
配置文件,其中可以配置上一节图片中列出的 Preset Configuration
:
js
// .versionrc.js
module.exports = {
types: [
{ type: 'feat', section: '✨ Features | 新功能' },
{ type: 'fix', section: '🐛 Bug Fixes | Bug 修复' },
{ type: 'init', section: '🎉 Init | 初始化' },
{ 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: '⏪ Revert | 回退', hidden: true },
{ type: 'build', section: '📦 Build System | 打包构建' },
{ type: 'chore', section: '🚀 Chore | 构建/工程依赖/工具' },
{ type: 'ci', section: '👷 Continuous Integration | CI 配置' }
],
// 默认值: "chore(release): {{currentTag}}"
releaseCommitMessageFormat: "{{currentTag}}",
// 跳过某步骤 可设置 bump changelog commit tag
skip: {
// changelog: true
}
}
后续执行 standard-version
相关命令时,会自动读取该文件。