Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
commitizen
Advanced tools
Commitizen is a tool that helps you write consistent and conventional commit messages. It provides a command-line interface (CLI) to guide you through the process of creating commit messages that follow a specified convention, such as the Angular commit message guidelines.
Interactive Commit Prompts
Commitizen provides an interactive CLI that prompts you to fill out the different parts of a commit message, ensuring that your commits follow a specified convention. Running `npx cz` will start the interactive prompt.
npx cz
Custom Adapters
Commitizen supports custom adapters that define different commit message conventions. For example, you can initialize the `cz-conventional-changelog` adapter to follow the Angular commit message guidelines.
npx commitizen init cz-conventional-changelog --save-dev --save-exact
Configuration
Commitizen allows you to configure the adapter in your project's `package.json` file. This configuration tells Commitizen which adapter to use for generating commit messages.
{
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
Commitlint checks if your commit messages meet the conventional commit format. It can be used in conjunction with Commitizen to enforce commit message conventions. While Commitizen helps you write commit messages, Commitlint ensures that they adhere to the specified guidelines.
Standard Version is a tool for versioning and changelog generation based on conventional commit messages. It automates the process of version bumping and changelog generation, which complements Commitizen's functionality of creating consistent commit messages.
Semantic Release automates the versioning and package publishing process based on the commit messages. It uses the same conventional commit guidelines that Commitizen helps enforce, making it a good companion tool for automating releases.
When you commit with Commitizen, you'll be prompted to fill out any required commit fields at commit time. No more waiting until later for a git commit hook to run and reject your commit (though that can still be helpful). No more digging through CONTRIBUTING.md to find what the preferred format is. Get instant feedback on your commit message formatting and be prompted for required fields.
Installation is as simple as running the following command (if you see EACCES
error, reading fixing npm permissions may help):
npm install -g commitizen
Now, simply use git cz
instead of git commit
when committing.
Alternatively, if you are using NPM 5.2+ you can use npx
instead of installing globally:
npx git-cz
or as an npm script:
...
"scripts": {
"commit": "npx git-cz"
}
When you're working in a Commitizen friendly repository, you'll be prompted to fill in any required fields and your commit messages will be formatted according to the standards defined by project maintainers.
If you're not working in a Commitizen friendly repository, then git cz
will work just the same as git commit
.
Install commitizen
globally, if you have not already.
npm install -g commitizen
Install your preferred commitizen
adapter globally, for example cz-conventional-changelog
npm install -g cz-conventional-changelog
Create a .czrc
file in your home
directory, with path
referring to the preferred, globally installed, commitizen
adapter
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
You are all set! Now cd
into any git
repository and use git cz
instead of git commit
and you will find the commitizen
prompt.
Protip: You can use all the git commit
options
with git cz
, for example: git cz -a
.
If your repository is a nodejs project, making it Commitizen-friendly is super easy.
If your repository is already Commitizen-friendly, the local commitizen
adapter will be used, instead of globally installed one.
As a project maintainer, making your repo Commitizen friendly allows you to select pre-existing commit message conventions or to create your own custom commit message convention. When a contributor to your repo uses Commitizen, they will be prompted for the correct fields at commit time.
For this example, we'll be setting up our repo to use AngularJS's commit message convention also known as conventional-changelog.
First, install the Commitizen cli tools:
npm install commitizen -g
Next, initialize your project to use the cz-conventional-changelog adapter by typing:
commitizen init cz-conventional-changelog --save-dev --save-exact
Or if you are using Yarn:
commitizen init cz-conventional-changelog --yarn --dev --exact
Note that if you want to force install over the top of an old adapter, you can apply the --force
argument. For more information on this, just run commitizen help
.
The above command does three things for you.
config.commitizen
key to the root of your package.json as shown here:...
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
}
This just tells Commitizen which adapter we actually want our contributors to use when they try to commit to this repo.
commitizen.path
is resolved via require.resolve and supports
process.cwd()
containing an index.js
fileprocess.cwd()
with js
extensionPlease note that in the previous version of Commitizen we used czConfig. czConfig has been deprecated and you should migrate to the new format before Commitizen 3.0.0.
Installing and running Commitizen locally allows you to make sure that developers are running the exact same version of Commitizen on every machine.
Install Commitizen with npm install --save-dev commitizen
.
On NPM 5.2+ you can use npx
to initialize the conventional changelog adapter:
npx commitizen init cz-conventional-changelog --save-dev --save-exact
For previous versions of NPM (< 5.2) you can execute ./node_modules/.bin/commitizen
or ./node_modules/.bin/git-cz
in order to actually use the commands.
You can then initialize the conventional changelog adapter using: ./node_modules/.bin/commitizen init cz-conventional-changelog --save-dev --save-exact
And you can then add some nice npm run scripts in your package.json pointing to the local version of commitizen:
...
"scripts": {
"commit": "git-cz"
}
This will be more convenient for your users because then if they want to do a commit, all they need to do is run npm run commit
and they will get the prompts needed to start a commit!
NOTE: if you are using
precommit
hooks thanks to something likehusky
, you will need to name your script some thing other than "commit" (e.g. "cm": "git-cz"). The reason is because npm-scripts has a "feature" where it automatically runs scripts with the name prexxx where xxx is the name of another script. In essence, npm and husky will run "precommit" scripts twice if you name the script "commit," and the work around is to prevent the npm-triggered precommit script.
Add the Commitizen-friendly badge to your README using the following markdown:
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
Your badge will look like this:
It may also make sense to change your README.md or CONTRIBUTING.md to include or link to the Commitizen project so that your new contributors may learn more about installing and using Commitizen.
Commitizen is great on its own, but it shines when you use it with some other amazing open source tools. Kent C. Dodds shows you how to accomplish this in his Egghead.io series, How to write an open source javascript library. Many of the concepts can be applied to non-javascript projects as well.
As of version 2.7.1, you may attempt to retry the last commit using the git cz --retry
command. This can be helpful when you have tests set up to run via a git precommit hook. In this scenario, you may have attempted a Commitizen commit, painstakingly filled out all of the commitizen fields, but your tests fail. In previous Commitizen versions, after fixing your tests, you would be forced to fill out all of the fields again. Enter the retry command. Commitizen will retry the last commit that you attempted in this repo without you needing to fill out the fields again.
Please note that the retry cache may be cleared when upgrading commitizen versions, upgrading adapters, or if you delete the commitizen.json
file in your home or temp directory. Additionally, the commit cache uses the filesystem path of the repo, so if you move a repo or change its path, you will not be able to retry a commit. This is an edge case, but might be confusing if you have scenarios where you are moving folders that contain repos.
It is important to note that if you are running git-cz
from a npm script (let's say it is called commit
) you will need to do one of the following:
-- --retry
as an argument for your script. i.e: npm run commit -- --retry
npm-run git-cz --retry
nr commit --retry
or just nr c --retry
(which will run all scripts that starts with the letter 'c')Note that the last two options do not require you to pass --
before the args but the first does.
As a project maintainer of many projects, you may want to standardize on a single commit message format for all of them. You can create your own node module which acts as front-end for commitizen.
// my-cli.js
#!/usr/bin/env node
"use strict";
const path = require('path');
const bootstrap = require('commitizen/dist/cli/git-cz').bootstrap;
bootstrap({
cliPath: path.join(__dirname, '../../node_modules/commitizen'),
// this is new
config: {
"path": "cz-conventional-changelog"
}
});
// package.json
{
"name": "company-commit",
"bin": "./my-cli.js"
"dependencies": {
"commitizen": "^2.7.6",
"cz-conventional-changelog": "^1.1.5",
}
}
npm install company-commit --save-dev
./node_modules/.bin/company-commit
We know that every project and build process has different requirements so we've tried to keep Commitizen open for extension. You can do this by choosing from any of the pre-build adapters or even by building your own. Here are some of the great adapters available to you:
To create an adapter, just fork one of these great adapters and modify it to suit your needs. We pass you an instance of Inquirer.js but you can capture input using whatever means necessary. Just call the commit
callback with a string and we'll be happy. Publish it to npm, and you'll be all set!
Commitizen is an open source project that helps contributors be good open source citizens. It accomplishes this by prompting them to follow commit message conventions at commit time. It also empowers project maintainers to create or use predefined commit message conventions in their repos to better communicate their expectations to potential contributors.
Both! Commitizen is not meant to be a replacement for git commit hooks. Rather, it is meant to work side-by-side with them to ensure a consistent and positive experience for your contributors. Commitizen treats the commit command as a declarative action. The contributor is declaring that they wish to contribute to your project. It is up to you as the maintainer to define what rules they should be following.
We accomplish this by letting you define which adapter you'd like to use in your project. Adapters just allow multiple projects to share the same commit message conventions. A good example of an adapter is the cz-conventional-changelog adapter.
@JimTheDev (Jim Cummins, author) @kentcdodds @accraze @kytwb @Den-dp
Special thanks to @stevelacy, whose gulp-git project makes commitizen possible.
This project exists thanks to all the people who contribute. [Contribute].
Thank you to all our backers! 🙏 [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
FAQs
Git commit, but play nice with conventions.
The npm package commitizen receives a total of 730,616 weekly downloads. As such, commitizen popularity was classified as popular.
We found that commitizen demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.