@qlover/create-app 0.6.1 → 0.6.3

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.
Files changed (68) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/templates/react-app/README.en.md +257 -0
  5. package/dist/templates/react-app/README.md +29 -231
  6. package/dist/templates/react-app/config/IOCIdentifier.ts +13 -0
  7. package/dist/templates/react-app/docs/en/bootstrap.md +562 -0
  8. package/dist/templates/react-app/docs/en/development-guide.md +523 -0
  9. package/dist/templates/react-app/docs/en/env.md +482 -0
  10. package/dist/templates/react-app/docs/en/global.md +509 -0
  11. package/dist/templates/react-app/docs/en/i18n.md +268 -0
  12. package/dist/templates/react-app/docs/en/index.md +173 -0
  13. package/dist/templates/react-app/docs/en/ioc.md +424 -0
  14. package/dist/templates/react-app/docs/en/project-structure.md +434 -0
  15. package/dist/templates/react-app/docs/en/request.md +425 -0
  16. package/dist/templates/react-app/docs/en/router.md +404 -0
  17. package/dist/templates/react-app/docs/en/store.md +321 -0
  18. package/dist/templates/react-app/docs/en/theme.md +424 -0
  19. package/dist/templates/react-app/docs/en/typescript-guide.md +473 -0
  20. package/dist/templates/react-app/docs/zh/bootstrap.md +562 -0
  21. package/dist/templates/react-app/docs/zh/development-guide.md +523 -0
  22. package/dist/templates/react-app/docs/zh/env.md +479 -0
  23. package/dist/templates/react-app/docs/zh/global.md +511 -0
  24. package/dist/templates/react-app/docs/zh/i18n.md +268 -0
  25. package/dist/templates/react-app/docs/zh/index.md +173 -0
  26. package/dist/templates/react-app/docs/zh/ioc.md +422 -0
  27. package/dist/templates/react-app/docs/zh/project-structure.md +434 -0
  28. package/dist/templates/react-app/docs/zh/request.md +429 -0
  29. package/dist/templates/react-app/docs/zh/router.md +408 -0
  30. package/dist/templates/react-app/docs/zh/store.md +321 -0
  31. package/dist/templates/react-app/docs/zh/theme.md +424 -0
  32. package/dist/templates/react-app/docs/zh/typescript-guide.md +473 -0
  33. package/dist/templates/react-app/package.json +2 -2
  34. package/dist/templates/react-app/src/base/apis/AiApi.ts +10 -5
  35. package/dist/templates/react-app/src/base/apis/feApi/FeApiAdapter.ts +1 -1
  36. package/dist/templates/react-app/src/base/apis/feApi/FeApiBootstarp.ts +1 -1
  37. package/dist/templates/react-app/src/base/apis/userApi/UserApi.ts +10 -17
  38. package/dist/templates/react-app/src/base/apis/userApi/UserApiAdapter.ts +1 -1
  39. package/dist/templates/react-app/src/base/apis/userApi/UserApiBootstarp.ts +2 -1
  40. package/dist/templates/react-app/src/base/apis/userApi/UserApiType.ts +7 -5
  41. package/dist/templates/react-app/src/base/cases/I18nKeyErrorPlugin.ts +3 -2
  42. package/dist/templates/react-app/src/base/cases/InversifyContainer.ts +33 -0
  43. package/dist/templates/react-app/src/base/cases/RequestLogger.ts +1 -1
  44. package/dist/templates/react-app/src/base/cases/RequestStatusCatcher.ts +2 -2
  45. package/dist/templates/react-app/src/base/services/ProcesserExecutor.ts +1 -1
  46. package/dist/templates/react-app/src/base/services/RouteService.ts +5 -2
  47. package/dist/templates/react-app/src/base/services/UserService.ts +8 -10
  48. package/dist/templates/react-app/src/core/IOC.ts +73 -83
  49. package/dist/templates/react-app/src/core/bootstraps/BootstrapApp.ts +52 -4
  50. package/dist/templates/react-app/src/core/bootstraps/{index.ts → BootstrapsRegistry.ts} +2 -3
  51. package/dist/templates/react-app/src/core/registers/IocRegisterImpl.ts +25 -0
  52. package/dist/templates/react-app/src/core/registers/RegisterCommon.ts +11 -17
  53. package/dist/templates/react-app/src/core/registers/RegisterControllers.ts +10 -4
  54. package/dist/templates/react-app/src/core/registers/RegisterGlobals.ts +6 -15
  55. package/dist/templates/react-app/src/main.tsx +2 -5
  56. package/dist/templates/react-app/src/styles/css/antd-themes/dark.css +3 -1
  57. package/dist/templates/react-app/src/styles/css/antd-themes/index.css +1 -1
  58. package/dist/templates/react-app/src/styles/css/antd-themes/pink.css +6 -1
  59. package/dist/templates/react-app/src/styles/css/page.css +1 -1
  60. package/dist/templates/react-app/src/uikit/controllers/JSONStorageController.ts +1 -1
  61. package/dist/templates/react-app/tsconfig.app.json +2 -1
  62. package/dist/templates/react-app/tsconfig.node.json +2 -1
  63. package/package.json +2 -2
  64. package/dist/templates/react-app/src/base/port/ApiTransactionInterface.ts +0 -7
  65. package/dist/templates/react-app/src/base/port/RequestCatcherInterface.ts +0 -12
  66. package/dist/templates/react-app/src/core/bootstrap.ts +0 -58
  67. package/dist/templates/react-app/src/core/registers/RegisterApi.ts +0 -5
  68. package/dist/templates/react-app/src/core/registers/index.ts +0 -32
