generator-mico-cli 0.2.30 → 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 (183) hide show
  1. package/README.md +146 -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/micro-react/README.md +34 -0
  137. package/generators/micro-react/index.js +2 -0
  138. package/generators/micro-react/templates/apps/layout/config/config.dev.ts +21 -1
  139. package/generators/micro-react/templates/apps/layout/config/config.ts +0 -15
  140. package/generators/micro-react/templates/apps/layout/docs/arch-/346/227/245/345/277/227/344/270/216/345/270/270/351/207/217.md +16 -8
  141. package/generators/micro-react/templates/apps/layout/docs/feat-/346/236/204/345/273/272define/344/270/216/345/205/215/350/256/244/350/257/201/345/210/235/345/247/213/346/200/201.md +49 -3
  142. package/generators/micro-react/templates/apps/layout/docs/feature-/350/217/234/345/215/225/346/235/203/351/231/220/346/216/247/345/210/266.md +3 -1
  143. package/generators/micro-react/templates/apps/layout/docs/feature-/350/267/257/347/224/261/346/235/203/351/231/220/346/227/245/345/277/227.md +4 -4
  144. package/generators/micro-react/templates/apps/layout/src/app.tsx +10 -4
  145. package/generators/micro-react/templates/apps/layout/src/common/auth/auth-check-path.ts +14 -0
  146. package/generators/micro-react/templates/apps/layout/src/common/auth/index.ts +1 -0
  147. package/generators/micro-react/templates/apps/layout/src/common/logger.ts +51 -18
  148. package/generators/micro-react/templates/apps/layout/src/common/request/sso.ts +8 -5
  149. package/generators/micro-react/templates/package.json +1 -1
  150. package/generators/subapp-h5/ignore-list.json +1 -0
  151. package/generators/subapp-h5/index.js +424 -0
  152. package/generators/subapp-h5/meta.json +10 -0
  153. package/generators/subapp-h5/templates/.env +1 -0
  154. package/generators/subapp-h5/templates/.stylelintrc.js +22 -0
  155. package/generators/subapp-h5/templates/config/config.dev.ts +7 -0
  156. package/generators/subapp-h5/templates/config/config.prod.development.ts +7 -0
  157. package/generators/subapp-h5/templates/config/config.prod.production.ts +10 -0
  158. package/generators/subapp-h5/templates/config/config.prod.testing.ts +7 -0
  159. package/generators/subapp-h5/templates/config/config.prod.ts +7 -0
  160. package/generators/subapp-h5/templates/config/config.ts +6 -0
  161. package/generators/subapp-h5/templates/config/routes.ts +13 -0
  162. package/generators/subapp-h5/templates/eslint.config.ts +12 -0
  163. package/generators/subapp-h5/templates/mock/user.ts +34 -0
  164. package/generators/subapp-h5/templates/package.json +42 -0
  165. package/generators/subapp-h5/templates/src/app.tsx +14 -0
  166. package/generators/subapp-h5/templates/src/assets/yay.jpg +0 -0
  167. package/generators/subapp-h5/templates/src/intl.ts +37 -0
  168. package/generators/subapp-h5/templates/src/layouts/index.tsx +10 -0
  169. package/generators/subapp-h5/templates/src/pages/index.tsx +22 -0
  170. package/generators/subapp-h5/templates/src/services/user.ts +38 -0
  171. package/generators/subapp-h5/templates/tailwind.config.js +16 -0
  172. package/generators/subapp-h5/templates/tailwind.css +7 -0
  173. package/generators/subapp-h5/templates/tsconfig.json +3 -0
  174. package/generators/subapp-h5/templates/typings.d.ts +1 -0
  175. package/generators/subapp-react/README.md +43 -0
  176. package/generators/subapp-react/index.js +2 -0
  177. package/generators/subapp-react/templates/homepage/README.md +5 -1
  178. package/generators/subapp-react/templates/homepage/config/config.dev.ts +20 -0
  179. package/generators/subapp-react/templates/homepage/config/config.ts +0 -15
  180. package/generators/subapp-react/templates/homepage/src/common/logger.ts +50 -18
  181. package/generators/subapp-umd/README.md +37 -0
  182. package/lib/setup-multica-desktop.js +154 -0
  183. package/package.json +1 -1
