husky+commitlint配置步驟
阿新 • • 發佈:2021-11-13
husky v7+及commitlint v13+配置方法都有很大改變, 原有的配置方法已經不再使用
安裝git-hook工具
yarn add husky -D
在當前目錄下生成.husky資料夾,並刪除裡面的.gitignore忽略檔案,否則無法將.husky下面的檔案提交到git倉庫
yarn husky install
在.husky資料夾下建立commit-msg檔案
npx husky add .husky/commit-msg
在.husky/commit-msg檔案中寫入
#!/bin/sh . "$(dirname "$0")/_/husky.sh" # 提交記錄檢查 yarn commitlint--edit $1 # 格式化檢查 yarn format:check # eslint檢查 yarn lint:check
將.husky/commit-msg新增到程式碼倉庫
git add .husky/commit-msg
安裝git提交資訊規範配置檔案
yarn add -D @commitlint/{cli,config-conventional}
安裝changelog自動化生成工具
yarn add -D conventional-changelog-cli
package.json的script中新增
{ "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "changelog:init": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0", "changelog:help": "conventional-changelog --help", },
- 引數
-p
指定提交資訊的規範,有以下選擇:angular, atom, codemirror, ember, eslint, express, jquery, jscs or jshint
- 引數
-s
表示將新生成的CHANGELOG
輸出到-i
指定的檔案中 - 引數
-i
指定輸出CHANGELOG
內容的檔案 - 引數
-r
預設為1
0
將重新生成所有版本的變更資訊