mirror of
https://github.com/youzan/vant.git
synced 2025-10-15 23:55:08 +00:00
chore: move commit-lint to cli
This commit is contained in:
@@ -21,3 +21,13 @@ yarn add @vant/cli --dev
|
||||
```shell
|
||||
vant changelog ./name.md
|
||||
```
|
||||
|
||||
#### Commit Lint
|
||||
|
||||
```json
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"commit-msg": "vant commit-lint"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vant/cli",
|
||||
"version": "0.1.1",
|
||||
"version": "1.0.0",
|
||||
"description": "vant cli tools",
|
||||
"main": "./src/index.js",
|
||||
"bin": {
|
||||
|
38
packages/vant-cli/src/commit-lint.js
Normal file
38
packages/vant-cli/src/commit-lint.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const fs = require('fs');
|
||||
const signale = require('signale');
|
||||
|
||||
const commitRE = /^(revert: )?(fix|feat|docs|perf|test|types|build|chore|refactor|breaking change)(\(.+\))?: .{1,50}/;
|
||||
|
||||
function commitLint() {
|
||||
const gitParams = process.env.HUSKY_GIT_PARAMS;
|
||||
const commitMsg = fs.readFileSync(gitParams, 'utf-8').trim();
|
||||
|
||||
if (!commitRE.test(commitMsg)) {
|
||||
signale.error(`Error: invalid commit message format.
|
||||
|
||||
Proper commit message format is required for automated changelog generation.
|
||||
|
||||
Examples:
|
||||
|
||||
- fix(Button): incorrect style
|
||||
- feat(Button): incorrect style
|
||||
- docs(Button): fix typo
|
||||
|
||||
Allowed Types:
|
||||
|
||||
- fix
|
||||
- feat
|
||||
- docs
|
||||
- perf
|
||||
- test
|
||||
- types
|
||||
- build
|
||||
- chore
|
||||
- refactor
|
||||
- breaking change
|
||||
`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = commitLint;
|
@@ -2,10 +2,15 @@
|
||||
|
||||
const commander = require('commander');
|
||||
const changelog = require('./changelog');
|
||||
const commitLint = require('./commit-lint');
|
||||
|
||||
commander
|
||||
.command('changelog <dir>')
|
||||
.option('--tag [tag]', 'Since tag')
|
||||
.action(changelog);
|
||||
|
||||
commander
|
||||
.command('commit-lint')
|
||||
.action(commitLint);
|
||||
|
||||
commander.parse(process.argv);
|
||||
|
Reference in New Issue
Block a user