@qlover/create-app 0.4.1 → 0.4.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 (53) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/configs/_common/.gitignore.template +49 -23
  3. package/dist/index.js +1 -1
  4. package/package.json +1 -1
  5. package/templates/react-app/{.env → .env.template} +2 -3
  6. package/templates/react-app/README.md +89 -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/feapi.mock.json +8 -0
  10. package/templates/react-app/config/i18n.ts +3 -1
  11. package/templates/react-app/config/{Identifier.Error.ts → identifier/Error.ts} +7 -0
  12. package/templates/react-app/config/{Identifier.I18n.ts → identifier/I18n.ts} +321 -3
  13. package/templates/react-app/index.html +1 -1
  14. package/templates/react-app/package.json +3 -1
  15. package/templates/react-app/public/locales/en/common.json +55 -8
  16. package/templates/react-app/public/locales/zh/common.json +55 -8
  17. package/templates/react-app/public/router-root/logo.svg +1 -0
  18. package/templates/react-app/src/App.tsx +6 -3
  19. package/templates/react-app/src/base/cases/AppConfig.ts +1 -1
  20. package/templates/react-app/src/base/cases/PublicAssetsPath.ts +17 -0
  21. package/templates/react-app/src/base/port/LoginInterface.ts +8 -0
  22. package/templates/react-app/src/base/port/StoreInterface.ts +58 -0
  23. package/templates/react-app/src/base/services/I18nService.ts +15 -9
  24. package/templates/react-app/src/{uikit/controllers/RouterController.ts → base/services/RouteService.ts} +12 -12
  25. package/templates/react-app/src/{uikit/controllers/UserController.ts → base/services/UserService.ts} +29 -13
  26. package/templates/react-app/src/core/bootstrap.ts +1 -1
  27. package/templates/react-app/src/core/registers/RegisterCommon.ts +11 -1
  28. package/templates/react-app/src/core/registers/RegisterControllers.ts +3 -12
  29. package/templates/react-app/src/pages/auth/Layout.tsx +14 -6
  30. package/templates/react-app/src/pages/auth/Login.tsx +50 -29
  31. package/templates/react-app/src/pages/auth/Register.tsx +238 -1
  32. package/templates/react-app/src/pages/base/About.tsx +1 -1
  33. package/templates/react-app/src/pages/base/ErrorIdentifier.tsx +2 -2
  34. package/templates/react-app/src/pages/base/Executor.tsx +4 -4
  35. package/templates/react-app/src/pages/base/Home.tsx +1 -1
  36. package/templates/react-app/src/pages/base/JSONStorage.tsx +3 -3
  37. package/templates/react-app/src/pages/base/Request.tsx +4 -4
  38. package/templates/react-app/src/pages/base/components/BaseHeader.tsx +8 -2
  39. package/templates/react-app/src/styles/css/page.css +3 -3
  40. package/templates/react-app/src/styles/css/themes/_default.css +3 -3
  41. package/templates/react-app/src/styles/css/themes/dark.css +3 -3
  42. package/templates/react-app/src/styles/css/themes/pink.css +3 -3
  43. package/templates/react-app/src/uikit/components/LanguageSwitcher.tsx +7 -7
  44. package/templates/react-app/src/uikit/components/ThemeSwitcher.tsx +3 -3
  45. package/templates/react-app/src/uikit/contexts/BaseRouteContext.ts +1 -1
  46. package/templates/react-app/src/uikit/controllers/ExecutorController.ts +6 -3
  47. package/templates/react-app/src/uikit/controllers/JSONStorageController.ts +6 -3
  48. package/templates/react-app/src/uikit/controllers/RequestController.ts +3 -4
  49. package/templates/react-app/src/uikit/hooks/useDocumentTitle.ts +15 -0
  50. package/templates/react-app/src/uikit/hooks/useStore.ts +12 -0
  51. package/templates/react-app/src/uikit/providers/BaseRouteProvider.tsx +7 -1
  52. package/templates/react-app/src/uikit/providers/ProcessProvider.tsx +7 -7
  53. package/templates/react-app/vite.config.ts +20 -11
package/CHANGELOG.md CHANGED
@@ -1,5 +1,59 @@
1
1
  # @qlover/create-app
2
2
 
