Caso ainda não tenha criado, crie o repositório
git
ou clone um que já exista.
Execute no terminal
npm i -D @commitlint/config-conventional @commitlint/cli cz-conventional-changelog
Depois, rode o seguinte comando para criar o arquivo de configuração do commintlint
echo '{ "extends": ["@commitlint/config-conventional"] }' > .commitlintrc.json
Se o seu
package.json
estiver configurado com"type": "module"
, altere a extensão docommitlint.config.js
para.cjs
.
npm install -g commitizen
A instalação global evita o erro:
git: 'cz' is not a git command. See 'git --help'
"devDependencies": {
"comment": "Sua dependências..."
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
Edite o package.json
> commit
com
npm pkg set scripts.commit="git-cz"
npm install lint-staged
npm install husky --save-dev
Depois, rode o seguinte comando para criar o arquivo de configuração do lintstagedrc
echo '{ "*.{js,jsx,ts,tsx}": "eslint --fix" }' > .lintstagedrc.json
Edite o package.json
> prepare
com
npm pkg set scripts.prepare="husky install" && npm run prepare
husky init
O comando irá criar o script no package.json
e irá executar o install do Husky
npx husky add .husky/commit-msg 'npx commitlint --edit $1'
echo 'npx commitlint --edit $1' > .husky/commit-msg
npx husky add .husky/pre-commit "npx lint-staged"
echo 'npx lint-staged' > .husky/pre-commit
npx husky add .husky/prepare-commit-msg "exec < /dev/tty && git cz --hook || true"
echo 'exec < /dev/tty && git cz --hook || true' > .husky/prepare-commit-msg