1.0.1 • Published 7 months ago

@sehaj23/commit-craft v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

CommitCraft

A Git hook utility for formatting commit messages with conventional commit types. This tool helps you maintain consistent commit message formatting by prompting you to select a commit type and automatically prefixing your commit messages.

Features

  • šŸŽÆ Interactive commit type selection
  • ✨ Beautiful emoji-enhanced commit types
  • šŸš€ Conventional Commits standard compliance
  • šŸ”„ Automatic merge commit detection and skipping
  • 🚪 Easy commit abortion option
  • šŸ• Husky integration support
  • šŸ”§ Automatic hook setup on installation
  • šŸ’» Works in both traditional Git hooks and Husky

Installation

Global Installation

npm install -g commit-craft

Local Installation (Recommended)

npm install --save-dev commit-craft

The hook will be automatically set up when you install the package! šŸŽ‰

Usage

Automatic Setup

When you install CommitCraft, it automatically:

  1. āœ… Detects if you're using Husky or traditional Git hooks
  2. āœ… Creates the appropriate prepare-commit-msg hook
  3. āœ… Configures TTY redirection for interactive prompts
  4. āœ… Makes the hook executable

You should see output like:

šŸ” Setting up CommitCraft in: /path/to/your/project
šŸ” Husky detected: true
šŸ“ Creating Husky hook at: /path/to/your/project/.husky/prepare-commit-msg
āœ… Husky prepare-commit-msg hook created successfully!
šŸŽ‰ CommitCraft is ready to use! Try making a commit.

Manual Setup (if needed)

If automatic setup doesn't work, you can set up manually:

# Run the setup command
npx commit-craft-setup

With Husky

If you're using Husky for Git hooks:

  1. Install CommitCraft and Husky:
npm install --save-dev commit-craft husky
  1. Initialize Husky (if not already done):
npx husky install
  1. The hook will be automatically created, or you can create it manually:
npx husky add .husky/prepare-commit-msg "exec < /dev/tty && npx commit-craft \$1 \$2"

Your .husky/prepare-commit-msg file should look like:

#!/usr/bin/env sh
exec < /dev/tty && npx commit-craft $1 $2

Traditional Git Hooks

For traditional Git hooks, the hook will be automatically created at .git/hooks/prepare-commit-msg:

#!/bin/sh
exec < /dev/tty && npx commit-craft "$1" "$2"

Manual Usage

You can also use CommitCraft manually:

commit-craft <commit-file-path> [commit-source]

Commit Types

CommitCraft supports the following conventional commit types:

  • ✨ feat: A new feature
  • šŸ› fix: A bug fix
  • šŸ“ docs: Documentation only changes
  • šŸ’„ style: Changes that do not affect the meaning of the code
  • ā™»ļø refactor: A code change that neither fixes a bug nor adds a feature
  • āœ… test: Adding missing tests or correcting existing tests
  • šŸ”§ chore: Changes to the build process or auxiliary tools

Example

When you make a commit, CommitCraft will prompt you:

? Choose a commit type: (Use arrow keys)
āÆ ✨ feat
  šŸ› fix
  šŸ“ docs
  šŸ’„ style
  ā™»ļø refactor
  āœ… test
  šŸ”§ chore
  ────────────────
  🚪 Exit (abort commit)

Your commit message will be automatically formatted:

Original: "add user authentication"
Result: "feat: add user authentication"
āœ… Commit message formatted: feat: add user authentication

Troubleshooting

Interactive Prompt Not Working

If the prompt appears but doesn't wait for your input, the hook might be missing TTY redirection. Ensure your hook includes:

exec < /dev/tty && npx commit-craft $1 $2

Hook Not Running

  1. Check if the hook exists:

    # For Husky
    ls -la .husky/prepare-commit-msg
    
    # For Git hooks
    ls -la .git/hooks/prepare-commit-msg
  2. Ensure it's executable:

    chmod +x .husky/prepare-commit-msg
    # or
    chmod +x .git/hooks/prepare-commit-msg
  3. Re-run setup:

    npx commit-craft-setup

Husky Deprecation Warnings

If you see Husky deprecation warnings, update your hook to use the modern format (without the deprecated husky.sh sourcing). CommitCraft automatically creates hooks in the correct format.

Integration Examples

Complete Husky Setup

Here's a complete example of integrating CommitCraft with other common tools:

{
  "scripts": {
    "prepare": "husky install"
  },
  "devDependencies": {
    "commit-craft": "^1.0.0",
    "husky": "^8.0.0",
    "lint-staged": "^13.0.0"
  }
}

Husky hooks:

  • .husky/pre-commit: npx lint-staged
  • .husky/prepare-commit-msg: exec < /dev/tty && npx commit-craft $1 $2

With Commitizen Alternative

CommitCraft can be used as a lightweight alternative to Commitizen for teams that prefer a simpler setup with automatic installation.

Local Development

Installing from Local Path

To install CommitCraft from a local directory in another project:

# Install as dev dependency from local path
npm install --save-dev /path/to/CommitCraft

# The hook will be automatically set up!

Available Commands

  • commit-craft: Main command for formatting commit messages
  • commit-craft-setup: Manual setup command for hooks

Development

Building

npm run build

Development Mode

npm run dev

Testing

# Test the setup script
npm run build
node dist/setup.js

# Test the main script
echo "test message" > test-commit.txt
node dist/index.js test-commit.txt
cat test-commit.txt

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Changelog

v1.0.0

  • ✨ Initial release
  • šŸŽÆ Interactive commit type selection
  • šŸ• Husky integration support
  • šŸ”§ Automatic hook setup
  • šŸ’» TTY redirection for proper interactive prompts
  • šŸš€ Modern Husky format (no deprecation warnings)
1.0.1

7 months ago

1.0.0

7 months ago