Skip to content

✨ A modern CLI tool to write smart, consistent, and beautiful git commit messages, powered by Conventional Commits, emoji support, and optional AI. @typeweaver/commitweave

License

Notifications You must be signed in to change notification settings

GLINCKER/commitweave

Repository files navigation

Commitweave 🧢

npm version TypeScript License: MIT Node.js CI

A modern, battle-tested CLI tool for creating smart, structured, and beautiful git commit messages with emoji support, conventional commit rules, AI-powered summaries, and comprehensive TypeScript integration.

✨ Features

  • 🎨 Beautiful Interactive CLI - Intuitive prompts with colorful output using chalk and enquirer
  • πŸ“ Conventional Commits - Full support for conventional commit standards
  • 🎭 Smart Emoji Integration - Contextual emojis for different commit types
  • πŸ€– AI-Powered Summaries - Optional AI-generated commit messages (OpenAI, Anthropic, Mock)
  • βš™οΈ Highly Configurable - Customize commit types, emojis, and validation rules
  • πŸͺ Git Hooks Ready - Built-in pre-commit and post-commit hook support
  • πŸ”§ Full TypeScript Support - Complete type definitions and IntelliSense
  • πŸ“¦ Dual Module Support - Works with both CommonJS and ESM projects
  • πŸ›‘οΈ Cross-Platform - Windows, macOS, and Linux support
  • 🎯 Zero Dependencies in Production - Lightweight and fast

πŸš€ Installation

Global Installation (Recommended)

npm install -g @typeweaver/commitweave

Project Installation

# Using npm npm install --save-dev @typeweaver/commitweave # Using yarn yarn add --dev @typeweaver/commitweave # Using pnpm pnpm add --save-dev @typeweaver/commitweave

🎯 Quick Start

# Navigate to your git repository cd your-project # Initialize configuration (optional) commitweave init # Create a commit interactively commitweave

πŸ“– Usage

CLI Usage

# Interactive commit creation commitweave # Initialize configuration file commitweave init # Show help information commitweave --help

Programmatic Usage

CommonJS

const { CommitBuilder, defaultConfig, GitUtils } = require('@typeweaver/commitweave'); const builder = new CommitBuilder(defaultConfig); const message = builder .setType('feat') .setSubject('add user authentication') .setBody('Implement JWT-based authentication system') .build(); console.log(message); // Output: feat: ✨ add user authentication

ES Modules

import { CommitBuilder, defaultConfig, GitUtils, createCommitMessage } from '@typeweaver/commitweave'; // Using the builder pattern const builder = new CommitBuilder(defaultConfig); const message = builder .setType('fix') .setScope('auth') .setSubject('resolve token expiration issue') .setBreakingChange(false) .build(); // Using the helper function const quickMessage = createCommitMessage( 'docs', 'update API documentation', { config: defaultConfig } );

TypeScript

import type { Config, CommitType, CommitMessage, AIProvider, AISummaryOptions } from '@typeweaver/commitweave'; import { CommitBuilder, GitUtils, createAIProvider } from '@typeweaver/commitweave'; const config: Config = { commitTypes: [ { type: 'feat', emoji: '✨', description: 'A new feature', aliases: ['feature'] } ], emojiEnabled: true, conventionalCommits: true, aiSummary: false, maxSubjectLength: 50, maxBodyLength: 72 }; const gitUtils = new GitUtils(); const aiProvider = createAIProvider({ provider: 'mock' });

βš™οΈ Configuration

Commitweave uses glinr-commit.json for configuration. Create one with:

commitweave init

Configuration Schema

