The git-cz configuration system provides flexible configuration loading from multiple sources with default fallbacks and validation.
/**
* Load configuration with overrides from various sources
* @param root - Git repository root directory path
* @returns Merged configuration object with defaults and overrides
*/
function getConfig(root: string): Config;Configuration Resolution Order:
lib/defaults.js).git-cz.jsonchangelog.config.jschangelog.config.cjschangelog.config.jsonconfig.commitizen.changelog field/**
* Create application state with configuration and default answers
* @param config - Optional configuration overrides
* @returns State object with answers, config, and root properties
* @throws Error if git repository root cannot be found
*/
function createState(config?: Partial<Config>): State;The state object contains:
answers: Default answer values for all commit questionsconfig: Merged configuration from all sourcesroot: Git repository root directory path.git-cz.json:
{
"disableEmoji": false,
"format": "{type}{scope}: {emoji}{subject}",
"maxMessageLength": 64,
"minMessageLength": 3,
"scopes": ["api", "ui", "docs"],
"types": {
"feat": {
"description": "A new feature",
"emoji": "πΈ",
"value": "feat"
}
}
}changelog.config.json:
{
"format": "{type}{scope}: {emoji}{subject}",
"list": ["feat", "fix", "docs", "style", "refactor", "test", "chore"],
"scopes": ["auth", "api", "ui"],
"questions": ["type", "scope", "subject", "body", "breaking", "issues"]
}changelog.config.js:
module.exports = {
format: '{type}{scope}: {emoji}{subject}',
scopes: ['auth', 'api', 'ui', 'docs'],
types: {
feat: {
description: 'A new feature',
emoji: 'πΈ',
value: 'feat'
},
fix: {
description: 'A bug fix',
emoji: 'π',
value: 'fix'
}
},
questions: ['type', 'scope', 'subject', 'body', 'breaking', 'issues']
};changelog.config.cjs (CommonJS):
module.exports = {
disableEmoji: true,
format: '{type}{scope}: {subject}',
maxMessageLength: 72,
scopes: process.env.NODE_ENV === 'development' ? ['dev', 'test'] : ['prod']
};{
"config": {
"commitizen": {
"path": "./node_modules/git-cz",
"changelog": {
"format": "{type}{scope}: {emoji}{subject}",
"scopes": ["frontend", "backend", "docs"],
"disableEmoji": false
}
}
}
}interface Config {
/** Commit message format template with placeholders */
format: string;
/** Maximum allowed commit message length */
maxMessageLength: number;
/** Minimum required commit message length */
minMessageLength: number;
/** Map of commit types with metadata */
types: Record<string, CommitType>;
/** Ordered list of commit type names */
list: string[];
/** Available scopes for the project */
scopes: string[];
/** Questions to ask in interactive mode */
questions: string[];
/** Emoji prefix for breaking changes */
breakingChangePrefix: string;
/** Message template for closed issues */
closedIssueMessage: string;
/** Emoji prefix for closed issues */
closedIssuePrefix: string;
/** Disable emoji in commit messages */
disableEmoji?: boolean;
/** Custom messages for individual questions */
messages?: Record<string, string>;
}
interface CommitType {
/** Human-readable description of the commit type */
description: string;
/** Emoji associated with this commit type */
emoji: string;
/** Commit type value used in the message */
value: string;
}// Default format template
const format = '{type}{scope}: {emoji}{subject}';
// Default commit types with emojis
const types = {
chore: { description: 'Build process or auxiliary tool changes', emoji: 'π€', value: 'chore' },
ci: { description: 'CI related changes', emoji: 'π‘', value: 'ci' },
docs: { description: 'Documentation only changes', emoji: 'βοΈ', value: 'docs' },
feat: { description: 'A new feature', emoji: 'πΈ', value: 'feat' },
fix: { description: 'A bug fix', emoji: 'π', value: 'fix' },
perf: { description: 'A code change that improves performance', emoji: 'β‘οΈ', value: 'perf' },
refactor: { description: 'A code change that neither fixes a bug or adds a feature', emoji: 'π‘', value: 'refactor' },
release: { description: 'Create a release commit', emoji: 'πΉ', value: 'release' },
style: { description: 'Markup, white-space, formatting, missing semi-colons...', emoji: 'π', value: 'style' },
test: { description: 'Adding missing tests', emoji: 'π', value: 'test' }
};
// Default configuration constants
const config = {
breakingChangePrefix: '𧨠',
closedIssueMessage: 'Closes: ',
closedIssuePrefix: 'β
',
format,
list: ['test', 'feat', 'fix', 'chore', 'docs', 'refactor', 'style', 'ci', 'perf'],
maxMessageLength: 64,
minMessageLength: 3,
questions: ['type', 'scope', 'subject', 'body', 'breaking', 'issues', 'lerna'],
scopes: [],
types
};const getConfig = require('git-cz/lib/getConfig');
const createState = require('git-cz/lib/createState');
// Load configuration for current directory
const config = getConfig(process.cwd());
console.log(config.types.feat.emoji); // πΈ
// Create state with default configuration
const state = createState();
console.log(state.config.maxMessageLength); // 64
// Create state with custom overrides
const customState = createState({
disableEmoji: true,
maxMessageLength: 100
});const getConfig = require('git-cz/lib/getConfig');
try {
const config = getConfig('/path/to/repo');
// Validate scopes configuration
if (config.scopes && !Array.isArray(config.scopes)) {
throw new TypeError('scopes must be an array of strings');
}
console.log('Configuration loaded successfully');
} catch (error) {
console.error('Configuration error:', error.message);
}// changelog.config.js with dynamic values
module.exports = {
scopes: process.env.NODE_ENV === 'production'
? ['api', 'ui', 'docs']
: ['api', 'ui', 'docs', 'dev', 'test'],
disableEmoji: process.env.CI === 'true',
maxMessageLength: process.env.LONG_COMMITS === 'true' ? 100 : 64
};