Browse Source

build: 使用 commitizen 规范 git 提交信息

zhaihaoyi 6 years ago
parent
commit
b58faa7399
3 changed files with 283 additions and 263 deletions
  1. 14 5
      package.json
  2. 17 0
      scripts/verify-commit-msg.js
  3. 252 258
      yarn.lock

+ 14 - 5
package.json

@@ -19,15 +19,16 @@
   },
   "main": "dist/lib/vue-router-tab.umd.min.js",
   "scripts": {
-    "docs:dev": "vuepress dev docs",
-    "docs:build": "vuepress build docs",
     "demo:dev": "vue-cli-service serve",
     "demo:build": "vue-cli-service build",
+    "docs:dev": "vuepress dev docs",
+    "docs:build": "vuepress build docs",
     "lib:build": "vue-cli-service build --target lib --dest dist/lib ./src/lib/RouterTab/index.js",
     "lib:build:report": "vue-cli-service build --report --target lib --dest dist/lib ./src/lib/RouterTab/index.js",
     "lib:publish": "npm run lib:build && npm publish",
     "lint": "vue-cli-service lint",
-    "lint:fix": "vue-cli-service lint --fix"
+    "lint:fix": "vue-cli-service lint --fix",
+    "commit": "git-cz"
   },
   "dependencies": {
     "vue": "^2.5.22",
@@ -41,13 +42,15 @@
     "@vuepress/plugin-back-to-top": "^1.0.0-alpha.42",
     "@vuepress/plugin-pwa": "^1.0.0-alpha.43",
     "babel-eslint": "^10.0.1",
+    "cz-conventional-changelog": "^2.1.0",
     "eslint": "^5.8.0",
     "eslint-plugin-vue": "^5.0.0",
     "lint-staged": "^8.1.0",
     "node-sass": "^4.9.0",
     "sass-loader": "^7.1.0",
     "vue-template-compiler": "^2.5.22",
-    "vuepress": "^1.0.0-alpha.42"
+    "vuepress": "^1.0.0-alpha.42",
+    "yorkie": "^2.0.0"
   },
   "eslintConfig": {
     "root": true,
@@ -77,7 +80,8 @@
     "not ie <= 8"
   ],
   "gitHooks": {
-    "pre-commit": "lint-staged"
+    "pre-commit": "lint-staged",
+    "commit-msg": "node scripts/verify-commit-msg.js"
   },
   "lint-staged": {
     "*.js": [
@@ -88,5 +92,10 @@
       "vue-cli-service lint",
       "git add"
     ]
+  },
+  "config": {
+    "commitizen": {
+      "path": "./node_modules/cz-conventional-changelog"
+    }
   }
 }

+ 17 - 0
scripts/verify-commit-msg.js

@@ -0,0 +1,17 @@
+const chalk = require('chalk')
+const msgPath = process.env.GIT_PARAMS
+const msg = require('fs').readFileSync(msgPath, 'utf-8').trim()
+
+const commitRE = /^(revert: )?(feat|fix|polish|docs|style|refactor|perf|test|workflow|ci|chore|types|build)(\(.+\))?: .{1,50}/
+
+if (!commitRE.test(msg)) {
+  console.log()
+  console.error(
+    `  ${chalk.bgRed.white(' ERROR ')} ${chalk.red(`invalid commit message format.`)}\n\n` +
+    chalk.red(`  Proper commit message format is required for automated changelog generation. Examples:\n\n`) +
+    `    ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
+    `    ${chalk.green(`fix(v-model): handle events on blur (close #28)`)}\n\n` +
+    chalk.red(`  You can also use ${chalk.cyan(`npm run commit`)} to interactively generate a commit message.\n`)
+  )
+  process.exit(1)
+}

File diff suppressed because it is too large
+ 252 - 258
yarn.lock


Some files were not shown because too many files changed in this diff