当前位置: 首页 > 工具软件 > changelog-ci > 使用案例 >

standard-version(发版与 Changelog 自动化)

凌钊
2023-12-01

我们就可以使用 standard-version 进行版本管理自动化,包括更新 CHANGELOG.md,以及使用 git tag。它也会自动修改 package.json 里的 version

在使用 standard-version 之前,需要遵循 Conventional Commit Specifications 来进行标准化的 commit message 编写。这是因为 standard-version 是基于 commit 类型来更新版本号的(feature 会更新 minor, bug fix 会更新 patch, BREAKING CHANGES 会更新 major)。

这里,我们可以借助 commitizen 来进行标准化的 commit message 编写,具体配置流程详见
commitizen 配置好后,我们可以开始配置 standard-version 了。

 1. 安装

npm install -D standard-version

2. 在 package.json 中编写响应的脚本:

"scripts": {
  "release": "standard-version"
}

为了合理的使用 standard-version,我们首先需要 git add . 文件,然后执行 npm run commit 提交,最后执行 npm run release

执行完以后就会在项目根目录自动生成 CHANGELOG.md 文件。

CHANGELOG.md 配置

默认情况下,standard-version 只会在 CHANGELOG.md 中记录 featfix 类型的提交。如果想记录其他类型的提交,需要如下步骤:

  • 在项目的根目录下创建一个名为 .versionrc 的文件,并粘贴复制一下内容:
{
  "types": [
    {"type": "chore", "section":"Others", "hidden": false},
    {"type": "revert", "section":"Reverts", "hidden": false},
    {"type": "feat", "section": "Features", "hidden": false},
    {"type": "fix", "section": "Bug Fixes", "hidden": false},
    {"type": "improvement", "section": "Feature Improvements", "hidden": false},
    {"type": "docs", "section":"Docs", "hidden": false},
    {"type": "style", "section":"Styling", "hidden": false},
    {"type": "refactor", "section":"Code Refactoring", "hidden": false},
    {"type": "perf", "section":"Performance Improvements", "hidden": false},
    {"type": "test", "section":"Tests", "hidden": false},
    {"type": "build", "section":"Build System", "hidden": false},
    {"type": "ci", "section":"CI", "hidden":false}
  ]
}
  • "type" commit 类型
  • "section" 不同的 commit 类型所在 CHANGELOG.md 中的区域
  • "hidden" 是否在 CHANGELOG.md 中显示


 

参考:使用 commitizen 和 standard-version 自动化 JavaScript 项目版本控制 - 简书

 类似资料: