1. 程式人生 > 其它 >husky+commitlint配置步驟

husky+commitlint配置步驟

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將重新生成所有版本的變更資訊