本文講解了如何利用工具 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