From b6a47acdde02d5bbf009da465e79006d7ac679dd Mon Sep 17 00:00:00 2001 From: wwsun Date: Fri, 22 Sep 2023 17:48:54 +0800 Subject: [PATCH] chore: add husky --- .husky/commit-msg | 4 ++++ .husky/pre-commit | 4 ++++ commitlint.config.js | 7 +++++++ package.json | 13 ++++++++++--- yarn.lock | 12 ++++++------ 5 files changed, 31 insertions(+), 9 deletions(-) create mode 100755 .husky/commit-msg create mode 100755 .husky/pre-commit create mode 100644 commitlint.config.js diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000..74363b9 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +yarn commitlint --edit "$1" \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..12ac302 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +yarn lint-staged --allow-empty diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..4d93b8e --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,7 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + rules: { + 'scope-case': [0], + 'subject-case': [0], + }, +}; diff --git a/package.json b/package.json index 73809fb..21a2ba4 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "ver": "lerna version --no-private --conventional-commits", "release": "yarn eslint && yarn build && yarn run ver && lerna publish from-git", "release:beta": "yarn eslint && yarn build && yarn run ver && lerna publish from-package --dist-tag beta", - "up": "yarn upgrade-interactive --latest" + "up": "yarn upgrade-interactive --latest", + "postinstall": "husky install" }, "devDependencies": { "@babel/preset-env": "^7.19.3", @@ -49,11 +50,11 @@ "eslint-plugin-react": "^7.33.2", "eslint-plugin-react-hooks": "^4.6.0", "http-server": "^14.1.0", - "husky": "^8.0.1", + "husky": "^8.0.3", "jest": "^29.1.1", "jest-environment-jsdom": "^29.1.1", "lerna": "^6.6.1", - "lint-staged": "^13.1.0", + "lint-staged": "^14.0.1", "prettier": "^2.8.7", "react": "^17.0.0", "react-dom": "^17.0.0", @@ -63,5 +64,11 @@ }, "resolutions": { "@yarnpkg/parsers": "3.0.0-rc.48.1" + }, + "lint-staged": { + "*.{js,jsx,ts,tsx}": [ + "eslint --fix", + "prettier --write" + ] } } diff --git a/yarn.lock b/yarn.lock index ab46982..53e1aef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11185,9 +11185,9 @@ humanize-ms@^1.2.1: dependencies: ms "^2.0.0" -husky@^8.0.1: +husky@^8.0.3: version "8.0.3" - resolved "https://registry.npmmirror.com/husky/-/husky-8.0.3.tgz" + resolved "https://registry.npmmirror.com/husky/-/husky-8.0.3.tgz#4936d7212e46d1dea28fef29bb3a108872cd9184" integrity sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg== iconv-lite@0.4.24, iconv-lite@^0.4.24: @@ -13043,10 +13043,10 @@ lines-and-columns@~2.0.3: resolved "https://registry.npmmirror.com/lines-and-columns/-/lines-and-columns-2.0.3.tgz" integrity sha512-cNOjgCnLB+FnvWWtyRTzmB3POJ+cXxTA81LoW7u8JdmhfXzriropYwpjShnz1QLLWsQwY7nIxoDmcPTwphDK9w== -lint-staged@^13.1.0: - version "13.3.0" - resolved "https://registry.npmmirror.com/lint-staged/-/lint-staged-13.3.0.tgz" - integrity sha512-mPRtrYnipYYv1FEE134ufbWpeggNTo+O/UPzngoaKzbzHAthvR55am+8GfHTnqNRQVRRrYQLGW9ZyUoD7DsBHQ== +lint-staged@^14.0.1: + version "14.0.1" + resolved "https://registry.npmmirror.com/lint-staged/-/lint-staged-14.0.1.tgz#57dfa3013a3d60762d9af5d9c83bdb51291a6232" + integrity sha512-Mw0cL6HXnHN1ag0mN/Dg4g6sr8uf8sn98w2Oc1ECtFto9tvRF7nkXGJRbx8gPlHyoR0pLyBr2lQHbWwmUHe1Sw== dependencies: chalk "5.3.0" commander "11.0.0"