I am new to husky, and the official documentation isn't so clear to me.
I am using Yarn 1. Husky 8.
Problem: I can't add a new (additional) pre commit script.
Current status: I managed to add 1 pre-commit script that works fine. This is the script I added: https://gist.github.com/johncmunson/ca02a8027a923a7f4b2f662c67d6528c This is my folders structure:
.husky
_
.gitignore
husky.sh
prepare-commit-msg
The above script is inside the file prepare-commit-msg
.
Package.json:
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"format": "prettier --write .",
"lint": "eslint . --ext ts --ext tsx",
"prepare": "husky install",
"svgo": "svgo -f . -r"
},
"husky": {
"hooks": {
"prepare-commit-msg": "./prepare-commit-msg.sh $HUSKY_GIT_PARAMS"
}
}
What did I try to do:
I created another file svgo-optimize
in the .husky
folder:
.husky
_
.gitignore
husky.sh
prepare-commit-msg
svgo-optimize
And I added to that file this script https://plxity.hashnode.dev/compress-images-using-a-pre-commit-hook
Then added to package json such line: "husky": { "hooks": { "prepare-commit-msg": "./prepare-commit-msg.sh $HUSKY_GIT_PARAMS", "svgo-optimize": "./svgo-optimize.sh $HUSKY_GIT_PARAMS" } }
But when I make git commit -m "whatever" only the first script gets run. The second one, gets completely ignored. Also if I add some
echo` at the top of this second script, these echoes don't show up.
Questions: How do I correctly add this second script? What am I doing wrong?