Guide: Use prompt
@commitlint/prompt-cli helps with fast authoring of commit messages and ensures they adhere to the commit convention configured in commitlint.config.js.
Install
Create a git repository if needed
shgit initCreate a package.json if needed
shnpm initshyarn initshpnpm initshbun initInstall and configure if needed
shnpm install --save-dev @commitlint/cli @commitlint/config-conventional @commitlint/prompt-cli echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.jsshyarn add --dev @commitlint/cli @commitlint/config-conventional @commitlint/prompt-cli echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.jsshpnpm add --save-dev @commitlint/cli @commitlint/config-conventional @commitlint/prompt-cli echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.jsshbun add --dev @commitlint/cli @commitlint/config-conventional @commitlint/prompt-cli echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.jsshdeno add --dev npm:@commitlint/cli npm:@commitlint/config-conventional npm:@commitlint/prompt-cli echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
Provide a shortcut
To make prompt-cli easy to use, add a npm run-script to your package.json
json
{
"scripts": {
"commit": "commit"
}
}Test the prompt by executing
sh
git add .
npm run commitsh
git add .
yarn commitsh
git add .
pnpm commitsh
git add .
bun commitsh
git add .
deno task commitAn alternative to @commitlint/prompt-cli: commitizen
Another way to author commit messages that adhere to the commit convention configured in commitlint.config.js is to use commitizen. For more information, checkout their official website.
commitlint provides two adapters for commitizen:
@commitlint/promptprovides a way to interact same as@commitlint/prompt-cli@commitlint/cz-commitlintis inspired by cz-conventional-changelog, it provides a more modern way to interact.