Skip to content
文章目录

standard-version使用说明

配置文件

.versionrc.js

js
module.exports = {
  header: '# xxx系统 \n## 更新历史',
  commitUrlFormat: 'http://git项目地址/tree/{{hash}}',
  issueUrlFormat: 'http://gitissu地址/{{id}}',
  compareUrlFormat: 'http://git项目地址/-/compare/{{previousTag}}...{{currentTag}}',
  types: [
    { type: 'feat', section: '✨ Features | 新功能' },
    { type: 'fix', section: '🐛 Bug Fixes | Bug 修复' },
    { type: 'docs', section: '📝 Documentation | 文档更新' },
    { type: 'refactor', section: '♻️ Code Refactoring | 代码重构' },
    { type: 'perf', section: '⚡ Performance Improvements | 性能优化' },
    { type: 'test', section: '✅ Tests | 添加/更新测试代码' },
    { type: 'revert', section: '⏪ Revert | 回退', hidden: true },
    { type: 'release', section: '🔖 Build System | 打包构建' },
    { type: 'chore', section: '🤖 Chore | 构建/工程依赖/工具' },
    { type: 'ci', section: '👷 Continuous Integration | CI 配置' },
  ],
}

配置说明

配置项说明补充
header文档的头部内容支持 markdown 语法
commitUrlFormat提交内容可访问地址默认:///commit/
compareUrlFormat两个提交对比的可访问地址默认:///compare/...
issueUrlFormat提问内容地址默认:///issues/
userUrlFormat提交人可访问的地址默认:/
issuePrefixesArray or String,字符串或者字符串数组. 用于检索提问内容的标识如:#39;默认是:['#']
types用于配置输出的内容。type 对象包含:type 对应 commit 录入中的 type;section 展示的文字内容;hidden 是否隐藏例子:{"type": "feat", "section": "Features", "hidden": false}
preMajorBoolean, 用于控制是否显示 1.0.0 版本之前的 changelog。
  • host: 参数值来在package.json文件,自己添加一个 host 配置. 如:
json
{
  "name": "project-template",
  "private": true,
  "version": "3.0.4",
  "type": "module",
  "host": "https://gitcode.net"
}
  • repository: 参数值来在standard-versionpackage.jsonrepository.url 的解析
  • owner:参数值来在standard-versionpackage.jsonrepository.url 的解析
  • hash:参数值来在standard-versioncommit hash的解析
  • previousTag: 参数值来在standard-version对上一个标签的解析
  • currentTag: 参数值来在standard-version对当前标签的解析
  • user: 参数值来在standard-version@user的解析

当 git commit 消息中包含如下模式字符时会被特殊转换

  • #xxx: 会被转换为 [#xxx](issueUrlFormat) 的 markdown 内容
  • @user: 会被转换为 [@user](userUrlFormat)的 markdown 内容
  • 版本号: 被毁转换为[版本号](compareUrlFormat)的 markdown 内容

使用注意事项

如果项目的初始版本是: 0.0.00.x.x 这类,那么无论你是提交 feat 类型的 git commit 还是提交包含 BREAK CHANGE 类型的 git commit, standard-version 更新的都是次版本号, 也就是说你项目的版本号的变化是: 0.1.0, 0.2.0, 0.3.0, 0.4.0 ....

只有当你项目的版本号是1.0.0,1.1.0,2.0.0 ... y.x.x, y大于等于 1 时, standard-version 的更新规则才是: git commit 消息包含 BREAK CHANGE 内容时更新主版本号, 包含feat commit时,更新次版本号, 包含fix commit时, 更新修订号

关于语义化版本规范详见:《semver 语义化版本规范》

参考资料

自动产出 changelog-第二节:自动产出

Conventional Commits