Skip to content

Commit 74f37c1

Browse files
committed
feat(react-app): 替换 lefthook 为 husky
1 parent 5d6d857 commit 74f37c1

File tree

8 files changed

+62
-31
lines changed

8 files changed

+62
-31
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# commit-msg
2+
3+
# https://commitlint.js.org/guides/local-setup.html
4+
npx --no -- commitlint --edit $1
5+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# pre-commit
2+
3+
echo "node version = $(node -v)"
4+
echo "npm version = $(npm -v)"
5+
6+
# https://github.com/lint-staged/lint-staged?tab=readme-ov-file#command-line-flags
7+
npx lint-staged --allow-empty
8+
9+
# https://typicode.github.io/husky/get-started.html#scripting
10+
git update-index --again
11+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# pre-push
2+
3+
npm run build
4+
npm run lint
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @file .husky/prepare.mjs
3+
* @see https://typicode.github.io/husky/how-to.html#ci-server-and-docker
4+
*/
5+
6+
// Skip Husky install in production or CI
7+
if (process.env.NODE_ENV === 'production' || process.env.CI === 'true') {
8+
process.exit(0)
9+
}
10+
11+
const husky = (await import('husky')).default
12+
console.log(husky())

templates/react-app/lefthook.yml.ejs

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* lint-staged.config.mjs
3+
* @ref https://www.npmjs.com/package/lint-staged
4+
*/
5+
export default {
6+
<%_ if (codeLinter === 'biome') { _%>
7+
'*': [
8+
'biome check --write --no-errors-on-unmatched --files-ignore-unknown=true'
9+
],
10+
<%_ } else if (codeLinter === 'eslint') { _%>
11+
'*.{js,mjs,cjs,ts,mts,jsx,tsx}': [
12+
'prettier --write',
13+
'eslint --no-error-on-unmatched-pattern --no-warn-ignored --fix',
14+
],
15+
16+
'*.vue': [
17+
'prettier --write',
18+
'stylelint --fix --allow-empty-input',
19+
'eslint --no-error-on-unmatched-pattern --no-warn-ignored --fix',
20+
],
21+
<%_ } _%>
22+
23+
'*.{css,scss}': [
24+
'prettier --write',
25+
'stylelint --fix --allow-empty-input',
26+
],
27+
};

templates/react-app/package.json.ejs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"description": "A new React App - <%= ctx.projectName %>",
55
"scripts": {
6-
"prepare": "lefthook install",
6+
"prepare": "node .husky/prepare.mjs",
77
"openapi-axios": "openapi-axios",
88
<%_ if (codeLinter === 'biome') { _%>
99
"lint": "biome check && tsc --noEmit && stylelint '**/*.{css,scss}'",
@@ -53,7 +53,8 @@
5353
"@vitejs/plugin-react": "^4.3.4",
5454
"commit-and-tag-version": "^12.5.0",
5555
"cross-env": "^7.0.3",
56-
"lefthook": "^1.10.3",
56+
"husky": "^9.1.7",
57+
"lint-staged": "^16.0.0",
5758
"openapi-axios": "^0.34.0",
5859
"postcss": "^8.5.1",
5960
"sass-embedded": "^1.83.4",
File renamed without changes.

0 commit comments

Comments
 (0)