standard-version是一个帮助项目自动生成ChangeLog、升版本、打tag的工具。它基于semver和Conventional Commits规范。
当执行server-version
命令后,它会自动完成以下操作:
- 取得当前版本(比如package.json里面的version字段),升版本:
1.0.0 => 1.1.0
或者1.0.0 => 2.0.0
等(如何升级可以由参数控制) - 基于commits生成ChangeLog文件
- 提交一个commit,包含ChangeLog和版本变更的文件
- 打tag
以上功能都是可配置跳过的,对应:bump、changelog、commit、tag。比如在配置文件中按照如下配置,就可以跳过打tag操作:
{
skip: {
tag: true
}
}
和大部分工具的配置方式相同,为standard-version
添加配置有两种方式:
- Placing a standard-version stanza in your package.json (assuming your project is JavaScript).
- Creating a .versionrc, .versionrc.json or .versionrc.js.
目前使用的配置文件如下,其它配置参考官方文档:https://www.npmjs.com/package/standard-version
module.exports = {
skip: {
tag: true,
},
//types为Conventional Commits标准中定义,目前支持
//https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional
types: [
{ type: "feat", section: "新特性" },
{ type: "fix", section: "Bug修复" },
{ type: "docs", section: "文档" },
{ type: "chore", section: "配置项", hidden: true },
{ type: "style", section: "格式", hidden: true },
{ type: "refactor", section: "重构", hidden: true },
{ type: "perf", section: "性能", hidden: true },
{ type: "test", section: "测试", hidden: true },
{ type: "build", section: "构建", hidden: true },
{ type: "ci", section: "CI", hidden: true },
{ type: "revert", section: "回滚", hidden: true },
],
//hash链接
commitUrlFormat: "http://gitlab.cmss.com/BI/{{repository}}/commit/{{hash}}",
//issue链接
issueUrlFormat: "http://jira.cmss.com/browse/{{id}}",
//server-version自动commit的模板
releaseCommitMessageFormat:
"build: v{{currentTag}}版本发布 \n\nCode Source From: Self Code \nDescription: \nJira: # \n市场项目编号(名称):",
//需要server-version更新版本号的文件
bumpFiles: [
{
filename: "MY_VERSION_TRACKER.txt",
// The `plain-text` updater assumes the file contents represents the version.
type: "plain-text",
},
{
filename: "package.json",
// The `json` updater assumes the version is available under a `version` key in the provided JSON document.
type: "json",
},
],
};
package.json
"scripts": {
"release": "standard-version"
},
发布命令:
yarn release --release-as major
yarn release --release-as minor
yarn release