I try use Conventional Commit and for enforcing its rule I use conventional-changelog/commitlint and typicode/husky with a pre-commit hook. For read more about its setup see commitlint docs and this article.
Here I configured a husky hook for conventional commits:
- Install NPM:
npm init
- Install Husky:
npm install husky --save-dev
- Add
prepare
command for installing and activatinghusky hooks
in the package.json file:
npm pkg set scripts.prepare="husky install"
- Install CommitLint:
npm install --save-dev @commitlint/config-conventional @commitlint/cli
- Create the
commitlint.config.js
file with this content:
module.exports = { extends: '@commitlint/config-conventional']};
- Create the Husky folder:
mkdir .husky
- Link Husky and CommitLint:
# this command should run in git-bash
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit ${1}'
- Activate and installing all husky hooks with this command:
npm run prepare