30 Sept 2024
•
Ernesto Ballon
•
5 min read
Lets run :
npm i -D husky
npm set-script prepare "husky install" OR symple create a script "prepare": "husky install" in package.json
The following command will add the hooks to the .git/hooks directory
npm run prepare
This will create a “_” folder in the .husky
directory.
npx husky add .husky/pre-commit "npm test"
git add .husky/pre-commit
git commit -m "Keep calm and commit"
# `npm test` will run
Then, you can add the desire scripts to run inside the pre-commit file.
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run pre-commit
npm run lint-staged
With that we can have more control in the quality of code that we merge to our code base. Happy coding!