规范化的提交信息除了能很好描述项目的修改,还有一个很好的作用就是能根据提交记录来生成CHANGELOG.MD和自动生成版本号等功能。
一个用于生成CHANGELOG.md
和进行SemVer(语义化版本号)
发版的命令行工具
主要功能:
package.json
或者自定义一个文件git tag
CHANGELOG.md
CHANGELOG.md
和package.json
先简单了解下什么是语义化的版本控制,其是由GitHub
发起的一份用于规范版本号递增的规则,
主版本号.次版本号.修订号,版本号递增规则如下:
先行版本号可以加到“主版本号.次版本号.修订号”的后面,作为延伸。
当即将发布大版本改动前,但是又不能保证这个版本的功能 100% 正常,这个时候可以发布先行版本:
比如:1.0.0-alpha.0,1.0.0-alpha.1,1.0.0-rc.0,1.0.0-rc.1等。
standard-verstion
生成的CHANGELOG
只会包含feat
,fix
,BREACK-CHANGE
类型的提交记录
npm i --save-dev standard-version
添加npm script,完整的命令如下。
{
scripts: {
"release": "standard-version",
"release:alpha": "standard-version --prerelease alpha",
"release:rc": "standard-version --prerelease rc",
"release:major": "npm run release -- --release-as major",
"release:minor": "npm run release -- --release-as minor",
"release:patch": "npm run release -- --release-as patch"
}
}
执行过后会修改 package.version
并修改CHANGELOG
文件。
commitizen + cz-conventional-changelog + commitlint +standard-version
{
"name": "blog",
"version": "1.0.0",
"description": "blog",
"main": "index.js",
"scripts": {
"start": "npm run dev",
"release": "standard-version",
"release:alpha": "standard-version --prerelease alpha",
"release:rc": "standard-version --prerelease rc",
"release:major": "npm run release -- --release-as major",
"release:minor": "npm run release -- --release-as minor",
"release:patch": "npm run release -- --release-as patch"
},
"devDependencies": {
"@commitlint/cli": "^17.6.6",
"@commitlint/config-conventional": "^17.6.6",
"commitizen": "^4.2.2",
"cz-conventional-changelog": "^3.3.0",
"standard-version": "^9.1.0"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
}
}