@@ -0,0 +1,121 @@
1
+ import { cn } from '<%= packageScope %>/utils/tailwind';
2
+ import {
3
+ useEffect,
4
+ useState,
5
+ type FC,
6
+ type PropsWithChildren,
7
+ type ReactNode,
8
+ } from 'react';
9
+ import ImmersiveHeader from './ImmersiveHeader';
10
+ import LayoutFooter from './LayoutFooter';
11
+
12
+ /**
13
+ * 确保 viewport meta 包含 viewport-fit=cover,
14
+ * 这是 env(safe-area-inset-*) 生效的前置条件。
15
+ */
16
+ function useViewportFitCover() {
17
+ useEffect(() => {
18
+ const meta = document.querySelector<HTMLMetaElement>(
19
+ 'meta[name="viewport"]',
20
+ );
21
+ if (meta) {
22
+ const content = meta.getAttribute('content') || '';
23
+ if (!content.includes('viewport-fit')) {
24
+ meta.setAttribute('content', `${content},viewport-fit=cover`);
25
+ }
26
+ } else {
27
+ const el = document.createElement('meta');
28
+ el.name = 'viewport';
29
+ el.content =
30
+ 'width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,viewport-fit=cover';
31
+ document.head.appendChild(el);
32
+ }
33
+ }, []);
34
+ }
35
+
36
+ export interface LayoutProps extends PropsWithChildren {
37
+ /** 是否沉浸式布局 */
38
+ immersive?: boolean;
39
+ /** 布局容器附加样式 */
40
+ className?: string;
41
+ /** 沉浸式布局时,自定义头部内容 */
42
+ header?: ReactNode;
43
+ /** 沉浸式布局时,头部样式变体 */
44
+ headerVariant?: 'light' | 'dark' | 'transparent';
45
+ /** 沉浸式布局时,头部附加样式 */
46
+ headerClassName?: string;
47
+ /** 沉浸式布局时,头部右侧内容 */
48
+ headerEnd?: ReactNode;
49
+ /** 沉浸式布局时,内容区域附加样式 */
50
+ contentClassName?: string;
51
+ /** 底部内容 */
52
+ footer?: ReactNode;
53
+ /** 底部区域附加样式 */
54
+ footerClassName?: string;
55
+ /** 底部内容是否fixed定位在底部 */
56
+ footerFixed?: boolean;
57
+ }
58
+
59
+ /**
60
+ * 页面布局组件。
61
+ *
62
+ * 普通布局:不渲染 header,仅处理左、右、下方安全区域。
63
+ * 沉浸式布局:额外渲染 header,并处理上方安全区域。
64
+ */
65
+ const Layout: FC<LayoutProps> = ({
66
+ immersive = true,
67
+ headerVariant = 'dark',
68
+ children,
69
+ className,
70
+ header,
71
+ headerClassName,
72
+ headerEnd,
73
+ contentClassName,
74
+ footer,
75
+ footerClassName,
76
+ footerFixed,
77
+ }) => {
78
+ useViewportFitCover();
79
+
80
+ const [footerHeight, setFooterHeight] = useState(0);
81
+ const onFooterHeightChange = (height: number) => {
82
+ setFooterHeight(height);
83
+ };
84
+ return (
85
+ <div
86
+ className={cn(
87
+ 'flex flex-col w-screen h-screen overflow-hidden px-safe',
88
+ className,
89
+ )}
90
+ >
91
+ {immersive && (
92
+ <ImmersiveHeader
93
+ end={headerEnd}
94
+ className={headerClassName}
95
+ variant={headerVariant}
96
+ >
97
+ {header}
98
+ </ImmersiveHeader>
99
+ )}
100
+ <div className="flex flex-col flex-1 overflow-y-auto overscroll-contain">
101
+ <main
102
+ className={cn('flex-1 w-full', contentClassName)}
103
+ style={{
104
+ paddingBottom: footerHeight > 0 ? `${footerHeight}px` : undefined,
105
+ }}
106
+ >
107
+ {children}
108
+ </main>
109
+ <LayoutFooter
110
+ fixed={footerFixed}
111
+ className={footerClassName}
112
+ onFooterHeightChange={onFooterHeightChange}
113
+ >
114
+ {footer}
115
+ </LayoutFooter>
116
+ </div>
117
+ </div>
118
+ );
119
+ };
120
+
121
+ export default Layout;
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./src/.umi/tsconfig.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "paths": {
6
+ "<%= packageScope %>/components/*": ["./src/*"],
7
+ "@/*": ["./src/*"],
8
+ "@@/*": ["./src/.umi/*"],
9
+ "umi": ["./node_modules/umi"],
10
+ "umi/typings": ["./src/.umi/typings"]
11
+ }
12
+ }
13
+ }
@@ -0,0 +1 @@
1
+ import 'umi/typings';
@@ -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,19 @@
1
+ {
2
+ "name": "<%= packageScope %>/constant",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "exports": {
8
+ ".": "./src/index.ts",
9
+ "./*": "./src/*.ts"
10
+ },
11
+ "devDependencies": {
12
+ "<%= packageScope %>/eslint": "workspace:^",
13
+ "<%= packageScope %>/typescript": "workspace:^"
14
+ },
15
+ "scripts": {
16
+ "lint": "eslint",
17
+ "lint:fix": "eslint --fix"
18
+ }
19
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 会员常量,示例
3
+ */
4
+ export const enum MEMBER_CONSTANT {
5
+ NONE = 0, // 免费用户
6
+ MEMBER_TIER_BASIC = 1, // 基础会员
7
+ MEMBER_TIER_STANDARD = 2, // 标准会员
8
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "<%= packageScope %>/typescript"
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,18 @@
1
+ {
2
+ "name": "<%= packageScope %>/deeplink",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "exports": {
8
+ ".": "./src/index.ts"
9
+ },
10
+ "devDependencies": {
11
+ "<%= packageScope %>/eslint": "workspace:^",
12
+ "<%= packageScope %>/typescript": "workspace:^"
13
+ },
14
+ "scripts": {
15
+ "lint": "eslint",
16
+ "lint:fix": "eslint --fix"
17
+ }
18
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 跳转到首页
3
+ */
4
+ export function togoHome() {
5
+ // 示例:跳转到首页,请根据客户端的deeplink规则修改
6
+ location.href = '<%= projectName %>://router/home';
7
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "<%= packageScope %>/typescript"
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,18 @@
1
+ {
2
+ "name": "<%= packageScope %>/domain",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "exports": {
8
+ ".": "./src/index.ts"
9
+ },
10
+ "devDependencies": {
11
+ "<%= packageScope %>/eslint": "workspace:^",
12
+ "<%= packageScope %>/typescript": "workspace:^"
13
+ },
14
+ "scripts": {
15
+ "lint": "eslint",
16
+ "lint:fix": "eslint --fix"
17
+ }
18
+ }
@@ -0,0 +1,29 @@
1
+ import '../types.d';
2
+
3
+ function getMicoConfig() {
4
+ return window?.__MICO_CONFIG__;
5
+ }
6
+
7
+ /**
8
+ * 接口基础URL
9
+ */
10
+ export const apiBaseUrl: string = (() => {
11
+ const micoConfig = getMicoConfig();
12
+ return micoConfig?.API_BASE_URL ?? process.env.UMI_APP_API_BASE_URL ?? '';
13
+ })();
14
+
15
+ /**
16
+ * oss CDN 基础URL
17
+ */
18
+ export const cdnBaseUrl: string = (() => {
19
+ const micoConfig = getMicoConfig();
20
+ return micoConfig?.CDN_BASE_URL ?? process.env.UMI_APP_CDN_BASE_URL ?? '';
21
+ })();
22
+
23
+ /**
24
+ * 多语言接口基础URL
25
+ */
26
+ export const langBaseUrl: string = (() => {
27
+ const micoConfig = getMicoConfig();
28
+ return micoConfig?.LANG_BASE_URL ?? process.env.UMI_APP_LANG_BASE_URL ?? '';
29
+ })();
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "<%= packageScope %>/typescript"
3
+ }
@@ -0,0 +1,11 @@
1
+ declare global {
2
+ interface Window {
3
+ __MICO_CONFIG__?: MicoConfig;
4
+ }
5
+ }
6
+
7
+ export interface MicoConfig {
8
+ API_BASE_URL?: string; // 接口基础URL
9
+ CDN_BASE_URL?: string; // oss CDN 基础URL
10
+ LANG_BASE_URL?: string; // 多语言接口基础URL
11
+ }
@@ -0,0 +1,36 @@
1
+ import { defineConfig } from 'eslint/config';
2
+ import eslint from '@eslint/js';
3
+ import tseslint from 'typescript-eslint';
4
+ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
5
+
6
+ /**
7
+ * 基础配置
8
+ */
9
+ export default defineConfig([
10
+ {
11
+ languageOptions: {
12
+ parserOptions: {
13
+ projectService: true,
14
+ },
15
+ },
16
+ },
17
+ {
18
+ ignores: [
19
+ 'node_modules',
20
+ 'dist',
21
+ 'public',
22
+ '.turbo',
23
+ 'type/**',
24
+ 'mock/**',
25
+ '**/.stylelintrc.*',
26
+ '**/tailwind.config.*',
27
+ '**/postcss.config.*',
28
+ 'src/.umi',
29
+ 'src/.umi-production',
30
+ 'src/.umi-test',
31
+ ],
32
+ },
33
+ eslint.configs.recommended,
34
+ ...tseslint.configs.recommended,
35
+ eslintPluginPrettierRecommended,
36
+ ]);
@@ -0,0 +1,33 @@
1
+ import { defineConfig } from 'eslint/config';
2
+ import eslintPluginReact from 'eslint-plugin-react';
3
+ import eslintPluginReactHooks from 'eslint-plugin-react-hooks';
4
+ import eslintPluginReactRefresh from 'eslint-plugin-react-refresh';
5
+
6
+ import eslintConfigBase from './eslint.config.base';
7
+
8
+ import type { ESLint } from 'eslint';
9
+
10
+ /**
11
+ * React 配置
12
+ */
13
+ export default defineConfig([
14
+ ...eslintConfigBase,
15
+ {
16
+ files: ['**/*.{ts,tsx,js,jsx}'],
17
+ plugins: {
18
+ react: eslintPluginReact,
19
+ 'react-hooks': eslintPluginReactHooks as ESLint.Plugin,
20
+ 'react-refresh': eslintPluginReactRefresh,
21
+ },
22
+ settings: {
23
+ react: {
24
+ version: 'detect',
25
+ },
26
+ },
27
+ rules: {
28
+ ...eslintPluginReact.configs.recommended.rules,
29
+ ...eslintPluginReact.configs['jsx-runtime'].rules,
30
+ ...eslintPluginReactHooks.configs.recommended.rules,
31
+ },
32
+ },
33
+ ]);
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "<%= packageScope %>/eslint",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "main": "./eslint.config.base.ts",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": "./eslint.config.base.ts",
9
+ "./react": "./eslint.config.react.ts"
10
+ },
11
+ "devDependencies": {
12
+ "@eslint/js": "^9.0.0",
13
+ "eslint": "catalog:",
14
+ "eslint-config-prettier": "^10.1.8",
15
+ "eslint-plugin-prettier": "^5.5.5",
16
+ "eslint-plugin-react": "^7.37.5",
17
+ "eslint-plugin-react-hooks": "^7.0.1",
18
+ "eslint-plugin-react-refresh": "^0.5.2",
19
+ "globals": "^17.4.0",
20
+ "typescript-eslint": "^8.57.2"
21
+ }
22
+ }
@@ -0,0 +1,17 @@
1
+ import baseConfig from '<%= packageScope %>/eslint/react';
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
+ {
13
+ rules: {
14
+ '@typescript-eslint/no-explicit-any': 'off',
15
+ },
16
+ },
17
+ ]);
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "<%= packageScope %>/js-bridge",
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
+ "devDependencies": {
16
+ "<%= packageScope %>/eslint": "workspace:^",
17
+ "<%= packageScope %>/typescript": "workspace:^"
18
+ },
19
+ "dependencies": {
20
+ "<%= packageScope %>/domain": "workspace:^",
21
+ "<%= packageScope %>/utils": "workspace:^"
22
+ }
23
+ }
@@ -0,0 +1,126 @@
1
+ // 注册JSBridge方法
2
+ import { isAndroid, isIOS } from '<%= packageScope %>/utils/env';
3
+ import { canUseJSBridge } from './index';
4
+
5
+ import type { JSBridgeResponse } from '../type';
6
+
7
+ function createPostID() {
8
+ return `${Math.random().toString(36).substring(2, 6)}_${Date.now()}`;
9
+ }
10
+
11
+ function callIOSMethods<D = unknown, T = null>(
12
+ method: string,
13
+ payload: T,
14
+ ): Promise<JSBridgeResponse<D>> {
15
+ return new Promise((resolve, reject) => {
16
+ if (!canUseJSBridge()) {
17
+ reject(new Error('callIOSMethods: No bridge'));
18
+ return;
19
+ }
20
+ console.log(method, payload, '--->method, payload');
21
+ window.MCAIJsBridge!.post!<D, T>(method, payload, (response) => {
22
+ console.log(response, '<---response');
23
+ if (response === null) {
24
+ reject(new Error('callIOSMethods: No response'));
25
+ } else if (response.code === 0) {
26
+ resolve(response);
27
+ } else {
28
+ reject(
29
+ new Error(
30
+ `callIOSMethods: ${response.message ?? JSON.stringify(response)}`,
31
+ ),
32
+ );
33
+ }
34
+ });
35
+ });
36
+ }
37
+
38
+ interface AndroidMethodCallingIDMap {
39
+ resolve: (response: JSBridgeResponse<any>) => void;
40
+ reject: (error: Error) => void;
41
+ }
42
+ const androidMethodCallingIDMap = new Map<string, AndroidMethodCallingIDMap>();
43
+ function callAndroidMethods<D = unknown, T = null>(
44
+ method: string,
45
+ payload: T,
46
+ ): Promise<JSBridgeResponse<D>> {
47
+ if (!window.AndroidJSBridgeCallback) {
48
+ window.AndroidJSBridgeCallback = (postID, response) => {
49
+ console.log(postID, '<---postID', response);
50
+ if (!postID) {
51
+ console.error('callAndroidMethods: No postID');
52
+ }
53
+ if (!androidMethodCallingIDMap.has(postID)) {
54
+ console.error('callAndroidMethods: postID not found');
55
+ return;
56
+ }
57
+ const { resolve, reject } = androidMethodCallingIDMap.get(postID)!;
58
+ androidMethodCallingIDMap.delete(postID);
59
+ if (response === null) {
60
+ reject(new Error('callAndroidMethods: No response'));
61
+ } else if (response.code === 0) {
62
+ resolve(response);
63
+ } else {
64
+ reject(
65
+ new Error(
66
+ `callAndroidMethods: ${response.message ?? JSON.stringify(response)}`,
67
+ ),
68
+ );
69
+ }
70
+ };
71
+ }
72
+ return new Promise((resolve, reject) => {
73
+ if (!canUseJSBridge()) {
74
+ reject(new Error('callAndroidMethods: No bridge'));
75
+ return;
76
+ }
77
+ let postID = createPostID();
78
+ while (androidMethodCallingIDMap.has(postID)) {
79
+ postID = createPostID();
80
+ }
81
+ androidMethodCallingIDMap.set(postID, { resolve, reject });
82
+ console.log(postID, 'postID--->', method, payload);
83
+ window.Omigo!.post!(method, payload ? JSON.stringify(payload) : '', postID);
84
+ });
85
+ }
86
+
87
+ interface CallOptions {
88
+ showToast?: boolean;
89
+ isShowLoading?: boolean;
90
+ }
91
+ const callJSBridgeMethodsMap = new Set<string>();
92
+ export async function callJSBridgeMethods<D = unknown, T = null>(
93
+ method: string,
94
+ payload: T,
95
+ options?: CallOptions,
96
+ ) {
97
+ const { showToast = true, isShowLoading: _isShowLoading = false } =
98
+ options ?? {};
99
+ const isShowLoading = _isShowLoading;
100
+ if (isShowLoading) {
101
+ // 避免重复调用
102
+ if (callJSBridgeMethodsMap.has(method)) {
103
+ throw new Error(`callJSBridgeMethods: ${method} is already called`);
104
+ }
105
+ // 打开loading
106
+ callJSBridgeMethodsMap.add(method);
107
+ }
108
+ try {
109
+ if (isAndroid) {
110
+ return await callAndroidMethods<D, T>(method, payload);
111
+ } else if (isIOS) {
112
+ return await callIOSMethods<D, T>(method, payload);
113
+ }
114
+ throw new Error('callJSBridgeMethods: platform not supported');
115
+ } catch (error) {
116
+ if (showToast) {
117
+ // 显示toast
118
+ }
119
+ throw error;
120
+ } finally {
121
+ if (isShowLoading) {
122
+ // 关闭loading
123
+ callJSBridgeMethodsMap.delete(method);
124
+ }
125
+ }
126
+ }
@@ -0,0 +1,9 @@
1
+ import { callJSBridgeMethods } from './call';
2
+
3
+ /**
4
+ * 关闭当前H5页面,示例,具体实现请根据客户端的JSBridge规则修改
5
+ */
6
+ export default async function closeH5Page() {
7
+ const response = await callJSBridgeMethods('closeH5Page', null);
8
+ return response.data;
9
+ }