本文讲解了如何利用工具 commitizen/cz-cli + commitizen/cz-conventional-changelog + conventional-changelog/standard-version,规范提交信息和版本发布。
协做开发下不一样开发人员的 commit 书写习惯不一样,查看 commit 记录时感受就比较乱且不尽详细。我本身也是,没有一套合适的 commit 规范约束,每次都只是大概写个主要概述就提交,当须要返回查看时就看不出太多信息了。同时 CHANGELOG 也是记录的不尽详细,以前的手动书写不能让咱们查看项目的每一个发行版之间发生的变化。也因此上网查找了下解决方案,感受甚好,有必要总结一下。node
约定式提交规范是基于Angular提交准则造成,提交说明的结构以下:git
<类型>[可选的做用域]: <描述> [可选的正文] [可选的脚注]
其中,<类型>
是为了向类库使用者代表其意图,其可选值为:github
[可选的做用域]
: 是为了描述 这次 commit 影响的范围,好比: route, component, utils, build, api, website, docsweb
<描述>
: 这次提交的简短描述npm
[可选的正文]
: 这次提交的详细描述,描述为何修改,作了什么样的修改,以及开发的思路等等,输入 \n
换行json
[可选的页脚]
: 主要写下面2种api
npm install -g commitizen cz-conventional-changelog echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
全局模式下, 须要 ~/.czrc 配置文件, 为 commitizen 指定 Adapteride
执行工具
git cz
npm install -D commitizen cz-conventional-changelog
package.json中配置:性能
"script":{"commit":"git-cz"}, "config":{"commitizen":{"path":"node_modules/cz-conventional-changelog"}}
执行
npm run commit
一样能够有 2 种安装形式,这里只介绍项目级安装,接下来的介绍也都以此为例。
npm i -S standard-version
package.json 配置:
"scirpt":{"release":"standard-version"}
执行
npm run release
若全局安装,可直接使用 standard-version 命令,其做用等同于npm run release,下面再也不赘述
选项:
--release-as, -r Specify the release type manually (like npm version <major|minor|patch|1.1.0>) [字符串] // major: 1.0.0 -> 2.0.0, minor: 1.0.0 -> 1.1.0, patch : 1.0.0 -> 1.0.1 --prerelease, -p make a pre-release with optional option value to specify a tag id [字符串] --infile, -i Read the CHANGELOG from this file [默认值: "CHANGELOG.md"] --message, -m Commit message, replaces %s with new version [字符串] [默认值: "chore(release): %s"] --first-release, -f Is this the first release? [布尔] [默认值: false] --sign, -s Should the git commit and tag be signed? [布尔] [默认值: false] --no-verify, -n Bypass pre-commit or commit-msg git hooks during the commit phase [布尔] [默认值: false] --commit-all, -a Commit all staged changes, not just files affected by standard-version [布尔] [默认值: false] --silent Don't print logs and errors [布尔] [默认值: false] --tag-prefix, -t Set a custom prefix for the git tag to be created [字符串] [默认值: "v"] --scripts Provide scripts to execute for lifecycle events (prebump, precommit, [默认值: {}] --skip Map of steps in the release process that should be skipped [默认值: {}] --dry-run See the commands that running standard-version would run [布尔] [默认值: false]
经常使用发布命令
// 初次发布版本 npm run release --first-release // 添加版本信息和指定发布版本等级 npm run release -m "Commit message" -r minor // 确认发布,npm publish 发布到 npm git push --follow-tags origin master && npm publish