Semantic emojified git commit CLI tool with interactive prompts and Commitizen integration
npx @tessl/cli install tessl/npm-git-cz@4.8.0git-cz is a semantic emojified git commit tool that provides interactive prompts for creating conventional commits with emoji support. It integrates with the Commitizen ecosystem and offers both command-line and programmatic interfaces for consistent commit message formatting.
npm install git-czFor programmatic use as a Commitizen adapter:
const { prompter } = require("git-cz");For configuration and utility functions:
const createState = require("git-cz/lib/createState");
const getConfig = require("git-cz/lib/getConfig");
const formatCommitMessage = require("git-cz/lib/formatCommitMessage");
const parseArgs = require("git-cz/lib/parseArgs");
const runInteractiveQuestions = require("git-cz/lib/runInteractiveQuestions");
const runNonInteractiveMode = require("git-cz/lib/runNonInteractiveMode");For git utilities:
const getGitRootDir = require("git-cz/lib/util/getGitRootDir");
const getGitDir = require("git-cz/lib/util/getGitDir");
const { getAllPackages, getChangedPackages, isLerna } = require("git-cz/lib/util/lerna");For question creators:
const createQuestions = require("git-cz/lib/createQuestions");
const LimitedInputPrompt = require("git-cz/lib/LimitedInputPrompt");# Interactive mode (default)
git-cz
# or
gitcz
# Non-interactive mode
git-cz --non-interactive --type=feat --subject="add new feature"
# With additional options
git-cz --disable-emoji --dry-run --type=fix --subject="fix bug" --body="detailed description"// Using as a Commitizen adapter
const { prompter } = require("git-cz");
// This function is called by Commitizen
prompter(cz, commit => {
// commit is called with the formatted message
});const createState = require("git-cz/lib/createState");
const formatCommitMessage = require("git-cz/lib/formatCommitMessage");
// Create state with configuration
const state = createState();
// Set answers
state.answers = {
type: "feat",
scope: "auth",
subject: "add OAuth integration",
body: "Implemented OAuth 2.0 flow with Google and GitHub providers",
breaking: "",
issues: "#123"
};
// Format the commit message
const message = formatCommitMessage(state);
console.log(message);
// Output: feat(auth): 🎸 add OAuth integration
//
// Implemented OAuth 2.0 flow with Google and GitHub providers
//
// ✅ Closes: #123git-cz is built around several key components:
Command-line tool with comprehensive options for both interactive and non-interactive commit workflows. Includes dry-run mode, emoji control, and git hook integration.
// Available through bin/git-cz.js executable
// Supports all git commit pass-through argumentsProgrammatic adapter for the Commitizen ecosystem, providing the prompter function that handles interactive commit message creation.
/**
* Commitizen prompter function for interactive commit message creation
* @param cz - Commitizen instance
* @param commit - Callback function to execute the commit
*/
function prompter(cz: any, commit: (message: string) => void): void;Flexible configuration system supporting multiple file formats and sources with default fallbacks and validation.
/**
* Load configuration with overrides from various sources
* @param root - Git repository root directory
* @returns Merged configuration object
*/
function getConfig(root: string): Config;
/**
* Create application state with configuration and default answers
* @param config - Optional configuration overrides
* @returns State object with answers, config, and root
*/
function createState(config?: Partial<Config>): State;Custom question system with fuzzy search, character limits, and validation for gathering commit information through interactive prompts.
/**
* Run interactive questions to collect commit information
* @param state - Application state with configuration
* @param cliAnswers - Pre-filled answers from CLI arguments
* @returns Promise resolving to collected answers
*/
async function runInteractiveQuestions(
state: State,
cliAnswers?: Partial<Answers>
): Promise<Answers>;
/**
* Create filtered questions based on state and CLI answers
* @param state - Application state
* @param cliAnswers - Answers provided via CLI
* @returns Array of inquirer question objects
*/
function createQuestions(state: State, cliAnswers: Partial<Answers>): Question[];Template-based commit message generation with emoji support, word wrapping, and conventional commit format compliance.
/**
* Format commit message from state using configuration template
* @param state - Application state with answers and configuration
* @returns Formatted commit message string
*/
function formatCommitMessage(state: State): string;Command-line argument parsing with support for pass-through git options and non-interactive mode.
/**
* Parse command-line arguments for CLI and non-interactive options
* @returns Object with cliAnswers, cliOptions, and passThroughParams
*/
function parseArgs(): {
cliAnswers: Partial<Answers>;
cliOptions: {
disableEmoji?: boolean;
dryRun?: boolean;
format?: string;
help?: boolean;
hook?: boolean;
nonInteractive?: boolean;
version?: boolean;
};
passThroughParams: Record<string, string | boolean>;
};Execute git-cz without interactive prompts using predefined answers.
/**
* Populate state with answers for non-interactive execution
* @param state - Application state to update
* @param answers - Answer values with defaults (type: "chore", subject: "automated commit")
*/
function runNonInteractiveMode(
state: State,
answers: { type?: string; subject?: string; [key: string]: any }
): void;Helper functions for git repository operations and path resolution.
/**
* Get the root directory of the current git repository
* @returns Absolute path to git repository root
* @throws Error if not in a git repository
*/
function getGitRootDir(): string;
/**
* Get the .git directory path for the current repository
* @returns Absolute path to .git directory
*/
function getGitDir(): string;Utilities for working with Lerna monorepo environments.
/**
* Check if current project is a Lerna monorepo
* @param state - Application state with root directory
* @returns True if Lerna project detected
*/
function isLerna(state: State): boolean;
/**
* Get all packages in the Lerna monorepo
* @param state - Application state with root directory
* @returns Array of package names
*/
function getAllPackages(state: State): string[];
/**
* Get packages with changes in the Lerna monorepo
* @param state - Application state with root directory
* @returns Array of changed package names
*/
function getChangedPackages(state: State): string[];interface Config {
/** Commit message format template */
format: string;
/** Maximum commit message length */
maxMessageLength: number;
/** Minimum commit message length */
minMessageLength: number;
/** Available commit types with descriptions and emojis */
types: Record<string, CommitType>;
/** List of commit type names in order */
list: string[];
/** Available scopes for the project */
scopes: string[];
/** Questions to ask during interactive mode */
questions: string[];
/** Breaking change prefix emoji */
breakingChangePrefix: string;
/** Closed issue message template */
closedIssueMessage: string;
/** Closed issue prefix emoji */
closedIssuePrefix: string;
/** Disable emoji in commit messages */
disableEmoji?: boolean;
/** Custom messages for questions */
messages?: Record<string, string>;
}
interface CommitType {
/** Human-readable description */
description: string;
/** Emoji for this commit type */
emoji: string;
/** Type value used in commit message */
value: string;
}
interface State {
/** User answers to commit questions */
answers: Answers;
/** Merged configuration */
config: Config;
/** Git repository root directory */
root: string;
}
interface Answers {
/** Commit type (feat, fix, etc.) */
type: string;
/** Commit scope (optional) */
scope: string;
/** Commit subject/title */
subject: string;
/** Commit body (optional) */
body: string;
/** Breaking changes description (optional) */
breaking: string;
/** Issues closed by this commit (optional) */
issues: string;
/** Lerna packages affected - CLI uses 'lerna', question sets 'packages' */
lerna: string;
/** Packages selected in Lerna question (used by formatCommitMessage) */
packages?: string[];
}
interface Question {
/** Question type (input, autocomplete, checkbox, etc.) */
type: string;
/** Answer property name */
name: string;
/** Question message/prompt text */
message: string;
/** Source function for autocomplete questions */
source?: (answers: any, input: string) => Promise<any[]>;
/** Choices for selection questions */
choices?: any[];
/** Validation function */
validate?: (input: any) => boolean | string;
/** Input filter function */
filter?: (input: any) => any;
/** Maximum input length for limited prompts */
maxLength?: number;
/** Leading label function for prompts */
leadingLabel?: string | ((answers: any) => string);
}
interface LimitedInputPrompt {
/** Create a new limited input prompt with character counting */
constructor(options: {
maxLength: number;
leadingLabel?: string | ((answers: any) => string);
message: string;
name: string;
validate?: (input: string) => boolean | string;
filter?: (input: string) => string;
});
/** Calculate remaining characters */
remainingChar(): number;
/** Handle keypress events with length enforcement */
onKeypress(): void;
/** Get colored remaining character count text */
getCharsLeftText(): string;
/** Render prompt with character counter */
render(error?: string): void;
}