@@ -0,0 +1,268 @@
1
+ # 国际化系统
2
+
3
+ ## 概述
4
+
5
+ 国际化系统采用基于标识符别名的方案,结合 i18next 和 TypeScript 注释,实现了一个类型安全、易维护的国际化解决方案。主要特点:
6
+
7
+ - **标识符别名**:使用常量而非字符串作为翻译键
8
+ - **TypeScript 注释**:通过注释自动生成翻译资源
9
+ - **类型安全**:完整的类型检查和自动补全
10
+ - **路由集成**:支持 URL 路径中的语言参数
11
+ - **自动生成**:自动从源码生成翻译文件
12
+ - **开发友好**:完整的开发工具支持
13
+
14
+ ## 核心概念
15
+
16
+ ### 1. 标识符别名
17
+
18
+ 使用常量替代字符串键值,提供更好的类型安全和维护性:
19
+
20
+ ```typescript
21
+ // config/Identifier/common.ts
22
+
23
+ /**
24
+ * @description Theme switcher default theme label
25
+ * @localZh 默认主题
26
+ * @localEn Default Theme
27
+ */
28
+ export const HEADER_THEME_DEFAULT = 'header.theme.default';
29
+
30
+ /**
31
+ * @description Theme switcher dark theme label
32
+ * @localZh 暗色主题
33
+ * @localEn Dark Theme
34
+ */
35
+ export const HEADER_THEME_DARK = 'header.theme.dark';
36
+ ```
37
+
38
+ ### 2. 自动生成配置
39
+
40
+ 在 `vite.config.ts` 中配置自动生成:
41
+
42
+ ```typescript
43
+ import ts2Locales from '@brain-toolkit/ts2locales/vite';
44
+
45
+ export default defineConfig({
46
+ plugins: [
47
+ ts2Locales({
48
+ locales: ['en', 'zh'],
49
+ options: [
50
+ {
51
+ source: './config/Identifier/common.ts',
52
+ target: './public/locales/{{lng}}/common.json'
53
+ },
54
+ {
55
+ source: './config/Identifier/error.ts',
56
+ target: './public/locales/{{lng}}/common.json'
57
+ }
58
+ ]
59
+ })
60
+ ]
61
+ });
62
+ ```
63
+
64
+ ### 3. i18n 服务配置
65
+
66
+ ```typescript
67
+ // config/i18n.ts
68
+ export default {
69
+ fallbackLng: 'en',
70
+ debug: false,
71
+ interpolation: {
72
+ escapeValue: false
73
+ },
74
+ ns: ['common'],
75
+ defaultNS: 'common',
76
+ backend: {
77
+ loadPath: '/locales/{{lng}}/{{ns}}.json'
78
+ },
79
+ supportedLngs: ['en', 'zh']
80
+ } as const;
81
+ ```
82
+
83
+ ## 使用方式
84
+
85
+ ### 1. 定义翻译键
86
+
87
+ ```typescript
88
+ // config/Identifier/page.ts
89
+
90
+ /**
91
+ * @description Home page title
92
+ * @localZh 首页
93
+ * @localEn Home
94
+ */
95
+ export const PAGE_HOME_TITLE = 'page.home.title';
96
+
97
+ /**
98
+ * @description Home page welcome message
99
+ * @localZh 欢迎来到我们的应用
100
+ * @localEn Welcome to our application
101
+ */
102
+ export const PAGE_HOME_WELCOME = 'page.home.welcome';
103
+ ```
104
+
105
+ ### 2. 在组件中使用
106
+
107
+ ```tsx
108
+ import { useTranslation } from 'react-i18next';
109
+ import * as i18nKeys from '@config/Identifier/page';
110
+
111
+ function HomePage() {
112
+ const { t } = useTranslation();
113
+
114
+ return (
115
+ <div>
116
+ <h1>{t(i18nKeys.PAGE_HOME_TITLE)}</h1>
117
+ <p>{t(i18nKeys.PAGE_HOME_WELCOME)}</p>
118
+ </div>
119
+ );
120
+ }
121
+ ```
122
+
123
+ ### 3. 带参数的翻译
124
+
125
+ ```typescript
126
+ /**
127
+ * @description Welcome user message
128
+ * @localZh 欢迎,{{name}}!
129
+ * @localEn Welcome, {{name}}!
130
+ */
131
+ export const USER_WELCOME = 'user.welcome';
132
+
133
+ function Welcome({ username }: { username: string }) {
134
+ const { t } = useTranslation();
135
+ return <h1>{t(i18nKeys.USER_WELCOME, { name: username })}</h1>;
136
+ }
137
+ ```
138
+
139
+ ### 4. 语言切换
140
+
141
+ ```tsx
142
+ import { IOC } from '@/core/IOC';
143
+ import { I18nService } from '@/base/services/I18nService';
144
+
145
+ function LanguageSwitcher() {
146
+ const i18nService = IOC(I18nService);
147
+ const currentLang = i18nService.getCurrentLanguage();
148
+
149
+ const handleChange = (lang: string) => {
150
+ i18nService.changeLanguage(lang);
151
+ };
152
+
153
+ return (
154
+ <select value={currentLang} onChange={(e) => handleChange(e.target.value)}>
155
+ <option value="zh">中文</option>
156
+ <option value="en">English</option>
157
+ </select>
158
+ );
159
+ }
160
+ ```
161
+
162
+ ## 最佳实践
163
+
164
+ ### 1. 标识符组织
165
+
166
+ - **命名规范**:
167
+
168
+ ```typescript
169
+ // 页面相关
170
+ PAGE_HOME_TITLE;
171
+ PAGE_ABOUT_DESCRIPTION;
172
+
173
+ // 功能模块相关
174
+ AUTH_LOGIN_BUTTON;
175
+ AUTH_LOGOUT_CONFIRM;
176
+
177
+ // 公共组件相关
178
+ COMMON_SUBMIT_BUTTON;
179
+ COMMON_CANCEL_BUTTON;
180
+ ```
181
+
182
+ - **文件组织**:
183
+ ```
184
+ config/
185
+ ├── Identifier/
186
+ │ ├── common.ts // 公共文本
187
+ │ ├── page.ts // 页面文本
188
+ │ ├── error.ts // 错误信息
189
+ │ └── auth.ts // 认证相关
190
+ ```
191
+
192
+ ### 2. 注释规范
193
+
194
+ ```typescript
195
+ /**
196
+ * @description 简短的描述,说明文本用途
197
+ * @localZh 中文翻译文本
198
+ * @localEn 英文翻译文本
199
+ */
200
+ ```
201
+
202
+ ### 3. 类型安全
203
+
204
+ ```typescript
205
+ // 使用类型导入确保键值存在
206
+ import * as i18nKeys from '@config/Identifier';
207
+
208
+ // 类型检查会捕获错误的键值
209
+ t(i18nKeys.NONEXISTENT_KEY); // TS 错误
210
+ ```
211
+
212
+ ### 4. 动态内容
213
+
214
+ ```typescript
215
+ /**
216
+ * @description File upload progress
217
+ * @localZh 已上传 {{count}} 个文件,共 {{total}} 个
218
+ * @localEn Uploaded {{count}} files out of {{total}}
219
+ */
220
+ export const UPLOAD_PROGRESS = 'upload.progress';
221
+
222
+ // 使用
223
+ t(i18nKeys.UPLOAD_PROGRESS, { count: 3, total: 10 });
224
+ ```
225
+
226
+ ## 工作流程
227
+
228
+ 1. **开发阶段**:
229
+ - 在 Identifier 文件中定义翻译键和注释
230
+ - 使用标识符别名在代码中引用翻译
231
+ - 运行开发服务器时自动生成翻译文件
232
+
233
+ 2. **构建阶段**:
234
+ - 自动检查翻译完整性
235
+ - 生成生产环境翻译文件
236
+ - 优化翻译资源加载
237
+
238
+ 3. **运行时**:
239
+ - 根据 URL 检测语言
240
+ - 按需加载翻译资源
241
+ - 响应语言切换事件
242
+
243
+ ## 常见问题
244
+
245
+ ### 1. 翻译未生效
246
+
247
+ 检查以下几点:
248
+
249
+ - 确保标识符正确导出
250
+ - 检查注释格式是否规范
251
+ - 验证翻译文件是否生成
252
+ - 确认语言检测正确
253
+
254
+ ### 2. 类型错误
255
+
256
+ 可能的解决方案:
257
+
258
+ - 检查标识符导入路径
259
+ - 确保使用正确的标识符
260
+ - 更新 TypeScript 类型定义
261
+
262
+ ### 3. 性能优化
263
+
264
+ 开发建议:
265
+
266
+ - 合理拆分翻译文件
267
+ - 使用翻译资源预加载
268
+ - 避免重复翻译键
@@ -0,0 +1,173 @@
1
+ # React 应用开发文档
2
+
3
+ ## 简介
4
+
5
+ 这是一个基于 React 18 的现代化前端应用模板,集成了完整的开发框架和工具链。本模板提供了一套完整的开发解决方案,包括状态管理、路由管理、国际化、主题系统等核心功能。
6
+
7
+ ### 主要特性
8
+
9
+ - 🚀 **现代化技术栈**:基于 React 18、TypeScript、Vite
10
+ - 🎨 **主题定制**:支持动态主题切换,深色模式
11
+ - 🌍 **国际化**:内置多语言支持
12
+ - 📦 **状态管理**:基于发布订阅的响应式状态管理
13
+ - 🔑 **认证系统**:完整的用户认证解决方案
14
+ - 🛠️ **开发工具**:ESLint、Prettier、TypeScript
15
+ - 📱 **响应式设计**:支持多端适配
16
+ - 🧪 **测试支持**:集成单元测试和组件测试
17
+
18
+ ## 快速开始
19
+
20
+ ```bash
21
+ # 安装依赖
22
+ npm install
23
+
24
+ # 启动开发服务器
25
+ npm run dev
26
+
27
+ # 构建生产版本
28
+ npm run build
29
+ ```
30
+
31
+ ## 文档导航
32
+
33
+ ### 架构指南
34
+
35
+ - [项目结构说明](./project-structure.md)
36
+ - [开发规范指南](./development-guide.md)
37
+ - [构建部署指南](./deployment.md)
38
+
39
+ ### 核心功能
40
+
41
+ - [路由开发指南](./router.md)
42
+ - [状态管理指南](./store.md)
43
+ - [国际化开发指南](./i18n.md)
44
+ - [主题开发指南](./theme.md)
45
+ - [请求系统指南](./request.md)
46
+
47
+ ### 组件开发
48
+
49
+ - [组件开发指南](./component-guide.md)
50
+ - [TypeScript 开发规范](./typescript-guide.md)
51
+ - [样式开发指南](./styling-guide.md)
52
+
53
+ ### 工具和测试
54
+
55
+ - [测试开发指南](./testing.md)
56
+ - [Git 工作流指南](./git-workflow.md)
57
+ - [性能优化指南](./performance.md)
58
+
59
+ ### 安全和最佳实践
60
+
61
+ - [安全开发指南](./security.md)
62
+ - [文档编写指南](./documentation.md)
63
+
64
+ ## 目录结构
65
+
66
+ ```
67
+ docs/zh/
68
+ ├── index.md # 本文档
69
+ ├── project-structure.md # 项目结构说明
70
+ ├── development-guide.md # 开发规范指南
71
+ ├── router.md # 路由开发指南
72
+ ├── store.md # 状态管理指南
73
+ ├── i18n.md # 国际化开发指南
74
+ ├── theme.md # 主题开发指南
75
+ └── ...
76
+ ```
77
+
78
+ ## 核心概念
79
+
80
+ ### 1. 启动流程
81
+
82
+ 应用采用插件化的启动流程:
83
+
84
+ ```
85
+ Bootstrap 初始化 → 加载插件 → 初始化服务 → 渲染应用
86
+ ```
87
+
88
+ ### 2. 状态管理
89
+
90
+ 基于发布订阅模式的响应式状态管理:
91
+
92
+ ```
93
+ Action 触发 → Store 更新 → 组件重渲染
94
+ ```
95
+
96
+ ### 3. 路由系统
97
+
98
+ 配置式路由管理:
99
+
100
+ ```
101
+ 路由配置 → 自动生成路由 → 代码分割 → 按需加载
102
+ ```
103
+
104
+ ### 4. 国际化
105
+
106
+ 基于 TypeScript 注释的自动国际化:
107
+
108
+ ```
109
+ 注释定义 → 自动生成资源 → 动态加载 → 语言切换
110
+ ```
111
+
112
+ ## 开发流程
113
+
114
+ 1. **需求分析**
115
+ - 理解业务需求
116
+ - 设计技术方案
117
+ - 评估开发周期
118
+
119
+ 2. **开发阶段**
120
+ - 遵循开发规范
121
+ - 编写单元测试
122
+ - 进行代码审查
123
+
124
+ 3. **测试阶段**
125
+ - 单元测试
126
+ - 集成测试
127
+ - 性能测试
128
+
129
+ 4. **部署上线**
130
+ - 构建优化
131
+ - 部署配置
132
+ - 监控告警
133
+
134
+ ## 常见问题
135
+
136
+ ### 1. 开发环境配置
137
+
138
+ - 确保 Node.js 版本 >= 16
139
+ - 使用推荐的 IDE 配置
140
+ - 安装必要的开发工具
141
+
142
+ ### 2. 构建相关
143
+
144
+ - 常见构建错误解决
145
+ - 性能优化建议
146
+ - 部署注意事项
147
+
148
+ ### 3. 开发相关
149
+
150
+ - 代码规范问题
151
+ - 类型系统使用
152
+ - 组件开发规范
153
+
154
+ ## 贡献指南
155
+
156
+ 1. Fork 项目
157
+ 2. 创建特性分支
158
+ 3. 提交变更
159
+ 4. 发起 Pull Request
160
+
161
+ ## 更新日志
162
+
163
+ 查看 [CHANGELOG.md](../../CHANGELOG.md) 了解详细的更新历史。
164
+
165
+ ## 支持和帮助
166
+
167
+ - 提交 Issue
168
+ - 查看 Wiki
169
+ - 参与讨论
170
+
171
+ ## 许可证
172
+
173
+ 本项目基于 [ISC 许可证](../../LICENSE) 开源。