The git-cz Commitizen adapter provides programmatic integration with the Commitizen ecosystem for interactive commit message creation.
The main export for Commitizen integration is the prompter function.
/**
* Commitizen prompter function for interactive commit message creation
* @param cz - Commitizen instance provided by the framework
* @param commit - Callback function to execute the final commit
*/
function prompter(cz: any, commit: (message: string) => void): void;Usage in Commitizen:
const { prompter } = require("git-cz");
// Called by Commitizen framework
prompter(cz, (message) => {
// message contains the formatted commit message
// Commitizen handles the actual git commit
});To use git-cz as a Commitizen adapter, configure it in your package.json:
{
"config": {
"commitizen": {
"path": "./node_modules/git-cz"
}
}
}Or use the built distribution:
{
"config": {
"commitizen": {
"path": "./dist/cz.js"
}
}
}The prompter function internally:
createState()runInteractiveQuestions()formatCommitMessage()# Install Commitizen globally
npm install -g commitizen
# Install git-cz locally
npm install --save-dev git-cz
# Configure in package.json
{
"config": {
"commitizen": {
"path": "./node_modules/git-cz"
}
}
}
# Use with Commitizen
git czconst { prompter } = require("git-cz");
// Custom implementation
const customCommit = (message) => {
console.log("Generated commit message:");
console.log(message);
// Custom logic here instead of git commit
};
// Mock Commitizen instance
const mockCz = {};
prompter(mockCz, customCommit);const { prompter } = require("git-cz");
// Integration with git workflow tools
const handleCommit = async (message) => {
// Pre-commit processing
await runLinting();
await runTests();
// Execute git commit
execSync(`git commit -m "${message}"`);
// Post-commit actions
await updateChangelog();
};
prompter({}, handleCommit);The adapter respects all git-cz configuration options loaded from:
.git-cz.jsonchangelog.config.jschangelog.config.cjschangelog.config.jsonpackage.json (in config.commitizen.changelog)Example configuration:
{
"config": {
"commitizen": {
"path": "./node_modules/git-cz",
"changelog": {
"disableEmoji": false,
"format": "{type}{scope}: {emoji}{subject}",
"maxMessageLength": 64,
"minMessageLength": 3,
"scopes": ["auth", "api", "ui", "docs"],
"types": {
"feat": {
"description": "A new feature",
"emoji": "🎸",
"value": "feat"
}
}
}
}
}
}