diff --git a/package.json b/package.json index 167415f14..133166574 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "husky": { "hooks": { "pre-commit": "lint-staged", - "commit-msg": "node build/lint-commit-msg.js" + "commit-msg": "vant commit-lint" } }, "lint-staged": { @@ -70,7 +70,7 @@ "@babel/preset-env": "^7.5.5", "@babel/preset-typescript": "^7.3.3", "@types/jest": "^24.0.16", - "@vant/cli": "^0.1.1", + "@vant/cli": "^1.0.0", "@vant/doc": "^2.4.0", "@vant/eslint-config": "^1.2.4", "@vant/markdown-loader": "^2.2.0", diff --git a/packages/vant-cli/README.md b/packages/vant-cli/README.md index b1e84a2f3..761064a4c 100644 --- a/packages/vant-cli/README.md +++ b/packages/vant-cli/README.md @@ -21,3 +21,13 @@ yarn add @vant/cli --dev ```shell vant changelog ./name.md ``` + +#### Commit Lint + +```json +"husky": { + "hooks": { + "commit-msg": "vant commit-lint" + } +} +``` diff --git a/packages/vant-cli/package.json b/packages/vant-cli/package.json index 71faa9427..632928612 100644 --- a/packages/vant-cli/package.json +++ b/packages/vant-cli/package.json @@ -1,6 +1,6 @@ { "name": "@vant/cli", - "version": "0.1.1", + "version": "1.0.0", "description": "vant cli tools", "main": "./src/index.js", "bin": { diff --git a/build/lint-commit-msg.js b/packages/vant-cli/src/commit-lint.js similarity index 62% rename from build/lint-commit-msg.js rename to packages/vant-cli/src/commit-lint.js index 28c644a90..3c383b4f0 100644 --- a/build/lint-commit-msg.js +++ b/packages/vant-cli/src/commit-lint.js @@ -1,13 +1,14 @@ const fs = require('fs'); const signale = require('signale'); -const gitParams = process.env.HUSKY_GIT_PARAMS; -const commitMsg = fs.readFileSync(gitParams, 'utf-8').trim(); - const commitRE = /^(revert: )?(fix|feat|docs|perf|test|types|build|chore|refactor|breaking change)(\(.+\))?: .{1,50}/; -if (!commitRE.test(commitMsg)) { - signale.error(`Error: invalid commit message format. +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. @@ -30,5 +31,8 @@ Allowed Types: - refactor - breaking change `); - process.exit(1); + process.exit(1); + } } + +module.exports = commitLint; diff --git a/packages/vant-cli/src/index.js b/packages/vant-cli/src/index.js index 0fd9b3ab9..ddbce0c5c 100644 --- a/packages/vant-cli/src/index.js +++ b/packages/vant-cli/src/index.js @@ -2,10 +2,15 @@ const commander = require('commander'); const changelog = require('./changelog'); +const commitLint = require('./commit-lint'); commander .command('changelog