Browse Source

feat: add husky

xyh 2 years ago
parent
commit
61a14ceae1
7 changed files with 714 additions and 21 deletions
  1. 4 0
      .husky/commit-msg
  2. 4 0
      .husky/pre-commit
  3. 7 4
      .stylelintignore
  4. 29 0
      commitlint.config.cjs
  5. 20 1
      package.json
  6. 638 12
      pnpm-lock.yaml
  7. 12 4
      tsconfig.json

+ 4 - 0
.husky/commit-msg

@@ -0,0 +1,4 @@
+#!/usr/bin/env sh
+. "$(dirname -- "$0")/_/husky.sh"
+
+npx --no-install commitlint --edit 

+ 4 - 0
.husky/pre-commit

@@ -0,0 +1,4 @@
+#!/usr/bin/env sh
+. "$(dirname -- "$0")/_/husky.sh"
+
+pnpm pre-commit

+ 7 - 4
.stylelintignore

@@ -1,7 +1,10 @@
+/build
 *.js
-*.ts
 *.jsx
 *.tsx
-node_modules
-build
-coverage
+*.ts
+*.html
+*.json
+*.md
+/node_modules
+**/assets/*

+ 29 - 0
commitlint.config.cjs

@@ -0,0 +1,29 @@
+module.exports = {
+  extends: ['@commitlint/config-conventional'],
+  rules: {
+    'type-enum': [
+      2,
+      'always',
+      [
+        'feat', // new function
+        'fix', // fix the problem
+        'style', // modify code format
+        'refactor', // refactor code
+        'test', // add test
+        'perf', // performance optimization
+        'chore', // adding or removing dependencies, tools
+        'update', // update code
+        'revert',
+        'merge',
+        'build',
+      ],
+    ],
+    'type-case': [0],
+    'type-empty': [0],
+    'scope-empty': [0],
+    'scope-case': [0],
+    'subject-full-stop': [0, 'never'],
+    'subject-case': [0, 'never'],
+    'header-max-length': [0, 'always', 72],
+  },
+};

+ 20 - 1
package.json

@@ -24,9 +24,19 @@
     "test:watch": "pnpm -F app test:watch",
     "test:coverage": "pnpm -F app test:coverage",
     "cypress": "cypress open",
-    "cypress:run": "cypress run -b chrome"
+    "cypress:run": "cypress run -b chrome",
+    "lint:style": "stylelint packages/app/src *.*.css",
+    "lint:js": "eslint . --ext .js,.jsx,.ts,.tsx",
+    "lint:style-fix": "pnpm run lint:style --fix",
+    "lint:js-fix": "pnpm run lint:script --fix",
+    "prettier": "prettier -c --write **/*",
+    "prepare": "husky install",
+    "postinstall": "husky install",
+    "pre-commit": "lint-staged"
   },
   "devDependencies": {
+    "@commitlint/cli": "^17.5.1",
+    "@commitlint/config-conventional": "^17.4.4",
     "@types/jest": "^29.2.5",
     "@types/node": "^18.11.18",
     "@typescript-eslint/eslint-plugin": "^5.46.1",
@@ -40,8 +50,10 @@
     "eslint-plugin-jest": "^27.1.6",
     "eslint-plugin-react": "^7.32.2",
     "eslint-plugin-react-hooks": "^4.6.0",
+    "husky": "^8.0.3",
     "ip": "^1.1.8",
     "jest": "^29.3.1",
+    "lint-staged": "^13.2.1",
     "postcss": "^8.4.19",
     "prettier": "^2.8.6",
     "stylelint": "^15.3.0",
@@ -51,5 +63,12 @@
   },
   "dependencies": {
     "cypress": "^12.5.1"
+  },
+  "lint-staged": {
+    "**/*.css": "pnpm lint:style",
+    "**/*.{js,jsx,ts,tsx}": "pnpm lint:js",
+    "**/*.{js,jsx,ts,tsx,css}": [
+      "prettier --write"
+    ]
   }
 }

File diff suppressed because it is too large
+ 638 - 12
pnpm-lock.yaml


+ 12 - 4
tsconfig.json

@@ -1,7 +1,11 @@
 {
   "compilerOptions": {
     "target": "ESNext",
-    "lib": ["dom", "dom.iterable", "esnext"],
+    "lib": [
+      "dom",
+      "dom.iterable",
+      "esnext"
+    ],
     "strictNullChecks": true,
     "allowJs": true,
     "skipLibCheck": true,
@@ -18,13 +22,17 @@
     "jsx": "react-jsx"
   },
   "extends": "./tsconfig.paths.json",
-  "exclude": ["node_modules", "cypress.config.ts"],
+  "exclude": [
+    "node_modules",
+    "cypress.config.ts"
+  ],
   "include": [
     "packages/app/src",
     "packages/app/__tests__",
     "packages/webpack/bin",
     "packages/webpack/scripts",
     "packages/webpack/config",
-    ".eslintrc.cjs"
+    ".eslintrc.cjs",
+    "./commitlint.config.cjs"
   ]
-}
+}