{ "commitTypes": [ { "type": "feat", "emoji": "✨", "description": "A new feature", "aliases": ["feature", "new"] }, { "type": "fix", "emoji": "πŸ›", "description": "A bug fix", "aliases": ["bugfix", "hotfix"] }, { "type": "docs", "emoji": "πŸ“š", "description": "Documentation changes", "aliases": ["documentation"] }, { "type": "style", "emoji": "πŸ’Ž", "description": "Code style changes", "aliases": ["formatting"] }, { "type": "refactor", "emoji": "πŸ“¦", "description": "Code refactoring", "aliases": ["refactoring"] }, { "type": "perf", "emoji": "πŸš€", "description": "Performance improvements", "aliases": ["performance", "optimization"] }, { "type": "test", "emoji": "🚨", "description": "Adding or updating tests", "aliases": ["testing"] }, { "type": "build", "emoji": "πŸ› ", "description": "Build system changes", "aliases": ["ci", "deps"] }, { "type": "ci", "emoji": "βš™οΈ", "description": "CI configuration changes", "aliases": ["continuous-integration"] }, { "type": "chore", "emoji": "♻️", "description": "Other maintenance changes", "aliases": ["maintenance"] }, { "type": "revert", "emoji": "πŸ—‘", "description": "Revert previous changes", "aliases": ["rollback"] } ], "emojiEnabled": true, "conventionalCommits": true, "aiSummary": false, "maxSubjectLength": 50, "maxBodyLength": 72, "ai": { "provider": "mock", "apiKey": "", "model": "gpt-3.5-turbo", "maxTokens": 150, "temperature": 0.7 }, "hooks": { "preCommit": [], "postCommit": [] } }

Configuration Options

Option Type Default Description
commitTypes CommitType[] [Default types] Available commit types with emojis and aliases
emojiEnabled boolean true Include emojis in commit messages
conventionalCommits boolean true Follow conventional commit format
aiSummary boolean false Enable AI-powered commit generation
maxSubjectLength number 50 Maximum commit subject length
maxBodyLength number 72 Maximum line length for commit body
ai.provider string "mock" AI provider: openai, anthropic, or mock
ai.apiKey string "" API key for the AI provider
ai.model string Provider default Model to use for AI generation
hooks.preCommit string[] [] Commands to run before commit
hooks.postCommit string[] [] Commands to run after commit

πŸ€– AI Integration

Commitweave supports multiple AI providers for intelligent commit message generation:

OpenAI Integration

{ "ai": { "provider": "openai", "apiKey": "your-openai-api-key", "model": "gpt-3.5-turbo", "maxTokens": 150, "temperature": 0.7 } }

Anthropic Integration

{ "ai": { "provider": "anthropic", "apiKey": "your-anthropic-api-key", "model": "claude-3-haiku-20240307", "maxTokens": 150, "temperature": 0.7 } }

Mock Provider (Default)

Perfect for testing and development without API costs:

{ "ai": { "provider": "mock" } }

πŸ› οΈ API Reference

CommitBuilder

The main class for building commit messages:

class CommitBuilder { constructor(config: Config) setType(type: string): this setScope(scope: string): this setSubject(subject: string): this setBody(body: string): this setFooter(footer: string): this setBreakingChange(isBreaking: boolean): this setEmoji(emoji: string): this build(): string validate(): { valid: boolean; errors: string[] } reset(): this }

GitUtils

Git operations wrapper with enhanced functionality:

class GitUtils { constructor(workingDir?: string) async isGitRepository(): Promise<boolean> async getStatus(): Promise<StatusResult> async getStagedChanges(): Promise<StagedChanges> async getDiff(staged?: boolean): Promise<string> async stageAll(): Promise<void> async stageFiles(files: string[]): Promise<void> async commit(message: string, options?: { dryRun?: boolean }): Promise<string> async getCurrentBranch(): Promise<string> async getLastCommitMessage(): Promise<string> async hasUncommittedChanges(): Promise<boolean> }

AI Providers

interface AIProvider { generateCommitMessage(diff: string, options?: AISummaryOptions): Promise<CommitSuggestion> isConfigured(): boolean } // Available providers const openaiProvider = new OpenAIProvider(apiKey, model); const anthropicProvider = new AnthropicProvider(apiKey, model); const mockProvider = new MockAIProvider();

πŸ—οΈ Development

Building from Source

# Clone the repository git clone https://github.com/GLINCKER/commitweave.git cd commitweave # Install dependencies npm install # Build the project (dual CJS/ESM output) npm run build # Run in development mode npm run dev # Test the CLI locally npm start

Build System

