nsbp-cli 0.2.27 → 0.2.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/nsbp.js +97 -74
- package/package.json +1 -1
- package/templates/basic/.husky/README.md +47 -0
- package/templates/basic/.husky/commit-msg +17 -0
- package/templates/basic/.husky/pre-commit +4 -0
- package/templates/basic/.husky/pre-push +4 -0
- package/templates/basic/.prettierrc.js +13 -0
- package/templates/basic/README.md +43 -0
- package/templates/basic/docs/DEVELOPMENT_GUIDE.md +290 -0
- package/templates/basic/docs/ESLINT_AND_PRETTIER.md +184 -0
- package/templates/basic/docs/HUSKY_9_UPGRADE.md +76 -0
- package/templates/basic/docs/HUSKY_ESLINT_SETUP.md +293 -0
- package/templates/basic/docs/SETUP_GIT_HOOKS.md +106 -0
- package/templates/basic/eslint.config.js +98 -0
- package/templates/basic/gitignore +3 -0
- package/templates/basic/package.json +27 -3
- package/templates/basic/scripts/setup-husky.js +24 -0
- package/templates/basic/src/Routers.tsx +4 -5
- package/templates/basic/src/client/index.tsx +5 -1
- package/templates/basic/src/component/Header.tsx +10 -10
- package/templates/basic/src/component/Layout.tsx +9 -3
- package/templates/basic/src/component/Theme.tsx +5 -1
- package/templates/basic/src/containers/Home.tsx +141 -76
- package/templates/basic/src/containers/Photo.tsx +30 -18
- package/templates/basic/src/externals/window.d.ts +3 -1
- package/templates/basic/src/reducers/photo.ts +7 -2
- package/templates/basic/src/server/index.ts +35 -26
- package/templates/basic/src/server/photo.ts +14 -7
- package/templates/basic/src/server/utils.tsx +9 -7
- package/templates/basic/src/services/home.ts +1 -1
- package/templates/basic/src/services/photo.ts +28 -30
- package/templates/basic/src/store/constants.ts +1 -1
- package/templates/basic/src/store/index.ts +2 -1
- package/templates/basic/src/styled/component/header.ts +5 -1
- package/templates/basic/src/styled/home.ts +100 -24
- package/templates/basic/src/styled/photo.ts +2 -2
- package/templates/basic/src/utils/config.ts +1 -1
- package/templates/basic/src/utils/fetch.ts +4 -8
- package/templates/basic/src/utils/index.ts +1 -1
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# NSBP 开发指南
|
|
2
|
+
|
|
3
|
+
## 🚀 快速开始
|
|
4
|
+
|
|
5
|
+
### 1. 安装依赖
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# 使用 pnpm(Husky hooks 自动创建)
|
|
9
|
+
pnpm install
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
⚠️ **注意**:Husky 9.x 会自动创建 Git hooks,无需运行 `pnpm run prepare`。
|
|
13
|
+
|
|
14
|
+
### 2. 启动开发环境
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# 开发模式(带热重载)
|
|
18
|
+
pnpm run dev
|
|
19
|
+
|
|
20
|
+
# 或分步启动
|
|
21
|
+
pnpm run dev:init # 初始化构建
|
|
22
|
+
pnpm run dev:build:* # 监听文件变化
|
|
23
|
+
pnpm run dev:build:start # 启动服务器
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 3. 访问应用
|
|
27
|
+
|
|
28
|
+
- **客户端渲染**: http://localhost:3001/
|
|
29
|
+
- **服务端渲染**: http://localhost:3001/?seo=1
|
|
30
|
+
- **BrowserSync**: http://localhost:3000/
|
|
31
|
+
|
|
32
|
+
## 📝 开发工作流
|
|
33
|
+
|
|
34
|
+
### 提交代码
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# 1. 创建功能分支
|
|
38
|
+
git checkout -b feat/your-feature
|
|
39
|
+
|
|
40
|
+
# 2. 开发并测试
|
|
41
|
+
# ...
|
|
42
|
+
|
|
43
|
+
# 3. 格式化代码
|
|
44
|
+
pnpm run format
|
|
45
|
+
|
|
46
|
+
# 4. Lint 检查
|
|
47
|
+
pnpm run lint
|
|
48
|
+
|
|
49
|
+
# 5. 提交(Git hooks 自动运行 lint-staged)
|
|
50
|
+
git add .
|
|
51
|
+
git commit -m "feat: add new feature"
|
|
52
|
+
|
|
53
|
+
# 6. 推送(Git hooks 自动运行 lint)
|
|
54
|
+
git push origin feat/your-feature
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 提交信息格式
|
|
58
|
+
|
|
59
|
+
遵循 Conventional Commits 规范:
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
<type>(<scope>): <subject>
|
|
63
|
+
|
|
64
|
+
<body>
|
|
65
|
+
|
|
66
|
+
<footer>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**类型 (type)**:
|
|
70
|
+
- `feat`: 新功能
|
|
71
|
+
- `fix`: Bug 修复
|
|
72
|
+
- `docs`: 文档更新
|
|
73
|
+
- `style`: 代码格式化
|
|
74
|
+
- `refactor`: 重构(非功能或 Bug)
|
|
75
|
+
- `test`: 测试相关
|
|
76
|
+
- `chore`: 构建/工具链相关
|
|
77
|
+
- `perf`: 性能优化
|
|
78
|
+
- `ci`: CI 配置变更
|
|
79
|
+
|
|
80
|
+
**示例**:
|
|
81
|
+
```bash
|
|
82
|
+
git commit -m "feat(core): add SSR data preloading support"
|
|
83
|
+
git commit -m "fix(client): resolve hydration mismatch error"
|
|
84
|
+
git commit -m "docs(readme): update installation guide"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 🛠️ 常用命令
|
|
88
|
+
|
|
89
|
+
### 开发命令
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pnpm run dev # 完整开发环境
|
|
93
|
+
pnpm run dev:init # 初始化构建
|
|
94
|
+
pnpm run dev:build:* # 监听文件变化
|
|
95
|
+
pnpm run dev:build:start # 启动开发服务器
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 构建命令
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pnpm run build # 生产构建
|
|
102
|
+
pnpm run build:server # 构建服务端
|
|
103
|
+
pnpm run build:client # 构建客户端
|
|
104
|
+
pnpm run start # 启动生产服务器
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 代码质量
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
pnpm run lint # ESLint 检查
|
|
111
|
+
pnpm run lint:fix # ESLint 自动修复
|
|
112
|
+
pnpm run format # Prettier 格式化
|
|
113
|
+
pnpm run lint-staged # 对暂存文件运行 lint(Git 钩子自动执行)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 清理命令
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
pnpm run clean # 清理构建产物和缓存
|
|
120
|
+
rm -rf .temp_cache # 清理 Webpack 缓存
|
|
121
|
+
rm -rf node_modules # 清理依赖
|
|
122
|
+
pnpm install # 重新安装依赖
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Docker 命令
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# 生产环境
|
|
129
|
+
make build # 构建镜像
|
|
130
|
+
make prod # 启动生产环境
|
|
131
|
+
make logs # 查看日志
|
|
132
|
+
make restart # 重启容器
|
|
133
|
+
make shell # 进入容器
|
|
134
|
+
make down # 停止容器
|
|
135
|
+
make clean # 完全清理
|
|
136
|
+
|
|
137
|
+
# 开发环境
|
|
138
|
+
make dev # 启动开发环境
|
|
139
|
+
make logs-dev # 查看开发日志
|
|
140
|
+
make rebuild-dev # 重新构建并启动
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 📂 项目结构
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
nsbp/
|
|
147
|
+
├── cli/ # CLI 工具和模板
|
|
148
|
+
│ ├── bin/ # CLI 二进制文件
|
|
149
|
+
│ ├── templates/ # 项目模板
|
|
150
|
+
│ └── scripts/ # 构建脚本
|
|
151
|
+
├── config/ # Webpack 配置
|
|
152
|
+
│ ├── webpack.base.js # 基础配置
|
|
153
|
+
│ ├── webpack.client.js # 客户端配置
|
|
154
|
+
│ └── webpack.server.js # 服务端配置
|
|
155
|
+
├── public/ # 静态资源输出目录
|
|
156
|
+
├── src/ # 源代码目录
|
|
157
|
+
│ ├── client/ # 客户端入口
|
|
158
|
+
│ ├── server/ # 服务端代码
|
|
159
|
+
│ ├── containers/ # 页面组件
|
|
160
|
+
│ ├── component/ # 公共组件
|
|
161
|
+
│ ├── styled/ # 样式组件
|
|
162
|
+
│ ├── services/ # API 服务
|
|
163
|
+
│ ├── reducers/ # Redux reducers
|
|
164
|
+
│ ├── store/ # Redux store
|
|
165
|
+
│ └── utils/ # 工具函数
|
|
166
|
+
├── scripts/ # Node.js 脚本
|
|
167
|
+
├── docker/ # Docker 配置
|
|
168
|
+
├── docs/ # 文档
|
|
169
|
+
└── .husky/ # Git hooks
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## 🔍 代码检查工具
|
|
173
|
+
|
|
174
|
+
### ESLint
|
|
175
|
+
|
|
176
|
+
- **配置文件**: `.eslintrc.js`
|
|
177
|
+
- **忽略文件**: `.eslintignore`
|
|
178
|
+
- **用途**: TypeScript + React 代码质量检查
|
|
179
|
+
|
|
180
|
+
**规则**:
|
|
181
|
+
- TypeScript: 类型检查、未使用变量警告
|
|
182
|
+
- React: Hooks 规则、组件最佳实践
|
|
183
|
+
- Prettier: 代码风格一致性
|
|
184
|
+
|
|
185
|
+
### Prettier
|
|
186
|
+
|
|
187
|
+
- **配置文件**: `.prettierrc.js`
|
|
188
|
+
- **用途**: 自动格式化代码
|
|
189
|
+
|
|
190
|
+
**配置**:
|
|
191
|
+
- 2 空格缩进
|
|
192
|
+
- 单引号
|
|
193
|
+
- 无分号
|
|
194
|
+
- 100 字符换行
|
|
195
|
+
|
|
196
|
+
### Husky
|
|
197
|
+
|
|
198
|
+
- **配置目录**: `.husky/`
|
|
199
|
+
- **用途**: Git 钩子自动化
|
|
200
|
+
|
|
201
|
+
**钩子**:
|
|
202
|
+
- `pre-commit`: 提交前 lint 暂存文件
|
|
203
|
+
- `pre-push`: 推送前全量 lint
|
|
204
|
+
- `commit-msg`: 验证提交信息格式
|
|
205
|
+
|
|
206
|
+
## 🐛 常见问题
|
|
207
|
+
|
|
208
|
+
### Webpack 缓存错误
|
|
209
|
+
|
|
210
|
+
**问题**:
|
|
211
|
+
```
|
|
212
|
+
Cannot find module 'xxx'
|
|
213
|
+
Restoring failed for ResolverCachePlugin
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**解决方案**:
|
|
217
|
+
```bash
|
|
218
|
+
# 清理缓存
|
|
219
|
+
pnpm run clean
|
|
220
|
+
rm -rf .temp_cache
|
|
221
|
+
|
|
222
|
+
# 重新构建
|
|
223
|
+
pnpm run dev
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Git 钩子失败
|
|
227
|
+
|
|
228
|
+
**问题**:
|
|
229
|
+
```
|
|
230
|
+
husky - pre-commit hook failed
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**解决方案**:
|
|
234
|
+
```bash
|
|
235
|
+
# 查看错误
|
|
236
|
+
pnpm run lint
|
|
237
|
+
|
|
238
|
+
# 自动修复
|
|
239
|
+
pnpm run lint:fix
|
|
240
|
+
|
|
241
|
+
# 重新提交
|
|
242
|
+
git add .
|
|
243
|
+
git commit -m "style: resolve linting issues"
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### TypeScript 类型错误
|
|
247
|
+
|
|
248
|
+
**问题**: 编辑器显示类型错误,但项目能编译
|
|
249
|
+
|
|
250
|
+
**解决方案**:
|
|
251
|
+
```bash
|
|
252
|
+
# 重启 TypeScript 服务器
|
|
253
|
+
# VSCode: Ctrl+Shift+P -> "TypeScript: Restart TS Server"
|
|
254
|
+
|
|
255
|
+
# 确保项目已编译
|
|
256
|
+
pnpm run build:server
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Docker 权限错误
|
|
260
|
+
|
|
261
|
+
**问题**:
|
|
262
|
+
```
|
|
263
|
+
EACCES: permission denied
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
**解决方案**:
|
|
267
|
+
Docker 已在 `entrypoint.sh` 中自动修复权限,无需手动处理。
|
|
268
|
+
|
|
269
|
+
## 📚 相关文档
|
|
270
|
+
|
|
271
|
+
- [ESLINT_AND_PRETTIER.md](./ESLINT_AND_PRETTIER.md) - 代码风格配置
|
|
272
|
+
- [SETUP_GIT_HOOKS.md](./SETUP_GIT_HOOKS.md) - Git hooks 配置
|
|
273
|
+
- [README.md](../README.md) - 项目总览
|
|
274
|
+
|
|
275
|
+
## 💡 最佳实践
|
|
276
|
+
|
|
277
|
+
1. **提交前**: 总是运行 `pnpm run format` 和 `pnpm run lint:fix`
|
|
278
|
+
2. **分支管理**: 使用功能分支,不直接在 main/master 分支开发
|
|
279
|
+
3. **提交信息**: 遵循 Conventional Commits 规范
|
|
280
|
+
4. **代码审查**: 提交 PR 前自查代码质量和格式
|
|
281
|
+
5. **定期清理**: 定期运行 `pnpm run clean` 清理缓存
|
|
282
|
+
6. **依赖更新**: 使用 `pnpm update` 而不是手动修改版本号
|
|
283
|
+
|
|
284
|
+
## 🎯 下一步
|
|
285
|
+
|
|
286
|
+
- [ ] 配置 CI/CD 流程
|
|
287
|
+
- [ ] 添加单元测试
|
|
288
|
+
- [ ] 添加 E2E 测试
|
|
289
|
+
- [ ] 配置代码覆盖率
|
|
290
|
+
- [ ] 设置自动化部署
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# ESLint & Prettier 配置指南
|
|
2
|
+
|
|
3
|
+
本项目使用 ESLint + Prettier 进行代码风格检查和格式化。
|
|
4
|
+
|
|
5
|
+
## 📦 已安装的包
|
|
6
|
+
|
|
7
|
+
```json
|
|
8
|
+
{
|
|
9
|
+
"eslint": "^9.0.0",
|
|
10
|
+
"eslint-config-prettier": "^9.0.0",
|
|
11
|
+
"eslint-plugin-react": "^7.37.0",
|
|
12
|
+
"eslint-plugin-react-hooks": "^5.0.0",
|
|
13
|
+
"husky": "^9.0.0",
|
|
14
|
+
"lint-staged": "^15.0.0",
|
|
15
|
+
"prettier": "^3.3.0",
|
|
16
|
+
"prettier-plugin-organize-imports": "^4.0.0",
|
|
17
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
18
|
+
"@typescript-eslint/parser": "^8.0.0"
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 🔧 配置文件
|
|
23
|
+
|
|
24
|
+
### ESLint
|
|
25
|
+
- `.eslintrc.js` - ESLint 配置
|
|
26
|
+
- `.eslintignore` - ESLint 忽略规则
|
|
27
|
+
|
|
28
|
+
### Prettier
|
|
29
|
+
- `.prettierrc.js` - Prettier 配置
|
|
30
|
+
|
|
31
|
+
### Husky
|
|
32
|
+
- `.husky/pre-commit` - 提交前钩子
|
|
33
|
+
- `.husky/pre-push` - 推送前钩子
|
|
34
|
+
- `.husky/commit-msg` - 提交信息验证
|
|
35
|
+
|
|
36
|
+
## 📝 可用命令
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Lint 检查(不修复)
|
|
40
|
+
pnpm run lint
|
|
41
|
+
|
|
42
|
+
# Lint 检查并自动修复
|
|
43
|
+
pnpm run lint:fix
|
|
44
|
+
|
|
45
|
+
# 格式化代码
|
|
46
|
+
pnpm run format
|
|
47
|
+
|
|
48
|
+
# 同时 lint 和格式化(Git 钩子自动执行)
|
|
49
|
+
pnpm run lint-staged
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 🔍 ESLint 规则
|
|
53
|
+
|
|
54
|
+
### TypeScript 规则
|
|
55
|
+
- `@typescript-eslint/no-explicit-any`: 警告 - 允许 `any` 类型
|
|
56
|
+
- `@typescript-eslint/no-unused-vars`: 警告 - 未使用的变量(允许 `_` 开头)
|
|
57
|
+
|
|
58
|
+
### React 规则
|
|
59
|
+
- `react/react-in-jsx-scope`: 关闭 - 不需要显式 React 导入
|
|
60
|
+
- `react/prop-types`: 关闭 - 使用 TypeScript 类型系统
|
|
61
|
+
- `react-hooks/rules-of-hooks`: 错误 - 遵循 React Hooks 规则
|
|
62
|
+
- `react-hooks/exhaustive-deps`: 警告 - Hooks 依赖项检查
|
|
63
|
+
|
|
64
|
+
### 其他规则
|
|
65
|
+
- `prettier/prettier`: 错误 - 代码风格必须符合 Prettier 配置
|
|
66
|
+
- `no-console`: 警告 - 允许 `console.warn` 和 `console.error`
|
|
67
|
+
|
|
68
|
+
## 🎨 Prettier 配置
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
{
|
|
72
|
+
semi: false, // 不使用分号
|
|
73
|
+
singleQuote: true, // 使用单引号
|
|
74
|
+
tabWidth: 2, // 2 空格缩进
|
|
75
|
+
trailingComma: 'es5', // ES5 尾部逗号
|
|
76
|
+
printWidth: 100, // 每行最多 100 字符
|
|
77
|
+
arrowParens: 'always', // 箭头函数总是加括号
|
|
78
|
+
endOfLine: 'lf', // Unix 换行符
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 📁 忽略的文件
|
|
83
|
+
|
|
84
|
+
ESLint 会忽略以下目录和文件:
|
|
85
|
+
|
|
86
|
+
- `node_modules/`
|
|
87
|
+
- `build/`
|
|
88
|
+
- `dist/`
|
|
89
|
+
- `.temp_cache/`
|
|
90
|
+
- `public/js/`
|
|
91
|
+
- `public/css/`
|
|
92
|
+
- `*.bundle.js`
|
|
93
|
+
- `loadable-stats.json`
|
|
94
|
+
- `coverage/`
|
|
95
|
+
- Webpack 配置文件(`*.config.js`)
|
|
96
|
+
|
|
97
|
+
## 🚨 常见问题
|
|
98
|
+
|
|
99
|
+
### 1. Git 钩子阻止提交
|
|
100
|
+
|
|
101
|
+
**问题**:提交代码时,Git 钩子失败
|
|
102
|
+
|
|
103
|
+
**解决方案**:
|
|
104
|
+
```bash
|
|
105
|
+
# 查看错误信息
|
|
106
|
+
pnpm run lint
|
|
107
|
+
|
|
108
|
+
# 自动修复
|
|
109
|
+
pnpm run lint:fix
|
|
110
|
+
|
|
111
|
+
# 重新提交
|
|
112
|
+
git add .
|
|
113
|
+
git commit -m "fix: resolve linting issues"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 2. TypeScript 类型错误
|
|
117
|
+
|
|
118
|
+
**问题**:ESLint 报告类型错误
|
|
119
|
+
|
|
120
|
+
**解决方案**:
|
|
121
|
+
- 确保项目已编译:`pnpm run build:server`
|
|
122
|
+
- 重启 TypeScript 服务器(TS Language Server)
|
|
123
|
+
|
|
124
|
+
### 3. Prettier 格式冲突
|
|
125
|
+
|
|
126
|
+
**问题**:手动格式化后,ESLint 仍然报错
|
|
127
|
+
|
|
128
|
+
**解决方案**:
|
|
129
|
+
```bash
|
|
130
|
+
# 使用 Prettier 重新格式化
|
|
131
|
+
pnpm run format
|
|
132
|
+
|
|
133
|
+
# 确保编辑器使用 Prettier
|
|
134
|
+
# VSCode: 安装 Prettier 插件,启用 "Format on Save"
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 4. 跳过 Git 钩子(不推荐)
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
git commit --no-verify -m "your commit message"
|
|
141
|
+
git push --no-verify
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
⚠️ **警告**:仅在紧急情况下使用!
|
|
145
|
+
|
|
146
|
+
## 🎯 编辑器配置
|
|
147
|
+
|
|
148
|
+
### VSCode
|
|
149
|
+
|
|
150
|
+
推荐安装扩展:
|
|
151
|
+
- ESLint
|
|
152
|
+
- Prettier - Code formatter
|
|
153
|
+
- TypeScript Importer
|
|
154
|
+
|
|
155
|
+
项目根目录创建 `.vscode/settings.json`:
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"editor.formatOnSave": true,
|
|
160
|
+
"editor.codeActionsOnSave": {
|
|
161
|
+
"source.fixAll.eslint": "explicit"
|
|
162
|
+
},
|
|
163
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
164
|
+
"[typescript]": {
|
|
165
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
166
|
+
},
|
|
167
|
+
"[typescriptreact]": {
|
|
168
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
169
|
+
},
|
|
170
|
+
"eslint.validate": [
|
|
171
|
+
"javascript",
|
|
172
|
+
"javascriptreact",
|
|
173
|
+
"typescript",
|
|
174
|
+
"typescriptreact"
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## 📚 参考资料
|
|
180
|
+
|
|
181
|
+
- [ESlint 文档](https://eslint.org/docs/latest/)
|
|
182
|
+
- [Prettier 文档](https://prettier.io/docs/en/options)
|
|
183
|
+
- [React Hooks 规则](https://react-hooks.vercel.app/)
|
|
184
|
+
- [Conventional Commits](https://www.conventionalcommits.org/)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Husky 9.x 升级说明
|
|
2
|
+
|
|
3
|
+
## ℹ️ 关于 "husky install command is DEPRECATED" 警告
|
|
4
|
+
|
|
5
|
+
这是正常的!Husky 9.x 版本已经改变了安装方式。
|
|
6
|
+
|
|
7
|
+
### 变化说明
|
|
8
|
+
|
|
9
|
+
**Husky 8.x (旧版本)**:
|
|
10
|
+
- 需要手动运行 `husky install` 命令
|
|
11
|
+
- `prepare` 脚本:`"prepare": "husky install"`
|
|
12
|
+
|
|
13
|
+
**Husky 9.x (新版本)**:
|
|
14
|
+
- ✅ Hooks 在 `pnpm install` 时自动创建
|
|
15
|
+
- ✅ 不需要手动运行 `husky install`
|
|
16
|
+
- ✅ `prepare` 脚本:`"prepare": "husky"`(仅注册命令)
|
|
17
|
+
|
|
18
|
+
### 如何工作
|
|
19
|
+
|
|
20
|
+
运行 `pnpm install` 时:
|
|
21
|
+
1. Husky 自动创建 `.husky` 目录
|
|
22
|
+
2. 自动生成 Git hooks(pre-commit, pre-push, commit-msg)
|
|
23
|
+
3. 设置 Git hooks 路径:`git config core.hooksPath .husky`
|
|
24
|
+
|
|
25
|
+
### 当前配置
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"prepare": "husky" // 正确!注册 Husky 命令
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 验证安装
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# 检查 hooks 是否存在
|
|
37
|
+
ls .husky
|
|
38
|
+
# 应该看到: pre-commit, pre-push, commit-msg
|
|
39
|
+
|
|
40
|
+
# 检查 hooks 是否有执行权限
|
|
41
|
+
ls -la .husky/
|
|
42
|
+
# 应该看到: -rwxr-xr-x
|
|
43
|
+
|
|
44
|
+
# 测试提交
|
|
45
|
+
git commit -m "test: verify hooks"
|
|
46
|
+
# 应该自动运行 lint-staged
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 无需操作
|
|
50
|
+
|
|
51
|
+
这个警告可以安全忽略!🎉 你的项目已经正确配置了 Husky 9.x。
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 🔄 升级步骤(如需)
|
|
56
|
+
|
|
57
|
+
如果你之前使用的是 Husky 8.x,需要:
|
|
58
|
+
|
|
59
|
+
1. **更新 package.json**:
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"prepare": "husky" // 从 "husky install" 改为 "husky"
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
2. **重新安装依赖**:
|
|
67
|
+
```bash
|
|
68
|
+
pnpm install
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
3. **验证 hooks**:
|
|
72
|
+
```bash
|
|
73
|
+
ls .husky
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
完成!Husky 9.x 现在可以正常工作。
|