From fc111cdfc7bde65fa2f14d190751de5d24c43218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Thu, 22 Aug 2019 14:01:53 +0800 Subject: [PATCH] chore: move commit-lint to cli --- package.json | 4 ++-- packages/vant-cli/README.md | 10 ++++++++++ packages/vant-cli/package.json | 2 +- .../vant-cli/src/commit-lint.js | 16 ++++++++++------ packages/vant-cli/src/index.js | 5 +++++ yarn.lock | 8 ++++---- 6 files changed, 32 insertions(+), 13 deletions(-) rename build/lint-commit-msg.js => packages/vant-cli/src/commit-lint.js (62%) 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 ') .option('--tag [tag]', 'Since tag') .action(changelog); +commander + .command('commit-lint') + .action(commitLint); + commander.parse(process.argv); diff --git a/yarn.lock b/yarn.lock index 90e943009..95a0ebc51 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1202,10 +1202,10 @@ lodash.unescape "4.0.1" semver "5.5.0" -"@vant/cli@^0.1.1": - version "0.1.1" - resolved "https://registry.yarnpkg.com/@vant/cli/-/cli-0.1.1.tgz#d3513aa74b66bb3654d461198fd2b897ff155530" - integrity sha512-C7i4cVM5dCjcV6IgHhqwpdB/igGHL4/Dpxl50uyGk5Ac34E51iIUwgMXrA6xSjrtuwXW4yfwww9oNp92Vq/WqA== +"@vant/cli@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@vant/cli/-/cli-1.0.0.tgz#7ea529a94afb69fe945869e871b3bb87fcba0cfc" + integrity sha512-4gW8mQBVxXOeuBDnA5eKN7dd9hWHS+1fmbyIiFJqq5u0BXtkIi1Lz4ggLJBOpSu8hjx1PlDDEZariwhjqDYXxw== dependencies: commander "^2.17.1" shelljs "^0.8.2"