3
+ ## 0.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ #### ✨ Features
8
+
9
+ - **create-app:** enhance environment configuration and localization support ([76e5e22](https://github.com/qlover/fe-base/commit/76e5e22e41fe23ce109c303ca3974103f8a85cf6)) ([#432](https://github.com/qlover/fe-base/pull/432))
10
+
11
+ - Updated .gitignore to include .env files and added .env.template to the repository.
12
+ - Introduced a new .env.template file for environment variable configuration in the react-app template.
13
+ - Enhanced package.json scripts for development modes: added staging and production modes.
14
+ - Updated README.md to document environment variable usage with Vite.
15
+ - Added new error identifiers for token handling in Error.ts and updated UserService to utilize these identifiers.
16
+ - Improved localization files to include new keys for error messages related to token absence.
17
+
18
+ This update improves the application's configuration management and localization, enhancing developer experience and user feedback.
19
+
20
+ ## 0.4.2
21
+
22
+ ### Patch Changes
23
+
24
+ #### ✨ Features
25
+
26
+ - **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))
27
+
28
+ - Introduced a router prefix in the configuration to manage asset paths and API routes more effectively.
29
+ - Updated the application to utilize the new RouteService for routing logic, replacing the previous RouterController.
30
+ - Refactored user authentication handling to use UserService, improving modularity and maintainability.
31
+ - Added PublicAssetsPath service to manage public asset paths dynamically based on the router prefix.
32
+ - Updated localization files to include additional keys and ensure consistency across languages.
33
+ - Modified various components to integrate the new services and ensure proper routing and asset management.
34
+
35
+ This update enhances the overall structure and flexibility of the application, paving the way for future improvements.
36
+
37
+ - **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))
38
+
39
+ - Updated routing configuration to include localized titles for various pages, enhancing user experience.
40
+ - Added new keys for login and registration in localization files for both English and Chinese.
41
+ - Implemented a registration form with validation and user feedback, integrating with the UserService for account creation.
42
+ - Enhanced the Login component to utilize localized strings for better accessibility and clarity.
43
+ - Refactored the I18nService to support dynamic title updates based on the current route.
44
+
45
+ This update significantly improves the user interface and experience for authentication processes within the application.
46
+
47
+ - **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))
48
+
49
+ - Updated file structure for internationalization resources, moving identifiers to a new directory for better organization.
50
+ - Introduced new error and i18n identifier files to enhance localization support.
51
+ - Refactored store management by implementing a new StoreInterface, improving state management across services.
52
+ - Replaced deprecated useSliceStore with a new useStore hook for better integration with the updated store architecture.
53
+ - Enhanced README documentation to reflect changes in project structure and build optimizations.
54
+
55
+ This update significantly improves the maintainability and scalability of the application, paving the way for future enhancements.
56
+
3
57
  ## 0.4.1
4
58
 
5
59
  ### Patch Changes
@@ -1,32 +1,58 @@
1
- # Logs
2
- logs
3
- *.log
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+
3
+ # dependencies
4
+ node_modules
5
+ /.pnp
6
+ .pnp.js
7
+
8
+ # testing
9
+ /coverage
10
+
11
+ # next.js
12
+ /.next/
13
+ /out/
14
+
15
+ # production
16
+ /build
17
+
18
+ # misc
19
+ .DS_Store
20
+ *.pem
21
+
22
+ # debug
4
23
  npm-debug.log*
5
24
  yarn-debug.log*
6
25
  yarn-error.log*
7
- pnpm-debug.log*
8
- lerna-debug.log*
26
+ .pnpm-debug.log*
27
+
28
+ # local env files
29
+ .env*.*
30
+ !.env.template
31
+
32
+ # vercel
33
+ .vercel
9
34
 
10
- node_modules
11
- dist
12
- dist-ssr
13
- *.local
14
35
  # typescript
15
36
  *.tsbuildinfo
37
+ next-env.d.ts
16
38
 
