or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdcommitizen.mdconfiguration.mdformatting.mdindex.mdquestions.mdutilities.md
tile.json

configuration.mddocs/

Configuration System

The git-cz configuration system provides flexible configuration loading from multiple sources with default fallbacks and validation.

Capabilities

Configuration Loading

/**
 * 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:

  1. Default configuration (lib/defaults.js)
  2. Configuration file overrides (searched in order):
    • .git-cz.json
    • changelog.config.js
    • changelog.config.cjs
    • changelog.config.json
  3. Package.json config.commitizen.changelog field

State Creation

/**
 * 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 questions
  • config: Merged configuration from all sources
  • root: Git repository root directory path

Configuration Sources

JSON Configuration Files

.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"]
}

JavaScript Configuration Files

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']
};

Package.json Configuration

{
  "config": {
    "commitizen": {
      "path": "./node_modules/git-cz",
      "changelog": {
        "format": "{type}{scope}: {emoji}{subject}",
        "scopes": ["frontend", "backend", "docs"],
        "disableEmoji": false
      }
    }
  }
}

Configuration Schema

Complete Configuration Object

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 Configuration Values

// 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
};

Usage Examples

Basic Configuration Loading

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 
});

Custom Configuration Validation

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);
}

Dynamic Configuration

// 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
};