Commitweave uses a sophisticated dual-build system:

  • CommonJS Build (dist/index.js) - For Node.js and older tools
  • ESM Build (dist/index.mjs) - For modern ES modules
  • TypeScript Declarations (dist/index.d.ts) - For full type support
  • CLI Binary (dist/bin.js) - Executable CLI tool

Project Structure

commitweave/ β”œβ”€β”€ bin/ β”‚ β”œβ”€β”€ index.ts # ESM CLI entrypoint β”‚ └── index.cjs.ts # CommonJS CLI entrypoint β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ types/ # TypeScript type definitions β”‚ β”‚ β”œβ”€β”€ config.ts # Configuration types β”‚ β”‚ β”œβ”€β”€ commit.ts # Commit message types β”‚ β”‚ β”œβ”€β”€ git.ts # Git operation types β”‚ β”‚ β”œβ”€β”€ ai.ts # AI provider types β”‚ β”‚ └── index.ts # Unified type exports β”‚ β”œβ”€β”€ config/ β”‚ β”‚ └── defaultConfig.ts # Default configuration β”‚ β”œβ”€β”€ core/ β”‚ β”‚ └── commitBuilder.ts # Commit message builder β”‚ β”œβ”€β”€ utils/ β”‚ β”‚ β”œβ”€β”€ git.ts # Git operations β”‚ β”‚ └── ai.ts # AI integrations β”‚ └── index.ts # Main library exports β”œβ”€β”€ scripts/ β”‚ └── prepare-dist.js # Build preparation script β”œβ”€β”€ dist/ # Build output β”‚ β”œβ”€β”€ index.js # CommonJS entry β”‚ β”œβ”€β”€ index.mjs # ESM entry β”‚ β”œβ”€β”€ index.d.ts # Type definitions β”‚ β”œβ”€β”€ bin.js # CLI executable β”‚ └── lib/ # Internal modules β”œβ”€β”€ tsconfig*.json # TypeScript configurations β”œβ”€β”€ glinr-commit.json # Default config template └── README.md 

πŸ§ͺ Testing

# Run tests (when available) npm test # Test package imports node -e "console.log(Object.keys(require('./dist/index.js')))" # Test CLI functionality ./dist/bin.js --help

πŸ“¦ Package Distribution

The package is optimized for npm distribution with:

  • βœ… Dual Module Support - Both CJS and ESM
  • βœ… Complete TypeScript Definitions - Full IntelliSense support
  • βœ… Tree-shakable Exports - Import only what you need
  • βœ… Zero Runtime Dependencies - Production builds are dependency-free
  • βœ… Cross-platform Binary - Works on Windows, macOS, and Linux

🀝 Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes with proper TypeScript types
  4. Test your changes: npm run build && npm test
  5. Commit using commitweave: commitweave
  6. Push to your branch: git push origin feature/amazing-feature
  7. Open a Pull Request

Development Guidelines

  • Use TypeScript for all new code
  • Follow the existing code style and patterns
  • Add type definitions for all new APIs
  • Update documentation for new features
  • Test both CommonJS and ESM imports
  • Ensure cross-platform compatibility

πŸ“„ License

MIT License - see LICENSE for details.

πŸ—ΊοΈ Roadmap

v1.0 - Core Features

  • Interactive CLI with beautiful prompts
  • Conventional commit support
  • Emoji integration
  • Full TypeScript support
  • Dual module system (CJS/ESM)
  • AI provider infrastructure

v1.1 - Enhanced AI

  • Full OpenAI integration
  • Full Anthropic integration
  • Smart diff analysis
  • Context-aware suggestions

v1.2 - Advanced Features

  • Git hooks implementation
  • Configuration validation
  • Template system for custom formats
  • Plugin architecture

v1.3 - Developer Experience

  • Interactive configuration wizard
  • VS Code extension
  • GitHub Actions integration
  • Commit message templates

πŸ™ Acknowledgments

  • Conventional Commits - For the commit message standard
  • Inquirer.js/Enquirer - For beautiful CLI prompts
  • Chalk - For colorful terminal output
  • Simple Git - For Git operations
  • Zod - For runtime type validation

Made with ❀️ by TypeWeaver

npm β€’ GitHub β€’ Issues