generator-mico-cli 0.2.31 → 0.2.32

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 (162) hide show
  1. package/README.md +145 -18
  2. package/bin/mico.js +76 -0
  3. package/generators/h5-react/ignore-list.json +1 -0
  4. package/generators/h5-react/index.js +349 -0
  5. package/generators/h5-react/meta.json +11 -0
  6. package/generators/h5-react/templates/.commitlintrc.js +7 -0
  7. package/generators/h5-react/templates/.cursor/rules/cicd-deploy.mdc +104 -0
  8. package/generators/h5-react/templates/.cursor/rules/common-intl.mdc +42 -0
  9. package/generators/h5-react/templates/.cursor/rules/git-hooks.mdc +40 -0
  10. package/generators/h5-react/templates/.cursor/rules/internal-packages.mdc +46 -0
  11. package/generators/h5-react/templates/.cursor/rules/monorepo.mdc +64 -0
  12. package/generators/h5-react/templates/.cursor/rules/package-json.mdc +52 -0
  13. package/generators/h5-react/templates/.cursor/rules/tailwind-umi.mdc +60 -0
  14. package/generators/h5-react/templates/.cursor/rules/umi-app.mdc +74 -0
  15. package/generators/h5-react/templates/.cursor/rules/umi-config.mdc +86 -0
  16. package/generators/h5-react/templates/.cursor/rules/umi-mock.mdc +80 -0
  17. package/generators/h5-react/templates/.cursor/rules/workspace-request.mdc +52 -0
  18. package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/SKILL.md +213 -0
  19. package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/evals/evals.json +23 -0
  20. package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/cursor-rule-template.md +60 -0
  21. package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/phase-1-scanning.md +102 -0
  22. package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/phase-2-context-analysis.md +102 -0
  23. package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/phase-3-pattern-extraction.md +105 -0
  24. package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/phase-4-module-mapping.md +65 -0
  25. package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/phase-5-glossary.md +63 -0
  26. package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/templates/DEV_PATTERNS.tpl.md +77 -0
  27. package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/templates/GLOSSARY.tpl.md +17 -0
  28. package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/templates/MODULE_MAP.tpl.md +45 -0
  29. package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/templates/PROJECT_CONTEXT.tpl.md +155 -0
  30. package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/update-mode.md +116 -0
  31. package/generators/h5-react/templates/.env.development +5 -0
  32. package/generators/h5-react/templates/.env.production +5 -0
  33. package/generators/h5-react/templates/.env.testing +5 -0
  34. package/generators/h5-react/templates/.husky/commit-msg +2 -0
  35. package/generators/h5-react/templates/.husky/pre-commit +2 -0
  36. package/generators/h5-react/templates/.lintstagedrc.js +8 -0
  37. package/generators/h5-react/templates/.prettierrc.json +7 -0
  38. package/generators/h5-react/templates/CICD/before_build.sh +76 -0
  39. package/generators/h5-react/templates/CICD/start_dev.sh +54 -0
  40. package/generators/h5-react/templates/CICD/start_local.sh +30 -0
  41. package/generators/h5-react/templates/CICD/start_prod.sh +53 -0
  42. package/generators/h5-react/templates/CICD/start_test.sh +55 -0
  43. package/generators/h5-react/templates/CICD/wangsu_fresh_dev.sh +19 -0
  44. package/generators/h5-react/templates/CICD/wangsu_fresh_prod.sh +19 -0
  45. package/generators/h5-react/templates/CICD/wangsu_fresh_test.sh +19 -0
  46. package/generators/h5-react/templates/README.md +301 -0
  47. package/generators/h5-react/templates/_gitignore +30 -0
  48. package/generators/h5-react/templates/_npmrc +6 -0
  49. package/generators/h5-react/templates/apps/.gitkeep +0 -0
  50. package/generators/h5-react/templates/dev.preset.json +10 -0
  51. package/generators/h5-react/templates/package.json +56 -0
  52. package/generators/h5-react/templates/packages/common-intl/README.md +180 -0
  53. package/generators/h5-react/templates/packages/common-intl/eslint.config.ts +12 -0
  54. package/generators/h5-react/templates/packages/common-intl/package.json +31 -0
  55. package/generators/h5-react/templates/packages/common-intl/src/index.ts +3 -0
  56. package/generators/h5-react/templates/packages/common-intl/src/intl.ts +100 -0
  57. package/generators/h5-react/templates/packages/common-intl/tsconfig.json +3 -0
  58. package/generators/h5-react/templates/packages/components/eslint.config.ts +12 -0
  59. package/generators/h5-react/templates/packages/components/package.json +32 -0
  60. package/generators/h5-react/templates/packages/components/src/Layout/ImmersiveHeader.tsx +126 -0
  61. package/generators/h5-react/templates/packages/components/src/Layout/LayoutFooter.tsx +72 -0
  62. package/generators/h5-react/templates/packages/components/src/Layout/index.tsx +121 -0
  63. package/generators/h5-react/templates/packages/components/src/assets/image/back.png +0 -0
  64. package/generators/h5-react/templates/packages/components/src/index.ts +0 -0
  65. package/generators/h5-react/templates/packages/components/tsconfig.json +13 -0
  66. package/generators/h5-react/templates/packages/components/typings.d.ts +1 -0
  67. package/generators/h5-react/templates/packages/constant/eslint.config.ts +12 -0
  68. package/generators/h5-react/templates/packages/constant/package.json +19 -0
  69. package/generators/h5-react/templates/packages/constant/src/index.ts +0 -0
  70. package/generators/h5-react/templates/packages/constant/src/member.ts +8 -0
  71. package/generators/h5-react/templates/packages/constant/tsconfig.json +3 -0
  72. package/generators/h5-react/templates/packages/deeplink/eslint.config.ts +12 -0
  73. package/generators/h5-react/templates/packages/deeplink/package.json +18 -0
  74. package/generators/h5-react/templates/packages/deeplink/src/index.ts +7 -0
  75. package/generators/h5-react/templates/packages/deeplink/tsconfig.json +3 -0
  76. package/generators/h5-react/templates/packages/domain/eslint.config.ts +12 -0
  77. package/generators/h5-react/templates/packages/domain/package.json +18 -0
  78. package/generators/h5-react/templates/packages/domain/src/index.ts +29 -0
  79. package/generators/h5-react/templates/packages/domain/tsconfig.json +3 -0
  80. package/generators/h5-react/templates/packages/domain/types.d.ts +11 -0
  81. package/generators/h5-react/templates/packages/eslint/eslint.config.base.ts +36 -0
  82. package/generators/h5-react/templates/packages/eslint/eslint.config.react.ts +33 -0
  83. package/generators/h5-react/templates/packages/eslint/package.json +22 -0
  84. package/generators/h5-react/templates/packages/js-bridge/eslint.config.ts +17 -0
  85. package/generators/h5-react/templates/packages/js-bridge/package.json +23 -0
  86. package/generators/h5-react/templates/packages/js-bridge/src/call.ts +126 -0
  87. package/generators/h5-react/templates/packages/js-bridge/src/closeH5Page.ts +9 -0
  88. package/generators/h5-react/templates/packages/js-bridge/src/getUserInfo.ts +96 -0
  89. package/generators/h5-react/templates/packages/js-bridge/src/index.ts +15 -0
  90. package/generators/h5-react/templates/packages/js-bridge/tsconfig.json +3 -0
  91. package/generators/h5-react/templates/packages/js-bridge/type.d.ts +24 -0
  92. package/generators/h5-react/templates/packages/request/axios.d.ts +42 -0
  93. package/generators/h5-react/templates/packages/request/eslint.config.ts +17 -0
  94. package/generators/h5-react/templates/packages/request/package.json +22 -0
  95. package/generators/h5-react/templates/packages/request/src/index.ts +165 -0
  96. package/generators/h5-react/templates/packages/request/src/interceptors.ts +126 -0
  97. package/generators/h5-react/templates/packages/request/src/types.ts +101 -0
  98. package/generators/h5-react/templates/packages/request/src/url-resolver.ts +66 -0
  99. package/generators/h5-react/templates/packages/request/src/utils.ts +12 -0
  100. package/generators/h5-react/templates/packages/request/tsconfig.json +3 -0
  101. package/generators/h5-react/templates/packages/request/umi.d.ts +94 -0
  102. package/generators/h5-react/templates/packages/typescript/package.json +11 -0
  103. package/generators/h5-react/templates/packages/typescript/tsconfig.base.json +23 -0
  104. package/generators/h5-react/templates/packages/typescript/tsconfig.react.json +7 -0
  105. package/generators/h5-react/templates/packages/umi-config/eslint.config.ts +12 -0
  106. package/generators/h5-react/templates/packages/umi-config/package.json +31 -0
  107. package/generators/h5-react/templates/packages/umi-config/src/config.dev.ts +34 -0
  108. package/generators/h5-react/templates/packages/umi-config/src/config.prod.development.ts +17 -0
  109. package/generators/h5-react/templates/packages/umi-config/src/config.prod.production.ts +42 -0
  110. package/generators/h5-react/templates/packages/umi-config/src/config.prod.testing.ts +17 -0
  111. package/generators/h5-react/templates/packages/umi-config/src/config.prod.ts +56 -0
  112. package/generators/h5-react/templates/packages/umi-config/src/config.ts +86 -0
  113. package/generators/h5-react/templates/packages/umi-config/src/index.ts +25 -0
  114. package/generators/h5-react/templates/packages/umi-config/src/plugins/apply-sentry-plugin.ts +57 -0
  115. package/generators/h5-react/templates/packages/umi-config/src/type.d.ts +3 -0
  116. package/generators/h5-react/templates/packages/umi-config/tsconfig.json +3 -0
  117. package/generators/h5-react/templates/packages/utils/eslint.config.ts +12 -0
  118. package/generators/h5-react/templates/packages/utils/package.json +27 -0
  119. package/generators/h5-react/templates/packages/utils/src/date.ts +21 -0
  120. package/generators/h5-react/templates/packages/utils/src/env.ts +40 -0
  121. package/generators/h5-react/templates/packages/utils/src/index.ts +3 -0
  122. package/generators/h5-react/templates/packages/utils/src/md5.ts +17 -0
  123. package/generators/h5-react/templates/packages/utils/src/mock.ts +83 -0
  124. package/generators/h5-react/templates/packages/utils/src/number.ts +23 -0
  125. package/generators/h5-react/templates/packages/utils/src/tailwind.ts +12 -0
  126. package/generators/h5-react/templates/packages/utils/src/url.ts +19 -0
  127. package/generators/h5-react/templates/packages/utils/tsconfig.json +9 -0
  128. package/generators/h5-react/templates/page.config.ts +1 -0
  129. package/generators/h5-react/templates/pnpm-workspace.yaml +17 -0
  130. package/generators/h5-react/templates/scripts/collect-dist.js +78 -0
  131. package/generators/h5-react/templates/scripts/dev-preset.js +265 -0
  132. package/generators/h5-react/templates/scripts/dev-preset.schema.json +39 -0
  133. package/generators/h5-react/templates/scripts/dev.js +133 -0
  134. package/generators/h5-react/templates/scripts/gateway.ts +241 -0
  135. package/generators/h5-react/templates/turbo.json +86 -0
  136. package/generators/subapp-h5/ignore-list.json +1 -0
  137. package/generators/subapp-h5/index.js +424 -0
  138. package/generators/subapp-h5/meta.json +10 -0
  139. package/generators/subapp-h5/templates/.env +1 -0
  140. package/generators/subapp-h5/templates/.stylelintrc.js +22 -0
  141. package/generators/subapp-h5/templates/config/config.dev.ts +7 -0
  142. package/generators/subapp-h5/templates/config/config.prod.development.ts +7 -0
  143. package/generators/subapp-h5/templates/config/config.prod.production.ts +10 -0
  144. package/generators/subapp-h5/templates/config/config.prod.testing.ts +7 -0
  145. package/generators/subapp-h5/templates/config/config.prod.ts +7 -0
  146. package/generators/subapp-h5/templates/config/config.ts +6 -0
  147. package/generators/subapp-h5/templates/config/routes.ts +13 -0
  148. package/generators/subapp-h5/templates/eslint.config.ts +12 -0
  149. package/generators/subapp-h5/templates/mock/user.ts +34 -0
  150. package/generators/subapp-h5/templates/package.json +42 -0
  151. package/generators/subapp-h5/templates/src/app.tsx +14 -0
  152. package/generators/subapp-h5/templates/src/assets/yay.jpg +0 -0
  153. package/generators/subapp-h5/templates/src/intl.ts +37 -0
  154. package/generators/subapp-h5/templates/src/layouts/index.tsx +10 -0
  155. package/generators/subapp-h5/templates/src/pages/index.tsx +22 -0
  156. package/generators/subapp-h5/templates/src/services/user.ts +38 -0
  157. package/generators/subapp-h5/templates/tailwind.config.js +16 -0
  158. package/generators/subapp-h5/templates/tailwind.css +7 -0
  159. package/generators/subapp-h5/templates/tsconfig.json +3 -0
  160. package/generators/subapp-h5/templates/typings.d.ts +1 -0
  161. package/lib/setup-multica-desktop.js +154 -0
  162. package/package.json +1 -1
