Browse Source

feat: add pre-commit hook

yangkaixuan 5 years ago
parent
commit
242b4b829d
2 changed files with 13 additions and 1 deletions
  1. 1 1
      package.json
  2. 12 0
      scripts/verifymail.js

+ 1 - 1
package.json

@@ -35,7 +35,7 @@
   },
   "husky": {
     "hooks": {
-      "pre-commit": "lint-staged",
+      "pre-commit": "node ./scripts/verifymail.js && lint-staged",
       "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
     }
   },

+ 12 - 0
scripts/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);
+}