Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 828 Bytes

husk-usage.md

File metadata and controls

46 lines (35 loc) · 828 Bytes

Husky usage

You can use husky hook when you want to run additional cmd when run git cmd

Use case:

I have a repo my-app
I want to run npm run build:prod admin first whenever I run git commit (https://githooks.com/)
if npm run build:prod admin success -> continue to git commit
else exit
I want no changes made on my repo or my package.json file

How

npm i husky -g

cd my-app
npx husky install
cd ./husky
touch pre-commit

pre-commit file will look like:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# exit 0 -> succeed
npm run build:prod admin && exit 0 
# commit a change
touch new-file.txt
git add new-file.txt
git commit -m"new file"

> npm run build:prod admin
> ...

# bypass hook
git commit -m"new file" --no-verify
> ...

That's it <3