@@ -0,0 +1,94 @@
1
+ declare module 'umi' {
2
+ type WithPromise<T> = T | Promise<T>;
3
+
4
+ type AxiosResponse = import('./axios.d').AxiosResponse;
5
+ type AxiosError = import('./axios.d').AxiosError;
6
+ type AxiosInstance = import('./axios.d').AxiosInstance;
7
+ type RequestError = import('./axios.d').RequestError;
8
+ type AxiosRequestConfig = import('./axios.d').AxiosRequestConfig;
9
+
10
+ export type RequestInterceptorAxios = (
11
+ config: RequestOptions,
12
+ ) => WithPromise<RequestOptions>;
13
+
14
+ export type RequestInterceptorUmiRequest = (
15
+ url: string,
16
+ config: RequestOptions,
17
+ ) => WithPromise<{ url: string; options: RequestOptions }>;
18
+
19
+ export type RequestInterceptor =
20
+ | RequestInterceptorAxios
21
+ | RequestInterceptorUmiRequest;
22
+
23
+ export type ErrorInterceptor = (error: Error) => Promise<Error>;
24
+
25
+ export type ResponseInterceptor = <T = any>(
26
+ response: AxiosResponse<T>,
27
+ ) => WithPromise<AxiosResponse<T>>;
28
+
29
+ export type RequestInterceptorTuple =
30
+ | [RequestInterceptor, ErrorInterceptor]
31
+ | [RequestInterceptor]
32
+ | RequestInterceptor;
33
+
34
+ export type ResponseInterceptorTuple =
35
+ | [ResponseInterceptor, ErrorInterceptor]
36
+ | [ResponseInterceptor]
37
+ | ResponseInterceptor;
38
+
39
+ export type RequestOptions = AxiosRequestConfig & {
40
+ skipErrorHandler?: boolean;
41
+ requestInterceptors?: RequestInterceptorTuple[];
42
+ responseInterceptors?: ResponseInterceptorTuple[];
43
+ getResponse?: boolean;
44
+ };
45
+
46
+ export type RequestConfig<T = any> = RequestOptions & {
47
+ errorConfig?: {
48
+ errorHandler?: (error: RequestError, opts: RequestOptions) => void;
49
+ errorThrower?: (res: T) => void;
50
+ };
51
+ };
52
+
53
+ export interface Request {
54
+ <T = any>(
55
+ url: string,
56
+ opts: RequestOptions & { getResponse: true },
57
+ ): Promise<AxiosResponse<T>>;
58
+ <T = any>(
59
+ url: string,
60
+ opts: RequestOptions & { getResponse: false },
61
+ ): Promise<T>;
62
+ <T = any>(url: string, opts?: RequestOptions): Promise<T>;
63
+ <T = any>(url: string): Promise<T>;
64
+ }
65
+
66
+ export const request: Request;
67
+
68
+ export type UseRequestService<R = any, P extends any[] = any[]> = (
69
+ ...args: P
70
+ ) => R | Promise<R>;
71
+
72
+ export type UseRequestResult<R = any, P extends any[] = any[]> = {
73
+ data?: R;
74
+ error?: Error;
75
+ loading: boolean;
76
+ params: P;
77
+ run: (...args: P) => Promise<R>;
78
+ runAsync: (...args: P) => Promise<R>;
79
+ refresh: () => void;
80
+ refreshAsync: () => Promise<R>;
81
+ mutate: (data?: R | ((oldData?: R) => R)) => void;
82
+ cancel: () => void;
83
+ [key: string]: any;
84
+ };
85
+
86
+ export const useRequest: <R = any, P extends any[] = any[]>(
87
+ service: UseRequestService<R, P>,
88
+ options?: any,
89
+ ) => UseRequestResult<R, P>;
90
+
91
+ export const UseRequestProvider: any;
92
+
93
+ export const getRequestInstance: () => AxiosInstance;
94
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "<%= packageScope %>/typescript",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "main": "./tsconfig.base.json",
7
+ "exports": {
8
+ ".": "./tsconfig.base.json",
9
+ "./react": "./tsconfig.react.json"
10
+ }
11
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "esModuleInterop": true,
10
+ "module": "esnext",
11
+ "moduleResolution": "bundler",
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "incremental": true,
15
+ "baseUrl": "../../",
16
+ "paths": {
17
+ "@/*": ["${configDir}/src/*"],
18
+ // "<%= packageScope %>/*": ["./packages/*"]
19
+ }
20
+ },
21
+ "exclude": ["node_modules"]
22
+ }
23
+
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "jsx": "react-jsx"
5
+ },
6
+ }
7
+
@@ -0,0 +1,12 @@
1
+ import baseConfig from '<%= packageScope %>/eslint';
2
+ import { defineConfig } from 'eslint/config';
3
+ export default defineConfig([
4
+ ...baseConfig,
5
+ {
6
+ languageOptions: {
7
+ parserOptions: {
8
+ tsconfigRootDir: import.meta.dirname,
9
+ },
10
+ },
11
+ },
12
+ ]);
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "<%= packageScope %>/umi-config",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "scripts": {
8
+ "lint": "eslint",
9
+ "lint:fix": "eslint --fix",
10
+ "postinstall": "umi setup",
11
+ "setup": "umi setup"
12
+ },
13
+ "exports": {
14
+ ".": "./src/index.ts",
15
+ "./config": "./src/config.ts",
16
+ "./config.dev": "./src/config.dev.ts",
17
+ "./config.prod.development": "./src/config.prod.development.ts",
18
+ "./config.prod": "./src/config.prod.ts",
19
+ "./config.prod.production": "./src/config.prod.production.ts",
20
+ "./config.prod.testing": "./src/config.prod.testing.ts"
21
+ },
22
+ "dependencies": {
23
+ "postcss-pxtorem": "^6.1.0"
24
+ },
25
+ "devDependencies": {
26
+ "umi": "catalog:",
27
+ "<%= packageScope %>/eslint": "workspace:^",
28
+ "@sentry/webpack-plugin": "^4.9.1",
29
+ "@types/postcss-pxtorem": "^6.1.0"
30
+ }
31
+ }
@@ -0,0 +1,34 @@
1
+ // https://umijs.org/config/
2
+
3
+ import { defineConfig } from 'umi';
4
+
5
+ // ts
6
+ import type { UmiConfig } from './type';
7
+
8
+ const DEFAULT_PROXY = {
9
+ // 接口
10
+ '/api': {
11
+ target: 'https://api-test.micoplatform.com',
12
+ changeOrigin: true,
13
+ pathRewrite: {
14
+ '^/api': '',
15
+ },
16
+ },
17
+ };
18
+
19
+ /**
20
+ * @name dev 模式专属配置
21
+ * @description 仅产出 `umi dev` 阶段的 delta(默认 `/api` 代理);
22
+ * 基础配置(mountElementId / 插件 / `monorepoRedirect` / ...)由子应用
23
+ * `config/config.ts` 中的 {@link import('./config').createBaseConfig} 提供,
24
+ * Umi 在加载时按 `config.ts` < `config.dev.ts` 顺序合并。
25
+ */
26
+ export function createDevConfig(options: UmiConfig = {}): UmiConfig {
27
+ return defineConfig({
28
+ ...options,
29
+ proxy: {
30
+ ...DEFAULT_PROXY,
31
+ ...(options.proxy ?? {}),
32
+ },
33
+ });
34
+ }
@@ -0,0 +1,17 @@
1
+ // https://umijs.org/config/
2
+
3
+ import { defineConfig } from 'umi';
4
+
5
+ // ts
6
+ import type { UmiConfig } from './type';
7
+
8
+ /**
9
+ * @name development 构建配置(`UMI_ENV=development`)
10
+ * @description 仅产出 development 环境的 delta;当前不上传 sourcemap、不挂 Sentry 插件,
11
+ * 故默认为空(保留扩展点)。构建公共 delta 由子应用 `config/config.prod.ts`
12
+ * 通过 {@link import('./config.prod').createProConfig} 注入;基础配置由
13
+ * `config/config.ts` 提供。
14
+ */
15
+ export function createDevelopmentConfig(options: UmiConfig = {}): UmiConfig {
16
+ return defineConfig(options);
17
+ }
@@ -0,0 +1,42 @@
1
+ // https://umijs.org/config/
2
+
3
+ import { defineConfig } from 'umi';
4
+ import { applySentryPlugin } from './plugins/apply-sentry-plugin';
5
+
6
+ //ts
7
+ import type { UmiConfig } from './type';
8
+
9
+ export interface ProductionConfigOptions {
10
+ /**
11
+ * @name 应用名称
12
+ * @description 用于 Sentry sourcemap 上传的 `urlPrefix` 段;与 `apps/<目录>/package.json` 的
13
+ * `name` 一致;同时与子应用 `config/config.prod.ts` 中传给 `createProConfig` 的
14
+ * `appName` 保持一致
15
+ */
16
+ appName: string;
17
+ }
18
+
19
+ /**
20
+ * @name production 构建配置(`UMI_ENV=production`)
21
+ * @description 仅产出 production 环境的 delta:`hidden-source-map` + Sentry sourcemap 上传。
22
+ * 构建公共 delta 由子应用 `config/config.prod.ts` 通过
23
+ * {@link import('./config.prod').createProConfig} 注入;基础配置由
24
+ * `config/config.ts` 提供。
25
+ */
26
+ export function createProductionConfig(
27
+ { appName }: ProductionConfigOptions,
28
+ options: UmiConfig = {},
29
+ ): UmiConfig {
30
+ return defineConfig({
31
+ ...options,
32
+ devtool: 'hidden-source-map',
33
+ chainWebpack(memo, args) {
34
+ memo.optimization.runtimeChunk(false);
35
+ memo.plugins.delete('runtimePublicPath');
36
+ memo.output.chunkFilename('[name].[contenthash:8].async.js');
37
+ applySentryPlugin({ memo, appName });
38
+ options.chainWebpack?.(memo, args);
39
+ return memo;
40
+ },
41
+ });
42
+ }
@@ -0,0 +1,17 @@
1
+ // https://umijs.org/config/
2
+
3
+ import { defineConfig } from 'umi';
4
+
5
+ // ts
6
+ import type { UmiConfig } from './type';
7
+
8
+ /**
9
+ * @name testing 构建配置(`UMI_ENV=testing`)
10
+ * @description 仅产出 testing 环境的 delta;当前不上传 sourcemap、不挂 Sentry 插件,
11
+ * 故默认为空(保留扩展点)。构建公共 delta 由子应用 `config/config.prod.ts`
12
+ * 通过 {@link import('./config.prod').createProConfig} 注入;基础配置由
13
+ * `config/config.ts` 提供。
14
+ */
15
+ export function createTestingConfig(options: UmiConfig = {}): UmiConfig {
16
+ return defineConfig(options);
17
+ }
@@ -0,0 +1,56 @@
1
+ // https://umijs.org/config/
2
+ import { defineConfig } from 'umi';
3
+
4
+ // ts
5
+ import type { UmiConfig } from './type';
6
+
7
+ export interface ProConfigOptions {
8
+ /**
9
+ * @name 应用名称
10
+ * @description 用于 `publicPath` / `cssPublicPath` 拼接,与 `apps/<目录>/package.json` 的 `name` 一致;
11
+ * 同时作为 Sentry sourcemap 上传的 `urlPrefix` 段
12
+ */
13
+ appName: string;
14
+ }
15
+
16
+ /**
17
+ * @name 构建公共配置
18
+ * @description 仅产出构建阶段共享的 delta:`publicPath: 'auto'` / `cssPublicPath: './'`、
19
+ * `externals`(react / react-dom / @common-web/sentry)、
20
+ * `chainWebpack` 中 `runtimeChunk(false)` + 删除 `runtimePublicPath` 插件 +
21
+ * 自定义异步 chunk 文件名(runtime 内联进入口 `umi.js`,宿主页只引一个入口 JS,
22
+ * 动态 `import()` 仍可按需切片,由 webpack 5 按 `document.currentScript.src` 解析 publicPath)。
23
+ */
24
+ export function createProConfig(options: UmiConfig = {}): UmiConfig {
25
+ return defineConfig({
26
+ publicPath: 'auto',
27
+ cssPublicPath: './',
28
+
29
+ /**
30
+ * @name 外部依赖配置
31
+ * @description 将大型公共库排除打包,运行时从主应用获取
32
+ * @doc https://umijs.org/docs/api/config#externals
33
+ */
34
+ externals: {
35
+ react: 'React',
36
+ 'react-dom': 'ReactDOM',
37
+ '@common-web/sentry': 'CommonWebSentry',
38
+ },
39
+ ...options,
40
+
41
+ /**
42
+ * @name 代码分割策略
43
+ * @description
44
+ * - `runtimeChunk(false)`:webpack runtime **必须内联进入口 `umi.js`**,宿主页只引一个入口 JS
45
+ * - 删除 `runtimePublicPath`:避免 Umi 用 `window.publicPath` 写空字符串覆盖 `publicPath: 'auto'`
46
+ * 异步 chunk 会沿用 webpack 5 按 `document.currentScript.src` 推算出的 publicPath
47
+ */
48
+ chainWebpack(memo, args) {
49
+ memo.optimization.runtimeChunk(false);
50
+ memo.plugins.delete('runtimePublicPath');
51
+ memo.output.chunkFilename('[name].[contenthash:8].async.js');
52
+ options.chainWebpack?.(memo, args);
53
+ return memo;
54
+ },
55
+ });
56
+ }
@@ -0,0 +1,86 @@
1
+ // https://umijs.org/config/
2
+
3
+ import postcssPxtorem from 'postcss-pxtorem';
4
+ import { defineConfig } from 'umi';
5
+
6
+ // ts
7
+ import type { UmiConfig } from './type';
8
+
9
+ /**
10
+ * @name 应用基础配置
11
+ * @description 子应用 `config/config.ts` 的入口;包含 dev / build 都会用到的全部公共字段
12
+ * (挂载点、history、Tailwind / request 插件、`monorepoRedirect`、`postcss-pxtorem` 等,
13
+ * `codeSplitting` 沿用 Umi 默认 `bigVendors` 策略,不在此显式声明)。
14
+ * `config.dev` / `config.prod.development` / `config.prod.testing` / `config.prod.production` 仅产出
15
+ * 对应环境的 delta,由 Umi 在加载时与本配置浅合并。
16
+ */
17
+ export function createBaseConfig(options: UmiConfig = {}): UmiConfig {
18
+ return defineConfig({
19
+ /**
20
+ * @name 挂载元素 ID
21
+ * @description React 应用挂载的 DOM 元素 id
22
+ */
23
+ mountElementId: 'root',
24
+
25
+ publicPath: '/',
26
+
27
+ /**
28
+ * @name 基础路径
29
+ * @description 子应用的路由前缀
30
+ */
31
+ base: '/',
32
+
33
+ /**
34
+ * @name 路由历史模式
35
+ * @description 使用 Hash 路由(URL 形如 `/#/path`),无需服务端 fallback
36
+ */
37
+ history: { type: 'hash' },
38
+
39
+ /**
40
+ * @name 构建产物文件名 hash
41
+ * @description 为静态资源文件名追加内容 hash,利于缓存与更新
42
+ */
43
+ hash: false,
44
+
45
+ /**
46
+ * @name Tailwind CSS / Request 插件
47
+ * @doc https://umijs.org/docs/max/tailwindcss
48
+ */
49
+ plugins: ['@umijs/plugins/dist/tailwindcss', '@umijs/plugins/dist/request'],
50
+ tailwindcss: {},
51
+ request: {},
52
+
53
+ monorepoRedirect: {
54
+ srcDir: ['src'],
55
+ peerDeps: true,
56
+ },
57
+ mfsu: false,
58
+
59
+ /**
60
+ * @name moment 的国际化配置
61
+ */
62
+ ignoreMomentLocale: true,
63
+
64
+ /**
65
+ * @name 快速热更新配置
66
+ */
67
+ fastRefresh: true,
68
+
69
+ /**
70
+ * @name 其他配置
71
+ */
72
+ esbuildMinifyIIFE: true,
73
+
74
+ define: {
75
+ 'process.env.NODE_ENV': process.env.NODE_ENV,
76
+ },
77
+ extraPostCSSPlugins: [
78
+ postcssPxtorem({
79
+ rootValue: 16,
80
+ propList: ['*'],
81
+ minPixelValue: 2,
82
+ }),
83
+ ],
84
+ ...options,
85
+ });
86
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * <%= projectName %>/umi-config
3
+ *
4
+ * 子应用 Umi 配置工厂。Umi 在加载时按
5
+ * config.ts < config.[UMI_ENV].ts < config.[dev|prod].ts < config.[dev|prod].[UMI_ENV].ts 的优先级**叠加合并**,
6
+ * 因此本包遵循"基础 + 环境 delta"的拆分;6 个工厂彼此**无继承**,由 Umi 在
7
+ * 子应用 config 目录加载时按文件名约定自然合并:
8
+ *
9
+ * - config → 子应用 config/config.ts 的入口(基础公共配置 + 路由)
10
+ * - config.dev → umi dev 阶段(dev 专属 delta,仅默认 /api 代理)
11
+ * - config.prod → umi build 阶段公共 delta(PUBLIC_PATH / chainWebpack / externals 等)
12
+ * - config.prod.development → UMI_ENV=development umi build(环境专属 delta,当前为空)
13
+ * - config.prod.testing → UMI_ENV=testing umi build(环境专属 delta,当前为空)
14
+ * - config.prod.production → UMI_ENV=production umi build(环境专属 delta:sourcemap + Sentry)
15
+ */
16
+
17
+ export { createBaseConfig } from './config';
18
+ export { createDevConfig } from './config.dev';
19
+ export { createProConfig, type ProConfigOptions } from './config.prod';
20
+ export { createDevelopmentConfig } from './config.prod.development';
21
+ export {
22
+ createProductionConfig,
23
+ type ProductionConfigOptions,
24
+ } from './config.prod.production';
25
+ export { createTestingConfig } from './config.prod.testing';
@@ -0,0 +1,57 @@
1
+ import { sentryWebpackPlugin } from '@sentry/webpack-plugin';
2
+ import { version } from '../../../../package.json';
3
+
4
+ import { defineConfig } from 'umi';
5
+ type ChainWebpack = Parameters<typeof defineConfig>[0]['chainWebpack'] & {};
6
+ type Memo = Parameters<ChainWebpack>[0];
7
+
8
+ interface ApplySentryPluginOptions {
9
+ /** webpack-chain 实例(Umi chainWebpack 的参数) */
10
+ memo: Memo;
11
+ /** 应用名称,用于 urlPrefix 路径 */
12
+ appName: string;
13
+ /** Sentry project 名称,默认 '<%= projectName %>' */
14
+ project?: string;
15
+ }
16
+
17
+ /**
18
+ * 往 webpack-chain 配置上挂载 Sentry sourcemap 上传插件
19
+ */
20
+ export function applySentryPlugin({
21
+ memo,
22
+ appName,
23
+ project = '<%= projectName %>',
24
+ }: ApplySentryPluginOptions) {
25
+ // 使用 Legacy Upload 方式,自托管 Sentry 不支持 Debug ID / Artifact Bundle
26
+ memo.plugin('sentry').use(
27
+ class {
28
+ apply(compiler: unknown) {
29
+ sentryWebpackPlugin({
30
+ url: 'https://sentry.micoworld.net',
31
+ org: 'micocenter',
32
+ project,
33
+ authToken: process.env.SENTRY_AUTH_TOKEN,
34
+ release: {
35
+ name: version,
36
+ uploadLegacySourcemaps: {
37
+ // source map 文件路径
38
+ paths: ['./dist'],
39
+ ignore: ['node_modules'],
40
+ ext: ['js', 'map'],
41
+ // URL 前缀
42
+ urlPrefix: `~/<%= cdnPrefixPath %><%= projectName %>/${version}/${appName}`,
43
+ },
44
+ },
45
+ sourcemaps: {
46
+ disable: true,
47
+ // 上传后删除的 source map 文件
48
+ filesToDeleteAfterUpload: ['dist/**/*.map'],
49
+ },
50
+ errorHandler: (err: Error) => {
51
+ console.warn('SentryCliPlugin error:', err);
52
+ },
53
+ }).apply(compiler);
54
+ }
55
+ },
56
+ );
57
+ }
@@ -0,0 +1,3 @@
1
+ import { defineConfig } from 'umi';
2
+
3
+ export type UmiConfig = ReturnType<typeof defineConfig>;
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "./src/.umi/tsconfig.json"
3
+ }
@@ -0,0 +1,12 @@
1
+ import baseConfig from '<%= packageScope %>/eslint';
2
+ import { defineConfig } from 'eslint/config';
3
+ export default defineConfig([
4
+ ...baseConfig,
5
+ {
6
+ languageOptions: {
7
+ parserOptions: {
8
+ tsconfigRootDir: import.meta.dirname,
9
+ },
10
+ },
11
+ },
12
+ ]);
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "<%= packageScope %>/utils",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "scripts": {
8
+ "lint": "eslint",
9
+ "lint:fix": "eslint --fix"
10
+ },
11
+ "exports": {
12
+ ".": "./src/index.ts",
13
+ "./*": "./src/*.ts"
14
+ },
15
+ "dependencies": {
16
+ "class-variance-authority": "^0.7.1",
17
+ "clsx": "^2.1.1",
18
+ "dayjs": "^1.11.20",
19
+ "spark-md5": "^3.0.2",
20
+ "tailwind-merge": "^3.5.0"
21
+ },
22
+ "devDependencies": {
23
+ "<%= packageScope %>/eslint": "workspace:^",
24
+ "<%= packageScope %>/typescript": "workspace:^",
25
+ "@types/spark-md5": "^3.0.5"
26
+ }
27
+ }
@@ -0,0 +1,21 @@
1
+ import dayjs, { type ConfigType } from 'dayjs';
2
+
3
+ /**
4
+ * 格式化日期
5
+ * @param date 日期
6
+ * @param format 格式
7
+ * @returns 格式化后的日期
8
+ */
9
+ export function formatDate(date: ConfigType, format: string = 'YYYY.MM.DD') {
10
+ return dayjs(date).format(format);
11
+ }
12
+
13
+ /**
14
+ * 格式化日期(秒)
15
+ * @param Second 秒
16
+ * @param format 格式
17
+ * @returns 格式化后的日期
18
+ */
19
+ export function formatDateBySecond(Second: number, format?: string) {
20
+ return formatDate(Second * 1000, format);
21
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * 是否是开发环境
3
+ */
4
+ export const isDev = process.env.UMI_APP_ENV === 'development';
5
+
6
+ /**
7
+ * 是否是测试环境
8
+ */
9
+ export const isTest = process.env.UMI_APP_ENV === 'testing';
10
+
11
+ /**
12
+ * 是否是生产环境
13
+ */
14
+ export const isProd = process.env.UMI_APP_ENV === 'production';
15
+
16
+ /**
17
+ * 是否是调试环境
18
+ */
19
+ export const isDebug = isDev || isTest;
20
+
21
+ /**
22
+ * 是否是Android
23
+ */
24
+ export const isAndroid = (() => {
25
+ const userAgent = window.navigator.userAgent || '';
26
+ return userAgent.indexOf('Android') > -1 || userAgent.indexOf('Adr') > -1;
27
+ })();
28
+
29
+ /**
30
+ * 是否是iOS(含 iPadOS 13+ 默认的桌面版 UA)
31
+ */
32
+ export const isIOS = (() => {
33
+ const userAgent = window.navigator.userAgent || '';
34
+ if (/\(i[^;]+;( U;)? CPU.+Mac OS X/.test(userAgent)) return true;
35
+ // iPadOS 13+ 默认使用 Mac 桌面 UA,需通过触控点数量识别
36
+ return (
37
+ /Macintosh;.*Mac OS X/.test(userAgent) &&
38
+ (window.navigator.maxTouchPoints ?? 0) > 1
39
+ );
40
+ })();
@@ -0,0 +1,3 @@
1
+ export * from './env';
2
+ export * from './md5';
3
+ export * from './tailwind';
@@ -0,0 +1,17 @@
1
+ import SparkMD5 from 'spark-md5';
2
+
3
+ /**
4
+ * 计算文件的MD5值的Base64编码
5
+ * @param arrayBuffer 文件的二进制数据
6
+ * @returns 文件的MD5值的Base64编码
7
+ */
8
+ export function md5DigestBase64(arrayBuffer: ArrayBuffer) {
9
+ const spark = new SparkMD5.ArrayBuffer();
10
+ spark.append(arrayBuffer);
11
+ const raw = spark.end(true); // 16 字节二进制字符串
12
+ let bin = '';
13
+ for (let i = 0; i < raw.length; i++) {
14
+ bin += String.fromCharCode(raw.charCodeAt(i) & 0xff);
15
+ }
16
+ return btoa(bin);
17
+ }