A unified conventional commit message linter with presets and easy project integration
Package Exports
@ttvuong/conventional-commit
Readme
@hemidi/conventional-commit
Gói Conventional Commit linter và interactive CLI cho các dự án JavaScript/TypeScript.
Giới thiệu
@hemidi/conventional-commit là một công cụ toàn diện để áp dụng và kiểm tra conventional commit messages trong dự án của bạn. Package này cung cấp cả chức năng linting và interactive commit builder.
Tính năng chính
Commit Linting: Kiểm tra commit messages theo quy tắc conventional commits
Interactive Mode: Xây dựng commit messages một cách tương tác
Git Hooks: Tự động validate commits với Husky integration
Multiple Presets: Hỗ trợ nhiều preset configurations
CI/CD Ready: Tích hợp dễ dàng với CI/CD pipelines
Customizable Rules: Tùy chỉnh rules theo nhu cầu dự án
Auto-initialization: Tự động setup hooks và configurations
Cài đặt
npm i -D @hemidi/conventional-commit husky commitizen
Bắt đầu nhanh
Bước 1: Khởi tạo project
npx midi-cz init
Lệnh này sẽ:
Thêm scripts vào package.json
Cài đặt git hooks với Husky
Tạo commitlint configuration file
Bước 2: Sử dụng interactive commit
npm run commit
Bước 3: Kiểm tra commits
npm run commit:check # Kiểm tra commit cuốinpm run commit:all # Kiểm tra tất cả commits từ development
Tham chiếu Scripts
Scripts cơ bản
Script
Mô tả
Mode
Output
commit
Interactive commit builder
interactive
Git commit
commit:check
Kiểm tra commit message cuối
check
Console output
commit:all
Kiểm tra tất cả commits từ development
check
Console output
Scripts được tạo tự động
Khi chạy npx midi-cz init, các scripts sau sẽ được thêm vào package.json:
# Tạo commit với interactive modenpm run commit
# Kiểm tra commit vừa tạonpm run commit:check
# Kiểm tra nhiều commits
npx midi-cz --from origin/development --to HEAD
Before push
# Kiểm tra tất cả commits localnpm run commit:all
CI/CD Pipeline
# CI mode với JSON output
npx midi-cz --check--format json --quiet# Kiểm tra PR commits
npx midi-cz --from origin/development --to HEAD
Custom validation
# Sử dụng custom config
npx midi-cz --config ./custom-commitlint.config.js
# Kiểm tra với specific preset
npx midi-cz --preset @company/commitlint-config
Conventional Commit Format
Cấu trúc cơ bản
<type>(<scope>): <subject>
<body>
<footer>
Types được hỗ trợ
Type
Mô tả
Ví dụ
feat
Tính năng mới
feat: add user authentication
fix
Sửa lỗi
fix: resolve login issue
docs
Thay đổi documentation
docs: update API guide
style
Code style (không ảnh hưởng logic)
style: format code
refactor
Refactor code
refactor: improve performance
perf
Cải thiện performance
perf: optimize query
test
Thêm/sửa tests
test: add unit tests
build
Build system changes
build: update webpack config
ci
CI/CD changes
ci: add GitHub Actions
chore
Maintenance tasks
chore: update dependencies
revert
Revert commit
revert: revert commit abc123
Ví dụ commit messages
Simple commit
feat: add user profile page
With scope
fix(auth): resolve token expiration issue
With body
feat(api): implement pagination for users endpoint
Add limit and offset parameters to GET /users
Default limit is 20, maximum is 100
Breaking change
feat!: update API response format
BREAKING CHANGE: API responses now use camelCase instead of snake_case
With footer references
fix(ui): correct button alignment in header
The submit button was misaligned on mobile devices
due to incorrect flexbox properties.
Fixes #123
Closes #456
$ npm run commit:check
[midi-cz] Checking commit messages...
✅ feat: add user authentication
Check mode - Failed
$ npm run commit:check
[midi-cz] Checking commit messages...
❌ Add new feature
Type is required (e.g., feat, fix, docs)
Subject must be in lower-case
JSON format output
[{"message":"feat: add login feature","valid":true,"errors":[],"warnings":[]},{"message":"WIP: working on dashboard","valid":false,"errors":["Type must be one of: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"],"warnings":[]}]
Troubleshooting
Common Issues
Husky hooks not working
# Re-install huskynpm run prepare
# Verify hook existsls-la .husky/commit-msg
Commitizen not found
# Install commitizen and adapternpm i -D commitizen cz-conventional-changelog
B1: Vào thư mục conventional-commit, cài đặt dependencies và kiểm tra authentication với npm registry
cd packages/ci/conventional-commit &&npminstallnpmwhoami# Nếu chưa đăng nhập, chạy lệnh:npm login
B2: Cần thay đổi các thông tin cần thiết trong file package.json nếu cần
{"name":"@hemidi/conventional-commit",// <- Thay đổi tên package nếu cần"version":"1.0.0",// <- Thay đổi version"description":"Conventional commit..."// <- Thay đổi mô tả}
B3: Quản lý version của package
# examplenpm version patch # 1.0.1npm version minor # 1.1.0npm version major # 2.0.0