Command-line interface for @umijs/fabric providing git commit message validation and package information utilities.
The main fabric command provides access to validation tools and package information.
# Main command structure
fabric [command] [options]
# Available commands:
fabric verify-commit # Validate git commit messages
fabric --version # Display package version and local development status
fabric --help # Show help information and available commandsValidates git commit messages against conventional commit standards with emoji support.
/**
* Validates git commit messages according to conventional commit format
* Used in git hooks to enforce consistent commit message patterns
*
* Usage: fabric verify-commit
* Environment: Requires GIT_PARAMS or HUSKY_GIT_PARAMS environment variable
*/
fabric verify-commitValidation Rules:
The commit message must match this pattern:
/^(((\ud83c[\udf00-\udfff])|(\ud83d[\udc00-\ude4f\ude80-\udeff])|[\u2600-\u2B55]) )?(revert: )?(feat|fix|docs|UI|refactor|perf|workflow|build|CI|typos|chore|tests|types|wip|release|dep|locale)(\(.+\))?: .{1,50}/Supported Commit Types:
/**
* Valid commit types for conventional commits
*/
type CommitType =
| 'feat' // New feature
| 'fix' // Bug fix
| 'docs' // Documentation changes
| 'UI' // User interface changes
| 'refactor' // Code refactoring
| 'perf' // Performance improvements
| 'workflow' // Workflow changes
| 'build' // Build system changes
| 'CI' // Continuous integration changes
| 'typos' // Typography fixes
| 'chore' // Maintenance tasks
| 'tests' // Test additions or modifications
| 'types' // Type definition changes
| 'wip' // Work in progress
| 'release' // Release commits
| 'dep' // Dependency updates
| 'locale'; // Internationalization changes
/**
* Optional commit message components
*/
interface CommitMessageFormat {
/** Optional emoji prefix */
emoji?: string;
/** Optional revert prefix */
revert?: 'revert: ';
/** Required commit type */
type: CommitType;
/** Optional scope in parentheses */
scope?: string;
/** Required description (1-50 characters) */
description: string;
}Valid Commit Examples:
# Basic commits
feat: add user authentication
fix: resolve login validation bug
docs: update API documentation
# With scope
feat(auth): add OAuth2 integration
fix(ui): correct button alignment issues
perf(api): optimize database queries
# With emoji
💥 feat: add new payment system
🐛 fix: resolve memory leak in worker
📝 docs: add contribution guidelines
# With emoji and scope
🌷 UI(components): improve button styling
🏰 chore(deps): update development dependencies
🌐 locale(i18n): add French translations
# Revert commits
revert: feat: add experimental feature
revert: 🐛 fix: temporary workaroundDisplay package version and development status.
/**
* Display package version information
* Shows version number and local development indicator if present
*
* Usage: fabric --version | fabric -v
*/
fabric --version
fabric -vOutput Format:
4.0.1
@local # Only shown if .local file exists in package directoryDisplay available commands and usage examples.
/**
* Show help information with available commands and examples
*
* Usage: fabric --help | fabric -h
*/
fabric --help
fabric -hHelp Output:
Commands:
verify-commit 检查 commit 提交的信息
Examples:
fabric
fabric -h
verify-commit
fabric verify-commitNode.js version compatibility checking.
/**
* Minimum Node.js version requirement
* CLI will exit with error if Node.js version is below requirement
*/
const MIN_NODE_VERSION = '>= 8.0.0';
/**
* Version check performed on CLI startup
* @param {string} processVersion - Current Node.js version (process.version)
* @returns {boolean} True if version meets requirements
*/
function checkNodeVersion(processVersion: string): boolean;Configuration through environment variables.
/**
* Git hook parameters for commit message validation
* Contains path to the commit message file
*/
interface GitHookEnvironment {
/** Git parameters (legacy) */
GIT_PARAMS?: string;
/** Husky git parameters (modern) */
HUSKY_GIT_PARAMS?: string;
}Comprehensive error messages with internationalization support.
/**
* Error message localization based on system locale
* Supports Chinese (zh-CN) and English (default) error messages
*/
interface ErrorMessages {
/** System locale detection */
locale: 'zh-CN' | 'en-US' | string;
/** Localized error message for invalid commit format */
invalidCommitMessage: string;
/** Examples of valid commit messages */
validExamples: string[];
/** Reference to commit convention documentation */
documentationLink: string;
}Chinese Error Messages:
提交日志不符合规范
合法的提交日志格式如下(emoji 和 模块可选填):
💥 feat(模块): 添加了个很棒的功能
🐛 fix(模块): 修复了一些 bug
📝 docs(模块): 更新了一下文档
🌷 UI(模块): 修改了一下样式
🏰 chore(模块): 对脚手架做了些更改
🌐 locale(模块): 为国际化做了微小的贡献
其他提交类型: refactor, perf, workflow, build, CI, typos, tests, types, wip, release, depEnglish Error Messages:
invalid commit message format.
Proper commit message format is required for automated changelog generation. Examples:
💥 feat(compiler): add 'comments' option
🐛 fix(compiler): fix some bug
📝 docs(compiler): add some docs
🌷 UI(compiler): better styles
🏰 chore(compiler): Made some changes to the scaffolding
🌐 locale(compiler): Made a small contribution to internationalization
Other commit types: refactor, perf, workflow, build, CI, typos, tests, types, wip, release, depIntegration with popular git hook tools.
Husky Integration:
// package.json
{
"husky": {
"hooks": {
"commit-msg": "fabric verify-commit"
}
}
}lint-staged Integration:
// package.json
{
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix",
"git add"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "fabric verify-commit"
}
}
}Simple git hooks Integration:
#!/bin/sh
# .git/hooks/commit-msg
# Validate commit message format
fabric verify-commit
# Exit with non-zero code if validation fails
if [ $? -ne 0 ]; then
exit 1
fiBasic Git Hook Setup:
# Install the package
npm install @umijs/fabric --save-dev
# Add to package.json scripts
npm pkg set scripts.commit-lint="fabric verify-commit"
# Use with husky
npx husky add .husky/commit-msg "npm run commit-lint"Manual Validation:
# Validate current commit message
echo "feat: add new feature" | GIT_PARAMS=/dev/stdin fabric verify-commit
# Check version
fabric --version
# Get help
fabric --helpCI/CD Integration:
# .github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install dependencies
run: npm ci
- name: Validate commit messages
run: |
# Validate all commit messages in PR
for commit in $(git rev-list origin/main..HEAD); do
git log --format=%B -n 1 $commit | GIT_PARAMS=/dev/stdin fabric verify-commit
done