17
- # Editor directories and files
18
- .vscode/*
19
- !.vscode/extensions.json
20
- .idea
21
- .DS_Store
22
- *.suo
23
- *.ntvs*
24
- *.njsproj
25
- *.sln
26
- *.sw?
39
+ .husky
40
+ !packages/create-app/configs/_common/.husky
41
+ public/robots.txt
42
+ public/sitemap*.xml
43
+ dist
44
+ .eslintcache
45
+ .npmrc
46
+ .secrets
47
+
48
+ # local output dir
49
+ *.output/
27
50
 
28
- # lock
51
+ # lock file
52
+ package-lock.json
29
53
  yarn.lock
30
- pnpm-lock.yaml
31
- pnpm-lock.yml
32
- package-lock.json
54
+
55
+ rollup.config-*.*js
56
+
57
+ .nx/cache
58
+ .nx/workspace-data
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.1",
2381
+ version: "0.4.3",
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.1",
3
+ "version": "0.4.3",
4
4
  "description": "Create a new app with a single command",
5
5
  "private": false,
6
6
  "type": "module",
@@ -10,16 +10,15 @@ 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
17
16
  VITE_USER_TOKEN_STORAGE_KEY=fe_user_token
18
17
  VITE_OPEN_AI_MODELS='["gpt-4o-mini","gpt-3.5-turbo","gpt-3.5-turbo-2","gpt-4","gpt-4-32k"]'
19
- VITE_OPEN_AI_BASE_URL=https://api.openai.com/v1
18
+ VITE_OPEN_AI_BASE_URL=
20
19
  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/
@@ -72,6 +72,25 @@ pnpm test
72
72
  - 支持服务自动注册和依赖管理
73
73
  - 提供完整的类型推导
74
74
 
75
+ ### env 配置注入
76
+
77
+ [vite 环境变量和模式](https://cn.vite.dev/guide/env-and-mode#env-variables-and-modes)
78
+
79
+ `vite dev` 默认 NODE_ENV 表示为 development, 他会加载可能的 `.env[mode]` 文件, 比如 .env.local -> .env
80
+
81
+ `vite build`默认 NODE_ENV 表示为 production, 他会加载可能的 `.env[mode]` 文件, 比如 .env.production -> .env
82
+
83
+ Nodejs NODE_ENV 只支持 development,production,test
84
+
85
+ 这个和 vite 中的 mode 是完全不一样的, mode 可以根据 `--mode` 指定不同模式,来加载不同的 env 配置
86
+
87
+ 比如:
88
+
89
+ ```bash
90
+ vite dev --mode staging # 加载 .env.staging
91
+ vite dev --mode local # 加载 .env.local
92
+ ```
93
+
75
94
  ### 国际化支持
76
95
 
77
96
  - 基于 i18next 的完整国际化解决方案
@@ -85,7 +104,7 @@ pnpm test
85
104
  项目使用 `@brain-toolkit/ts2locales` 插件从 TypeScript 注释自动生成国际化资源:
86
105
 
87
106
  ```typescript
88
- // config/Identifier.I18n.ts
107
+ // config/Identifier/I18n.ts
89
108
  export const Messages = {
90
109
  /**
91
110
  * @description Home page welcome message
@@ -116,11 +135,11 @@ export default defineConfig({
116
135
  locales: i18nConfig.supportedLngs,
117
136
  options: [
118
137
  {
119
- source: './config/Identifier.Error.ts',
138
+ source: './config/Identifier/Error.ts',
120
139
  target: './public/locales/{{lng}}/common.json'
121
140
  },
122
141
  {
123
- source: './config/Identifier.I18n.ts',
142
+ source: './config/Identifier/I18n.ts',
124
143
  target: './public/locales/{{lng}}/common.json'
125
144
  }
126
145
  ]
@@ -147,7 +166,7 @@ await i18nService.changeLanguage('zh');
147
166
 
148
167
  ```typescript
149
168
  import { useBaseRoutePage } from '@/uikit/contexts/BaseRouteContext';
150
- import * as i18nKeys from '@config/Identifier.I18n';
169
+ import * as i18nKeys from '@config/Identifier/I18n';
151
170
 
152
171
  function MyComponent() {
153
172
  const { t } = useBaseRoutePage();
@@ -181,8 +200,8 @@ function Header() {
181
200
 
182
201
  1. 国际化标识符管理:
183
202
 
184
- - 在 `config/Identifier.I18n.ts` 中集中管理UI文本
185
- - 在 `config/Identifier.Error.ts` 中集中管理错误信息
203
+ - 在 `config/Identifier/I18n.ts` 中集中管理UI文本
204
+ - 在 `config/Identifier/Error.ts` 中集中管理错误信息
186
205
  - 使用有意义的 key 命名(如:'page.home.title')
187
206
 
188
207
  2. TypeScript 注释规范:
@@ -198,7 +217,7 @@ function Header() {
198
217
 
199
218
  4. 组件开发:
200
219
  - 使用 `useBaseRoutePage` hook 获取翻译函数
201
- - 从 `@config/Identifier.I18n` 引入国际化 key
220
+ - 从 `@config/Identifier/I18n` 引入国际化 key
202
221
  - 避免硬编码文本,始终使用国际化 key
203
222
 
204
223
  ### 主题系统
@@ -217,7 +236,7 @@ function Header() {
217
236
 
218
237
  ```typescript
219
238
  @injectable()
220
- export class RequestController extends SliceStore<RequestControllerState> {
239
+ export class RequestController extends StoreInterface<RequestControllerState> {
221
240
  constructor(
222
241
  @inject(FeApi) private readonly feApi: FeApi,
223
242
  @inject(UserApi) private readonly userApi: UserApi
@@ -375,3 +394,65 @@ const response = await api.request({
375
394
  1. 在 `public/locales` 添加翻译文件
376
395
  2. 使用 `useTranslation` hook 进行调用
377
396
  3. 支持按需加载语言包
397
+
398
+ ### 构建优化
399
+
400
+ 项目使用 Vite 进行构建,并进行了以下优化:
401
+
402
+ #### 代码分割
403
+
404
+ 自动进行智能代码分割,将代码分为以下几个主要块:
405
+
406
+ - react-vendor: React 核心库
407
+ - antd-core: Ant Design 核心组件
408
+ - antd-basic: 基础 UI 组件
409
+ - antd-advanced: 高级 UI 组件
410
+ - utils: 工具函数
411
+ - i18n: 国际化相关
412
+
413
+ #### 构建优化配置
414
+
415
+ ```typescript
416
+ build: {
417
+ // 分块大小警告限制设置为 600kb
418
+ chunkSizeWarningLimit: 600,
419
+ // 使用 terser 进行代码压缩
420
+ minify: 'terser',
421
+ terserOptions: {
422
+ compress: {
423
+ // 移除控制台输出和调试器语句
424
+ drop_console: true,
425
+ drop_debugger: true,
426
+ // 移除特定的控制台函数调用
427
+ pure_funcs: ['console.log', 'console.info', 'console.debug']
428
+ }
429
+ }
430
+ }
431
+ ```
432
+
433
+ ### 项目配置
434
+
435
+ #### 环境变量
436
+
437
+ - 使用 `@qlover/corekit-bridge/vite-env-config` 管理环境变量
438
+ - 自动注入应用名称和版本信息
439
+ - 支持环境变量前缀配置
440
+
441
+ #### 样式配置
442
+
443
+ - 集成 Tailwind CSS
444
+ - 按需加载 Ant Design 组件样式
445
+ - 支持主题模式覆盖
446
+
447
+ #### 开发服务器
448
+
449
+ ```bash
450
+ # 默认端口 3200,可通过环境变量配置
451
+ VITE_SERVER_PORT=3000 pnpm dev
452
+ ```
453
+
454
+ #### 测试配置
455
+
456
+ - 使用 Vitest 进行单元测试
457
+ - 支持 JSDOM 环境
458
+ - 内置测试工具配置
@@ -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';
@@ -8,9 +8,17 @@
8
8
  "email": "john.doe@example.com",
9
9
  "picture": "https://randomuser.me/api/portraits/men/1.jpg"
10
10
  },
11
+ "GET /api/userinfo": {
12
+ "name": "John Doe",
13
+ "email": "john.doe@example.com",
14
+ "picture": "https://randomuser.me/api/portraits/men/1.jpg"
15
+ },
11
16
  "POST https://feapi.example.com/api/login": {
12
17
  "token": "asdfasdf123123asdfasdf"
13
18
  },
19
+ "POST /api/login": {
20
+ "token": "/api/login-token-adfasdfasdf"
21
+ },
14
22
  "POST https://api.openai.com/v1/chat/completions": {
15
23
  "id": "chatcmpl-1234567890",
16
24
  "object": "chat.completion",
@@ -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;
@@ -25,3 +25,10 @@ export const GLOBAL_NO_WINDOW = 'err.global.no.window';
25
25
  * @localEn Must be used in PageProvider
26
26
  */
27
27
  export const WITHIN_PAGE_PROVIDER = 'err.within.page.provider';
28
+
29
+ /**
30
+ * @description 响应内容没有 token 值
31
+ * @localZh 响应内容没有 token 值
32
+ * @localEn Response not token value
33
+ */
34
+ export const RES_NO_TOKEN = 'response.no.token';