Husky 개요

설치 방법

설정 방법과 테스트

프로젝트 루트 디렉터리에서 아래의 명령어 입력

- npm init
    - npm init 후 node_modules 생기므로 .gitignore 추가(뭘 추가 할지는 구글링)
- npm install husky --save-dev
- npx husky install
- npx husky add .husky/commit-msg 'sh commit-msg'
- code .husky/commit-msg

image.png

#!/bin/sh
commit_message=$(head -n 1 "$1")

if ! echo "$commit_message" | grep -Eq '^(Feat|Fix|Docs|Style|Refactor|Test|Chore|Design|Comment|Rename|Remove|!BREAKING CHANGE|!HOTFIX) : .+$'; then
    echo "Error: Commit message does not follow the convention!"
    exit 1
fi
  "scripts": {
  
  } // 이 안에
 
    "prepare": "husky" //이걸 추가

image.png

커밋 컨벤션(”Type : “)을 지키지 않고 작성시 Error 발생

image.png