ソースを参照

feat: email check and commit config

richard1015 5 年 前
コミット
e9223031ef
5 ファイル変更43 行追加3 行削除
  1. 1 1
      .gitignore
  2. 1 1
      .prettierrc
  3. 15 0
      commitlint.config.js
  4. 12 0
      jd/verifymail.js
  5. 14 1
      package.json

+ 1 - 1
.gitignore

@@ -2,7 +2,7 @@
 node_modules
 /dist
 /libs
-/jd
+/jd/upload.js
 yarn.lock
 package.lock
 

+ 1 - 1
.prettierrc

@@ -1,6 +1,6 @@
 {
   "singleQuote": true,
-  "semi": true,
+  "semi": false,
   "bracketSpacing": true,
   "tabWidth": 2,
   "printWidth": 150,

+ 15 - 0
commitlint.config.js

@@ -0,0 +1,15 @@
+module.exports = {
+  extends: ['@commitlint/config-conventional'],
+  rules: {
+    'body-leading-blank': [1, 'always'],
+    'footer-leading-blank': [1, 'always'],
+    'header-max-length': [2, 'always', 72],
+    'scope-case': [2, 'always', 'lower-case'],
+    'subject-case': [2, 'never', ['sentence-case', 'start-case', 'pascal-case', 'upper-case']],
+    'subject-empty': [2, 'never'],
+    'subject-full-stop': [2, 'never', '.'],
+    'type-case': [2, 'always', 'lower-case'],
+    'type-empty': [2, 'never'],
+    'type-enum': [2, 'always', ['upd', 'chore', 'docs', 'feat', 'fix', 'test', 'refactor', 'revert', 'style']]
+  }
+}

+ 12 - 0
jd/verifymail.js

@@ -0,0 +1,12 @@
+#!/usr/bin/env node
+const { execSync } = require('child_process')
+
+const stdout = execSync('git config user.email').toString()
+
+if (stdout && /@jd.com$/gi.test(stdout.replace(/^\s+|\s+$/g, ''))) {
+  console.log('\x1B[31m%s\x1B[39m', 'ERROR:', '不能使用京东企业邮箱提交,请设置个人GitHub邮箱')
+  console.log('提示: git config user.email xxxxxxxx@xx.com')
+  process.exit(1)
+} else {
+  process.exit(0)
+}

+ 14 - 1
package.json

@@ -44,6 +44,8 @@
     "vue-router": "^4.0.0-0"
   },
   "devDependencies": {
+    "@commitlint/cli": "^11.0.0",
+    "@commitlint/config-conventional": "^11.0.0",
     "@typescript-eslint/eslint-plugin": "^2.33.0",
     "@typescript-eslint/parser": "^2.33.0",
     "@vue/cli-plugin-babel": "~4.5.0",
@@ -57,6 +59,8 @@
     "eslint": "^6.7.2",
     "eslint-plugin-prettier": "^3.1.3",
     "eslint-plugin-vue": "^7.0.0-0",
+    "husky": "^4.3.0",
+    "lint-staged": "^10.5.0",
     "prettier": "^1.19.1",
     "typescript": "~3.9.3"
   },
@@ -81,6 +85,15 @@
       "no-console": "off"
     }
   },
+  "husky": {
+    "hooks": {
+      "pre-commit": "node ./jd/verifymail.js && lint-staged",
+      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
+    }
+  },
+  "lint-staged": {
+    "*.{ts,js,vue,scss}": "prettier --write"
+  },
   "repository": {
     "type": "git",
     "url": "https://github.com/jdf2e/nutui.git"
@@ -90,4 +103,4 @@
     "last 2 versions",
     "not dead"
   ]
-}
+}