standard-version是一個(gè)幫助項(xiàng)目自動(dòng)生成ChangeLog锌俱、升版本晤郑、打tag的工具。它基于semver和Conventional Commits規(guī)范贸宏。
當(dāng)執(zhí)行server-version
命令后造寝,它會(huì)自動(dòng)完成以下操作:
- 取得當(dāng)前版本(比如package.json里面的version字段),升版本:
1.0.0 => 1.1.0
或者1.0.0 => 2.0.0
等(如何升級(jí)可以由參數(shù)控制) - 基于commits生成ChangeLog文件
- 提交一個(gè)commit吭练,包含ChangeLog和版本變更的文件
- 打tag
以上功能都是可配置跳過(guò)的诫龙,對(duì)應(yīng):bump、changelog线脚、commit赐稽、tag。比如在配置文件中按照如下配置浑侥,就可以跳過(guò)打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標(biāo)準(zhǔn)中定義寓落,目前支持
//https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional
types: [
{ type: "feat", section: "新特性" },
{ type: "fix", section: "Bug修復(fù)" },
{ type: "docs", section: "文檔" },
{ type: "chore", section: "配置項(xiàng)", hidden: true },
{ type: "style", section: "格式", hidden: true },
{ type: "refactor", section: "重構(gòu)", hidden: true },
{ type: "perf", section: "性能", hidden: true },
{ type: "test", section: "測(cè)試", hidden: true },
{ type: "build", section: "構(gòu)建", 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自動(dòng)commit的模板
releaseCommitMessageFormat:
"build: v{{currentTag}}版本發(fā)布 \n\nCode Source From: Self Code \nDescription: \nJira: # \n市場(chǎng)項(xiàng)目編號(hào)(名稱(chēng)):",
//需要server-version更新版本號(hào)的文件
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"
},
發(fā)布命令:
yarn release --release-as major
yarn release --release-as minor
yarn release