@sehaj23/commit-craft v1.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
npm install -g commit-craftLocal Installation (Recommended)
npm install --save-dev commit-craftThe hook will be automatically set up when you install the package! š
Usage
Automatic Setup
When you install CommitCraft, it automatically:
- ā Detects if you're using Husky or traditional Git hooks
- ā
Creates the appropriate
prepare-commit-msghook - ā Configures TTY redirection for interactive prompts
- ā 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-setupWith Husky
If you're using Husky for Git hooks:
- Install CommitCraft and Husky:
npm install --save-dev commit-craft husky- Initialize Husky (if not already done):
npx husky install- 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 $2Traditional 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 authenticationTroubleshooting
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 $2Hook Not Running
Check if the hook exists:
# For Husky ls -la .husky/prepare-commit-msg # For Git hooks ls -la .git/hooks/prepare-commit-msgEnsure it's executable:
chmod +x .husky/prepare-commit-msg # or chmod +x .git/hooks/prepare-commit-msgRe-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 messagescommit-craft-setup: Manual setup command for hooks
Development
Building
npm run buildDevelopment Mode
npm run devTesting
# 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.txtLicense
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)