-
Notifications
You must be signed in to change notification settings - Fork 5
Tools Conventional Commits
A specification for adding human and machine readable meaning to commit messages
You can using Conventional Commits in your repository using the following 3 tools:
- Commitizen
- Commitlint
- Husky
Commitizen is a CLI utility that helps you in typing when writing a commit message.
Let use it to write commit messages with following to Conventional Commits.
$ npm install --save-dev commitizen
$ npx commitizen init cz-conventional-changelog --save-dev --save-exact
$ npm set-script commit "cz"
By executing the above commands, the package.json
should modified like this now:
...
"scripts": {
...
"commit": "cz"
},
...
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
Now, you can use the input assistance by Commitizen by execute npm run commit
command, when you writing a commit message.
Commitlint is a Linter for commit messages.
Let use it to check that you are following Conventional Commits rules, even if you write a commit message without using Commitizen.
$ npm install --save-dev @commitlint/{config-conventional,cli}
Then, open the package.json
and insert the commitlint
field as follows:
...
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
}
}
Husky is a hook tool for Git.
Let use it to execute commitlint when you write a commit message in the repository.
$ npm install --save-dev husky
$ npm set-script prepare "node --eval 'process.exit(process.env.NODE_ENV == \"production\" ? 0 : 1)' || husky install"
$ npm run prepare
$ npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
By executing the above commands, the .husky/commit-msg
should modified like this now:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install commitlint --edit "$1"
And, package.json
should modified like this:
{
...
"scripts": {
...
"prepare": "node --eval 'process.exit(process.env.NODE_ENV == \"production\" ? 0 : 1)' || husky install"
},
...
NOTE: To works it properly in the production environment, It will be changed command depending whether the environment (NODE_ENV variable) is production.