内容简介:约定式提交:每次使用约定式提交不需要任何的配置,只需要严格遵守其规范就可以了。 为了保证每次提交的约定式提交使用交互式提交工具(例如:
约定式提交:每次使用 git commit 的时候都需要写 commit message ,如果message style是按照固定的模版格式书写,对于后期的维护和编写 changelog 都有巨大的好处。 而且现在的很多自动生成 changelog 的工具,都是建立在 约定式提交 的基础之上。
约定式提交校验配置
约定式提交不需要任何的配置,只需要严格遵守其规范就可以了。 为了保证每次提交的 commit message 都是遵守 conventional commit spec 所以添加了校验配置.
约定式提交工具
约定式提交使用交互式提交工具(例如: commitizen ),使用 工具 能够保证 约定式提交 个格式是满足规范的。
-
推荐使用vs code 插件
commitizen -
命令行方式的
commitizen配置(vscode commitizen和命令行方式任选其一即可)npm install --save-dev commitizen 复制代码
// package.json配置 { scripts: { "commit": "git-cz" } } 复制代码# 使用 npm run commit # 进入交互式, 如果commit message在console中换行,请使用'开始 复制代码
-
commitizen的适配器cz-conventional-changelogcommitizen只是一个提交的工具,只有添加了约定格式的适配器才能按照固定格式进行交互式提交, 否则就和普通的git commit一样了。(还有其他适配器可选,请参考官方文档) 不同的适配器,提供的约定标准有差异。# 建议安装npx这个神器 npm i npx -g npx commitizen init cz-conventional-changelog --save-dev --save-exact 复制代码
commitizen工具会在package.json中自动添加配置:{ "config": { "commitizen": { // "path": "cz-conventional-changelog" // 全局安装模式 "path": "./node_modules/cz-conventional-changelog" } } } 复制代码
约定式提交格式校验
为了防止出现不满足格式要求的 commit message 出现,还是需要添加上必要的格式校验.
-
commitlint校验约定式提交格式commitlint是在commit message之前进行校验格式,格式不对不进行提交。# 安装 npm install --save-dev @commitlint/config-conventional @commitlint/cli 复制代码
# 添加配置文件commitlint.config.js,工程根目录 echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js 复制代码 -
husky配置git hooks有了
git hooks我们可以做很多提交之前的验证。# 安装 npm i husky --save-dev 复制代码
// package.json 配置 { "husky": { "hooks": { "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", // 配合commitlint使用 // "pre-commit": "lint-staged" // 配置lint-staged } } } 复制代码 -
lint-staged配置(可选)list-staged主要配合linter用来格式化代码(统一的代码风格),这部是 可选 的。lint-staged是用来让格式化工具只lint需要提交的文件,其它文件忽略,这样能够提高效率。npm i lint-staged --save-dev 复制代码
// package.json 配置 { "lint-staged": { "src/**/*.{js,ts,css,vue,tsx,jsx}": [ "vue-cli-service lint", // npm run lint "git add" ] } } 复制代码
自动生成 changelog
自动生成 changelog 是建立在约定式提交的基础上。
自动生成 changelog 有两种方式:
-
conventional-changelog-cli生成changelog -
standard-version生成changelogstandard-version帮你做了自动打tag,自动生成changelog等过程.
conventional-changelog-cli 配置
在约定式提交的基础上来自动生成 changelog ,工具类库开发,推荐直接使用 standard-version ,高度集成了所有东西。
npm install conventional-changelog-cli --save-dev 复制代码
# 基本使用,其它参数参考官方网站 conventional-changelog -p angular -i CHANGELOG.md -s -r 0 复制代码
// package.json配置
{
scripts: {
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
}
}
复制代码
# 使用 npm run changelog 复制代码
standard-version 配置
# 安装 npm install standard-version --save-dev 复制代码
// package.json 配置
{
"scripts": {
"release": "standard-version"
},
// standard-version 好多配置看官方文档(可选)
"standard-version": {
// 可以配置不需要的环节
"skip": {
// bump, changelog, commit, tag
"tag": true
}
}
}
复制代码
# 项目根目录下使用,自行安装npx 模块 # npm i npx -g npx standard-version --release-as major npx standard-version --release-as minor npx standard-version --release-as patch npx standard-version --prerelease alpha npx standard-version --prerelease beta npx standard-version --prerelease rc npm run release -- -r minor npm run release -- -p beta 复制代码
package.json 中的scripts命令组织
{
scripts: {
"commit": "git-cz",
"release": "standard-version",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
"release:major": "standard-version -r major -n,
"release:minor": "standard-version -r minor -n,
"release:patch": "standard-version -r patch -n",
"prerelease:alpha": "standard-version -p alpha -n,
"prerelease:beta": "standard-version -p beta -n,
"prerelease:rc": "standard-version -p rc -n"
}
}
复制代码
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 悟懂 MapReduce,不纠结
- 前端小纠结--WebSocket实战
- 前端小纠结--VS Code调试配置分享
- 为什么你还在纠结于语法糖?
- 零基础的你还在纠结怎么学习Python编程吗?
- 前端小纠结--集成gitflow和standard-version使用
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Beginning ARKit for iPhone and iPad
Wallace Wang / Apress / 2018-11-5 / USD 39.99
Explore how to use ARKit to create iOS apps and learn the basics of augmented reality while diving into ARKit specific topics. This book reveals how augmented reality allows you to view the screen on ......一起来看看 《Beginning ARKit for iPhone and iPad》 这本书的介绍吧!