npm package: @sehaj23/commit-craft
Description: A Git hook utility for formatting commit messages with conventional commit types
Latest version: 1.0.1

# 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

```bash
npm install -g commit-craft
```

### Local Installation (Recommended)

```bash
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:

```bash
# Run the setup command
npx commit-craft-setup
```

### With Husky

If you're using Husky for Git hooks:

1. Install CommitCraft and Husky:
```bash
npm install --save-dev commit-craft husky
```

2. Initialize Husky (if not already done):
```bash
npx husky install
```

3. The hook will be automatically created, or you can create it manually:
```bash
npx husky add .husky/prepare-commit-msg "exec < /dev/tty && npx commit-craft \$1 \$2"
```

Your `.husky/prepare-commit-msg` file should look like:
```bash
#!/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`:

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

### Manual Usage

You can also use CommitCraft manually:

```bash
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:

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

### Hook Not Running

1. Check if the hook exists:
   ```bash
   # For Husky
   ls -la .husky/prepare-commit-msg
   
   # For Git hooks
   ls -la .git/hooks/prepare-commit-msg
   ```

2. Ensure it's executable:
   ```bash
   chmod +x .husky/prepare-commit-msg
   # or
   chmod +x .git/hooks/prepare-commit-msg
   ```

3. Re-run setup:
   ```bash
   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:

```json
{
  "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:

```bash
# 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

```bash
npm run build
```

### Development Mode

```bash
npm run dev
```

### Testing

```bash
# 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)