Commitizen adapter following the conventional-changelog format for standardized commit messages.
npx @tessl/cli install tessl/npm-cz-conventional-changelog@3.3.0A commitizen adapter that implements the conventional changelog format for creating standardized commit messages. This adapter provides an interactive prompting interface that guides developers through creating consistent, structured commit messages following conventional commit standards.
npm install cz-conventional-changelog// Direct usage (when configured as commitizen adapter)
const adapter = require('cz-conventional-changelog');For commitizen configuration in package.json:
{
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}The package is primarily used as a commitizen adapter. After installation and configuration, use with:
# Using git-cz (commitizen CLI)
git add .
git czThe adapter will prompt you through creating a conventional commit message following the format:
type(scope): subject
body
BREAKING CHANGE: breaking change description
issue referencesProvides a complete commitizen adapter object with interactive prompting functionality. The main module export is a function that takes configuration options and returns a commitizen adapter object.
/**
* Main export - factory function that creates a commitizen adapter
* @param {Object} options - Configuration options for the adapter
* @returns {Object} Commitizen adapter object with prompter function
*/
function createAdapter(options) {
return {
prompter: function(cz, commit) { /* implementation */ }
};
}
// Default export (index.js) pre-configures and returns the adapter
module.exports = createAdapter(configuredOptions);The core prompter function that guides users through conventional commit creation.
/**
* The prompter function guides users through conventional commit creation
* @param {Object} cz - Inquirer.js instance for prompting
* @param {Function} commit - Callback function to execute with final commit message
* @returns {void}
*/
function prompter(cz, commit);Interactive Prompts:
The prompter function guides users through the following sequence of questions:
All configuration options can be set in package.json under config.commitizen or via environment variables.
interface ConfigurationOptions {
/** Custom commit types object */
types?: { [key: string]: { description: string; title: string } };
/** Default commit type selection */
defaultType?: string;
/** Default scope value */
defaultScope?: string;
/** Default subject text */
defaultSubject?: string;
/** Default body text */
defaultBody?: string;
/** Default issues reference text */
defaultIssues?: string;
/** Disable automatic lowercase conversion of scope */
disableScopeLowerCase?: boolean;
/** Disable automatic lowercase conversion of subject */
disableSubjectLowerCase?: boolean;
/** Maximum width for commit header (default: 100) */
maxHeaderWidth?: number;
/** Maximum width for commit body lines (default: 100) */
maxLineWidth?: number;
}Environment Variable Overrides:
// Environment variables that override configuration
const environmentVariables = {
CZ_TYPE: "defaultType",
CZ_SCOPE: "defaultScope",
CZ_SUBJECT: "defaultSubject",
CZ_BODY: "defaultBody",
CZ_ISSUES: "defaultIssues",
CZ_MAX_HEADER_WIDTH: "maxHeaderWidth",
CZ_MAX_LINE_WIDTH: "maxLineWidth",
DISABLE_SCOPE_LOWERCASE: "disableScopeLowerCase",
DISABLE_SUBJECT_LOWERCASE: "disableSubjectLowerCase"
};Define custom commit types in your configuration:
{
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog",
"types": {
"feat": {
"description": "A new feature",
"title": "Features"
},
"fix": {
"description": "A bug fix",
"title": "Bug Fixes"
},
"docs": {
"description": "Documentation changes",
"title": "Documentation"
},
"style": {
"description": "Code style changes",
"title": "Styles"
},
"refactor": {
"description": "Code refactoring",
"title": "Code Refactoring"
},
"test": {
"description": "Adding or updating tests",
"title": "Tests"
},
"chore": {
"description": "Other changes",
"title": "Chores"
}
}
}
}
}The adapter automatically integrates with commitlint for header length validation:
/**
* Automatic commitlint integration
* If @commitlint/load is available, the adapter will:
* - Load commitlint configuration
* - Use header-max-length rule for maxHeaderWidth if not explicitly set
* - Override package.json and environment variable settings
*/{
"devDependencies": {
"commitizen": "^4.0.3",
"cz-conventional-changelog": "^3.3.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"scripts": {
"commit": "git-cz"
}
}{
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog",
"maxHeaderWidth": 72,
"maxLineWidth": 100,
"defaultType": "feat",
"defaultScope": "core",
"disableScopeLowerCase": true,
"disableSubjectLowerCase": false
}
}
}# Set defaults via environment variables
export CZ_TYPE="fix"
export CZ_SCOPE="auth"
export CZ_MAX_HEADER_WIDTH="50"
# Run commitizen
git czconst adapter = require('cz-conventional-changelog');
// The adapter object contains the prompter function
// Typically used by commitizen CLI, but can be used programmatically
console.log(typeof adapter.prompter); // "function"The adapter generates commit messages in conventional changelog format:
type(scope): subject
Optional body paragraph providing more detail about the change.
Can be multiple lines and should wrap at the configured maxLineWidth.
BREAKING CHANGE: Description of breaking changes if any exist.
This section appears when breaking changes are indicated.
Closes #123, #456Examples:
feat(auth): add OAuth2 login supportfix(parser): handle edge case in URL parsingdocs: update installation instructionsrefactor!: change API response formatThe adapter requires the following runtime dependencies:
commitizen: Configuration loading and CLI integrationconventional-commit-types: Standard commit type definitionschalk: Terminal color output for validation feedbackword-wrap: Text wrapping for commit body formattinglodash.map: Array mapping utilitylongest: Find longest string utility for formattingOptional dependency:
@commitlint/load: For commitlint configuration integration