使用插件standard-version
和conventional-changelog
生成 changelog 文档的方法。
具体步骤如下:
1. 安装插件
在 package.json 文件中补充添加如下内容:
"scripts": {
"commit": "git-cz",
"release": "standard-version",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"eslint": "eslint --fix --format codeframe 'src/**.js'",
"log": "conventional-changelog"
},
"devDependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-angular": "^8.3.4",
"@commitlint/config-conventional": "^8.2.0",
"cz-conventional-changelog": "^3.1.0",
"husky": "^3.1.0",
"lint-staged": "^10.1.1",
"standard-version": "^7.0.1"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"lint-staged": {
"src/**.js": [
"eslint --fix"
]
}
然后 npm run install
安装插件。
链接:
2. 相关指令说明:
- 使用 conventional-changelog 标准提交
npm run commit
- 自动生成版本号(版本号默认加 0.0.1)并修改 changelog 文件
npm run release
- 生成并更新 changelog 文档
npm run changelog
- eslint 代码检查
npm run eslint
- log 在终端打印 changelog 内容
npm run log
如果想知道更多的指令,可以在终端输入: standard-version --help
和conventional-changelog --help
。
目前使用最广的是基于 Angular 约定提交,用于说明 commit 的类别,只允许使用下面 7 个标识:
feat:新功能(feature)
fix:修补 bug
docs:文档(documentation)
style: 格式(不影响代码运行的变动)
refactor:重构(即不是新增功能,也不是修改 bug 的代码变动)
test:增加测试
chore:构建过程或辅助工具的变动
如果 type 为 feat 和 fix,则该 commit 将肯定出现在 Change log 之中。其他情况(docs、chore、style、refactor、test)可以自己定义。
生成changelog文档如图: