@qlover/create-app 0.4.0 → 0.4.2

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 (46) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/configs/_common/package.json.template +1 -1
  3. package/dist/index.js +1 -1
  4. package/package.json +1 -1
  5. package/templates/react-app/.env +1 -2
  6. package/templates/react-app/README.md +70 -8
  7. package/templates/react-app/config/app.router.json +13 -13
  8. package/templates/react-app/config/common.ts +8 -0
  9. package/templates/react-app/config/i18n.ts +3 -1
  10. package/templates/react-app/config/{Identifier.I18n.ts → identifier/I18n.ts} +321 -3
  11. package/templates/react-app/index.html +1 -1
  12. package/templates/react-app/public/locales/en/common.json +54 -8
  13. package/templates/react-app/public/locales/zh/common.json +54 -8
  14. package/templates/react-app/public/router-root/logo.svg +1 -0
  15. package/templates/react-app/src/App.tsx +6 -3
  16. package/templates/react-app/src/base/cases/PublicAssetsPath.ts +17 -0
  17. package/templates/react-app/src/base/port/LoginInterface.ts +8 -0
  18. package/templates/react-app/src/base/port/StoreInterface.ts +58 -0
  19. package/templates/react-app/src/base/services/I18nService.ts +15 -9
  20. package/templates/react-app/src/{uikit/controllers/RouterController.ts → base/services/RouteService.ts} +12 -12
  21. package/templates/react-app/src/{uikit/controllers/UserController.ts → base/services/UserService.ts} +21 -11
  22. package/templates/react-app/src/core/bootstrap.ts +1 -1
  23. package/templates/react-app/src/core/registers/RegisterCommon.ts +11 -1
  24. package/templates/react-app/src/core/registers/RegisterControllers.ts +3 -12
  25. package/templates/react-app/src/pages/auth/Layout.tsx +5 -5
  26. package/templates/react-app/src/pages/auth/Login.tsx +50 -29
  27. package/templates/react-app/src/pages/auth/Register.tsx +238 -1
  28. package/templates/react-app/src/pages/base/About.tsx +1 -1
  29. package/templates/react-app/src/pages/base/ErrorIdentifier.tsx +2 -2
  30. package/templates/react-app/src/pages/base/Executor.tsx +4 -4
  31. package/templates/react-app/src/pages/base/Home.tsx +1 -1
  32. package/templates/react-app/src/pages/base/JSONStorage.tsx +3 -3
  33. package/templates/react-app/src/pages/base/Request.tsx +4 -4
  34. package/templates/react-app/src/pages/base/components/BaseHeader.tsx +8 -2
  35. package/templates/react-app/src/uikit/components/LanguageSwitcher.tsx +7 -7
  36. package/templates/react-app/src/uikit/components/ThemeSwitcher.tsx +3 -3
  37. package/templates/react-app/src/uikit/contexts/BaseRouteContext.ts +1 -1
  38. package/templates/react-app/src/uikit/controllers/ExecutorController.ts +6 -3
  39. package/templates/react-app/src/uikit/controllers/JSONStorageController.ts +6 -3
  40. package/templates/react-app/src/uikit/controllers/RequestController.ts +3 -4
  41. package/templates/react-app/src/uikit/hooks/useDocumentTitle.ts +15 -0
  42. package/templates/react-app/src/uikit/hooks/useStore.ts +12 -0
  43. package/templates/react-app/src/uikit/providers/BaseRouteProvider.tsx +7 -1
  44. package/templates/react-app/src/uikit/providers/ProcessProvider.tsx +7 -7
  45. package/templates/react-app/vite.config.ts +20 -11
  46. /package/templates/react-app/config/{Identifier.Error.ts → identifier/Error.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # @qlover/create-app
2
2
 
3
+ ## 0.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ #### ✨ Features
8
+
9
+ - **create-app:** enhance routing and configuration with router prefix and new services ([b32795d](https://github.com/qlover/fe-base/commit/b32795d02af4234d4708a5bdcb111bf8d2a54bd6)) ([#430](https://github.com/qlover/fe-base/pull/430))
10
+
11
+ - Introduced a router prefix in the configuration to manage asset paths and API routes more effectively.
12
+ - Updated the application to utilize the new RouteService for routing logic, replacing the previous RouterController.
13
+ - Refactored user authentication handling to use UserService, improving modularity and maintainability.
14
+ - Added PublicAssetsPath service to manage public asset paths dynamically based on the router prefix.
15
+ - Updated localization files to include additional keys and ensure consistency across languages.
16
+ - Modified various components to integrate the new services and ensure proper routing and asset management.
17
+
18
+ This update enhances the overall structure and flexibility of the application, paving the way for future improvements.
19
+
20
+ - **create-app:** enhance login and registration features with improved localization and form handling ([a3724e5](https://github.com/qlover/fe-base/commit/a3724e5e75c8708dd00684ece563d9e1c63c0d00)) ([#430](https://github.com/qlover/fe-base/pull/430))
21
+
22
+ - Updated routing configuration to include localized titles for various pages, enhancing user experience.
23
+ - Added new keys for login and registration in localization files for both English and Chinese.
24
+ - Implemented a registration form with validation and user feedback, integrating with the UserService for account creation.
25
+ - Enhanced the Login component to utilize localized strings for better accessibility and clarity.
26
+ - Refactored the I18nService to support dynamic title updates based on the current route.
27
+
28
+ This update significantly improves the user interface and experience for authentication processes within the application.
29
+
30
+ - **create-app:** refactor internationalization and store management ([c86ed98](https://github.com/qlover/fe-base/commit/c86ed9818d844d4059878c11897051a6c504a333)) ([#430](https://github.com/qlover/fe-base/pull/430))
31
+
32
+ - Updated file structure for internationalization resources, moving identifiers to a new directory for better organization.
33
+ - Introduced new error and i18n identifier files to enhance localization support.
34
+ - Refactored store management by implementing a new StoreInterface, improving state management across services.
35
+ - Replaced deprecated useSliceStore with a new useStore hook for better integration with the updated store architecture.
36
+ - Enhanced README documentation to reflect changes in project structure and build optimizations.
37
+
38
+ This update significantly improves the maintainability and scalability of the application, paving the way for future enhancements.
39
+
40
+ ## 0.4.1
41
+
42
+ ### Patch Changes
43
+
44
+ #### 🐞 Bug Fixes
45
+
46
+ - **create-app:** correct prettier version formatting in package.json.template ([dbd9336](https://github.com/qlover/fe-base/commit/dbd93366e04dcbbeba245d2dc28a7909957b58c3)) ([#428](https://github.com/qlover/fe-base/pull/428))
47
+
3
48
  ## 0.4.0
4
49
 
5
50
  ### Minor Changes
@@ -67,7 +67,7 @@
67
67
  "husky": "^9.1.7",
68
68
  "lint-staged": "^15.0.0",
69
69
  "postcss": "^8.4.49",
70
- "prettier": "^3.5.3",
70
+ "prettier": "^3.5.3"
71
71
  },
72
72
  "dependencies": {
73
73
  "@qlover/fe-corekit": "latest"
package/dist/index.js CHANGED
@@ -2378,7 +2378,7 @@ var Generator = class {
2378
2378
 
2379
2379
  // package.json
2380
2380
  var package_default = {
2381
- version: "0.4.0",
2381
+ version: "0.4.2",
2382
2382
  description: "Create a new app with a single command"};
2383
2383
  function programArgs() {
2384
2384
  const program = new Command();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlover/create-app",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Create a new app with a single command",
5
5
  "private": false,
6
6
  "type": "module",
@@ -10,7 +10,6 @@ FE_RELEASE=false
10
10
  FE_RELEASE_ENV=production
11
11
 
12
12
  # ===== build
13
- VITE_PUBLIC_PATH=
14
13
  VITE_SERVER_PORT=3200
15
14
 
16
15
  # ===== app config
@@ -21,5 +20,5 @@ VITE_OPEN_AI_TOKEN=sk-proj-1234567890
21
20
  VITE_OPEN_AI_TOKEN_PREFIX=Bearer
22
21
  VITE_OPEN_AI_REQUIRE_TOKEN=true
23
22
  VITE_LOGIN_USER=admin
24
- VITE_LOGIN_PASSWORD=123456
23
+ VITE_LOGIN_PASSWORD=prod-123456
25
24
  VITE_FE_API_BASE_URL=https://feapi.example.com/
@@ -85,7 +85,7 @@ pnpm test
85
85
  项目使用 `@brain-toolkit/ts2locales` 插件从 TypeScript 注释自动生成国际化资源:
86
86
 
87
87
  ```typescript
88
- // config/Identifier.I18n.ts
88
+ // config/Identifier/I18n.ts
89
89
  export const Messages = {
90
90
  /**
91
91
  * @description Home page welcome message
@@ -116,11 +116,11 @@ export default defineConfig({
116
116
  locales: i18nConfig.supportedLngs,
117
117
  options: [
118
118
  {
119
- source: './config/Identifier.Error.ts',
119
+ source: './config/Identifier/Error.ts',
120
120
  target: './public/locales/{{lng}}/common.json'
121
121
  },
122
122
  {
123
- source: './config/Identifier.I18n.ts',
123
+ source: './config/Identifier/I18n.ts',
124
124
  target: './public/locales/{{lng}}/common.json'
125
125
  }
126
126
  ]
@@ -147,7 +147,7 @@ await i18nService.changeLanguage('zh');
147
147
 
148
148
  ```typescript
149
149
  import { useBaseRoutePage } from '@/uikit/contexts/BaseRouteContext';
150
- import * as i18nKeys from '@config/Identifier.I18n';
150
+ import * as i18nKeys from '@config/Identifier/I18n';
151
151
 
152
152
  function MyComponent() {
153
153
  const { t } = useBaseRoutePage();
@@ -181,8 +181,8 @@ function Header() {
181
181
 
182
182
  1. 国际化标识符管理:
183
183
 
184
- - 在 `config/Identifier.I18n.ts` 中集中管理UI文本
185
- - 在 `config/Identifier.Error.ts` 中集中管理错误信息
184
+ - 在 `config/Identifier/I18n.ts` 中集中管理UI文本
185
+ - 在 `config/Identifier/Error.ts` 中集中管理错误信息
186
186
  - 使用有意义的 key 命名(如:'page.home.title')
187
187
 
188
188
  2. TypeScript 注释规范:
@@ -198,7 +198,7 @@ function Header() {
198
198
 
199
199
  4. 组件开发:
200
200
  - 使用 `useBaseRoutePage` hook 获取翻译函数
201
- - 从 `@config/Identifier.I18n` 引入国际化 key
201
+ - 从 `@config/Identifier/I18n` 引入国际化 key
202
202
  - 避免硬编码文本,始终使用国际化 key
203
203
 
204
204
  ### 主题系统
@@ -217,7 +217,7 @@ function Header() {
217
217
 
218
218
  ```typescript
219
219
  @injectable()
220
- export class RequestController extends SliceStore<RequestControllerState> {
220
+ export class RequestController extends StoreInterface<RequestControllerState> {
221
221
  constructor(
222
222
  @inject(FeApi) private readonly feApi: FeApi,
223
223
  @inject(UserApi) private readonly userApi: UserApi
@@ -375,3 +375,65 @@ const response = await api.request({
375
375
  1. 在 `public/locales` 添加翻译文件
376
376
  2. 使用 `useTranslation` hook 进行调用
377
377
  3. 支持按需加载语言包
378
+
379
+ ### 构建优化
380
+
381
+ 项目使用 Vite 进行构建,并进行了以下优化:
382
+
383
+ #### 代码分割
384
+
385
+ 自动进行智能代码分割,将代码分为以下几个主要块:
386
+
387
+ - react-vendor: React 核心库
388
+ - antd-core: Ant Design 核心组件
389
+ - antd-basic: 基础 UI 组件
390
+ - antd-advanced: 高级 UI 组件
391
+ - utils: 工具函数
392
+ - i18n: 国际化相关
393
+
394
+ #### 构建优化配置
395
+
396
+ ```typescript
397
+ build: {
398
+ // 分块大小警告限制设置为 600kb
399
+ chunkSizeWarningLimit: 600,
400
+ // 使用 terser 进行代码压缩
401
+ minify: 'terser',
402
+ terserOptions: {
403
+ compress: {
404
+ // 移除控制台输出和调试器语句
405
+ drop_console: true,
406
+ drop_debugger: true,
407
+ // 移除特定的控制台函数调用
408
+ pure_funcs: ['console.log', 'console.info', 'console.debug']
409
+ }
410
+ }
411
+ }
412
+ ```
413
+
414
+ ### 项目配置
415
+
416
+ #### 环境变量
417
+
418
+ - 使用 `@qlover/corekit-bridge/vite-env-config` 管理环境变量
419
+ - 自动注入应用名称和版本信息
420
+ - 支持环境变量前缀配置
421
+
422
+ #### 样式配置
423
+
424
+ - 集成 Tailwind CSS
425
+ - 按需加载 Ant Design 组件样式
426
+ - 支持主题模式覆盖
427
+
428
+ #### 开发服务器
429
+
430
+ ```bash
431
+ # 默认端口 3200,可通过环境变量配置
432
+ VITE_SERVER_PORT=3000 pnpm dev
433
+ ```
434
+
435
+ #### 测试配置
436
+
437
+ - 使用 Vitest 进行单元测试
438
+ - 支持 JSDOM 环境
439
+ - 内置测试工具配置
@@ -19,7 +19,7 @@
19
19
  "index": true,
20
20
  "element": "base/Home",
21
21
  "meta": {
22
- "title": "fe-utils/home",
22
+ "title": "page.home.title",
23
23
  "icon": "home",
24
24
  "localNamespace": "common"
25
25
  }
@@ -28,7 +28,7 @@
28
28
  "path": "about",
29
29
  "element": "base/About",
30
30
  "meta": {
31
- "title": "关于",
31
+ "title": "page.about.title",
32
32
  "icon": "info",
33
33
  "localNamespace": "common"
34
34
  }
@@ -37,7 +37,7 @@
37
37
  "path": "jsonStorage",
38
38
  "element": "base/JSONStorage",
39
39
  "meta": {
40
- "title": "FE-Utils JSONStorage",
40
+ "title": "page.jsonstorage.title",
41
41
  "icon": "info",
42
42
  "localNamespace": "common"
43
43
  }
@@ -46,7 +46,7 @@
46
46
  "path": "request",
47
47
  "element": "base/Request",
48
48
  "meta": {
49
- "title": "FE-Utils Request",
49
+ "title": "page.request.title",
50
50
  "icon": "info",
51
51
  "localNamespace": "common"
52
52
  }
@@ -55,7 +55,7 @@
55
55
  "path": "executor",
56
56
  "element": "base/Executor",
57
57
  "meta": {
58
- "title": "FE-Utils Executor",
58
+ "title": "page.executor.title",
59
59
  "icon": "info",
60
60
  "localNamespace": "common"
61
61
  }
@@ -64,7 +64,7 @@
64
64
  "path": "errorIdentifier",
65
65
  "element": "base/ErrorIdentifier",
66
66
  "meta": {
67
- "title": "FE-Utils ErrorIdentifier",
67
+ "title": "page.error_identifier.title",
68
68
  "icon": "info",
69
69
  "localNamespace": "common"
70
70
  }
@@ -74,7 +74,7 @@
74
74
  "element": "404",
75
75
  "meta": {
76
76
  "category": "common",
77
- "title": "404",
77
+ "title": "page.404.title",
78
78
  "layout": "blank",
79
79
  "localNamespace": "common"
80
80
  }
@@ -84,7 +84,7 @@
84
84
  "element": "500",
85
85
  "meta": {
86
86
  "category": "common",
87
- "title": "500",
87
+ "title": "page.500.title",
88
88
  "layout": "blank",
89
89
  "localNamespace": "common"
90
90
  }
@@ -107,7 +107,7 @@
107
107
  "path": "login",
108
108
  "element": "auth/Login",
109
109
  "meta": {
110
- "title": "登录",
110
+ "title": "page.login.title",
111
111
  "icon": "info",
112
112
  "localNamespace": "common"
113
113
  }
@@ -116,7 +116,7 @@
116
116
  "path": "register",
117
117
  "element": "auth/Register",
118
118
  "meta": {
119
- "title": "注册",
119
+ "title": "page.register.title",
120
120
  "icon": "info",
121
121
  "localNamespace": "common"
122
122
  }
@@ -129,7 +129,7 @@
129
129
  "element": "404",
130
130
  "meta": {
131
131
  "category": "common",
132
- "title": "404",
132
+ "title": "page.404.title",
133
133
  "layout": "blank",
134
134
  "localNamespace": "common"
135
135
  }
@@ -139,7 +139,7 @@
139
139
  "element": "500",
140
140
  "meta": {
141
141
  "category": "common",
142
- "title": "500",
142
+ "title": "page.500.title",
143
143
  "layout": "blank",
144
144
  "localNamespace": "common"
145
145
  }
@@ -149,7 +149,7 @@
149
149
  "element": "404",
150
150
  "meta": {
151
151
  "category": "common",
152
- "title": "404",
152
+ "title": "page.404.title",
153
153
  "layout": "blank",
154
154
  "localNamespace": "common"
155
155
  }
@@ -29,3 +29,11 @@ export const loggerStyles = {
29
29
  trace: { color: '#808080' },
30
30
  log: { color: '#000000' }
31
31
  };
32
+
33
+ /**
34
+ * 路由前缀
35
+ *
36
+ * - 需要以 / 开头
37
+ * - 但是不能只有 /
38
+ */
39
+ export const routerPrefix = '/router-root';
@@ -1,3 +1,5 @@
1
+ import { routerPrefix } from './common';
2
+
1
3
  export default {
2
4
  fallbackLng: 'en',
3
5
  debug: false,
@@ -7,7 +9,7 @@ export default {
7
9
  ns: ['common'],
8
10
  defaultNS: 'common',
9
11
  backend: {
10
- loadPath: '/locales/{{lng}}/{{ns}}.json'
12
+ loadPath: routerPrefix + '/locales/{{lng}}/{{ns}}.json'
11
13
  },
12
14
  supportedLngs: ['en', 'zh']
13
15
  } as const;