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.
- package/README.md +145 -18
- package/bin/mico.js +76 -0
- package/generators/h5-react/ignore-list.json +1 -0
- package/generators/h5-react/index.js +349 -0
- package/generators/h5-react/meta.json +11 -0
- package/generators/h5-react/templates/.commitlintrc.js +7 -0
- package/generators/h5-react/templates/.cursor/rules/cicd-deploy.mdc +104 -0
- package/generators/h5-react/templates/.cursor/rules/common-intl.mdc +42 -0
- package/generators/h5-react/templates/.cursor/rules/git-hooks.mdc +40 -0
- package/generators/h5-react/templates/.cursor/rules/internal-packages.mdc +46 -0
- package/generators/h5-react/templates/.cursor/rules/monorepo.mdc +64 -0
- package/generators/h5-react/templates/.cursor/rules/package-json.mdc +52 -0
- package/generators/h5-react/templates/.cursor/rules/tailwind-umi.mdc +60 -0
- package/generators/h5-react/templates/.cursor/rules/umi-app.mdc +74 -0
- package/generators/h5-react/templates/.cursor/rules/umi-config.mdc +86 -0
- package/generators/h5-react/templates/.cursor/rules/umi-mock.mdc +80 -0
- package/generators/h5-react/templates/.cursor/rules/workspace-request.mdc +52 -0
- package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/SKILL.md +213 -0
- package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/evals/evals.json +23 -0
- package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/cursor-rule-template.md +60 -0
- package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/phase-1-scanning.md +102 -0
- package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/phase-2-context-analysis.md +102 -0
- package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/phase-3-pattern-extraction.md +105 -0
- package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/phase-4-module-mapping.md +65 -0
- package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/phase-5-glossary.md +63 -0
- package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/templates/DEV_PATTERNS.tpl.md +77 -0
- package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/templates/GLOSSARY.tpl.md +17 -0
- package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/templates/MODULE_MAP.tpl.md +45 -0
- package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/templates/PROJECT_CONTEXT.tpl.md +155 -0
- package/generators/h5-react/templates/.cursor/skills/biz-app-analyzer/references/update-mode.md +116 -0
- package/generators/h5-react/templates/.env.development +5 -0
- package/generators/h5-react/templates/.env.production +5 -0
- package/generators/h5-react/templates/.env.testing +5 -0
- package/generators/h5-react/templates/.husky/commit-msg +2 -0
- package/generators/h5-react/templates/.husky/pre-commit +2 -0
- package/generators/h5-react/templates/.lintstagedrc.js +8 -0
- package/generators/h5-react/templates/.prettierrc.json +7 -0
- package/generators/h5-react/templates/CICD/before_build.sh +76 -0
- package/generators/h5-react/templates/CICD/start_dev.sh +54 -0
- package/generators/h5-react/templates/CICD/start_local.sh +30 -0
- package/generators/h5-react/templates/CICD/start_prod.sh +53 -0
- package/generators/h5-react/templates/CICD/start_test.sh +55 -0
- package/generators/h5-react/templates/CICD/wangsu_fresh_dev.sh +19 -0
- package/generators/h5-react/templates/CICD/wangsu_fresh_prod.sh +19 -0
- package/generators/h5-react/templates/CICD/wangsu_fresh_test.sh +19 -0
- package/generators/h5-react/templates/README.md +301 -0
- package/generators/h5-react/templates/_gitignore +30 -0
- package/generators/h5-react/templates/_npmrc +6 -0
- package/generators/h5-react/templates/apps/.gitkeep +0 -0
- package/generators/h5-react/templates/dev.preset.json +10 -0
- package/generators/h5-react/templates/package.json +56 -0
- package/generators/h5-react/templates/packages/common-intl/README.md +180 -0
- package/generators/h5-react/templates/packages/common-intl/eslint.config.ts +12 -0
- package/generators/h5-react/templates/packages/common-intl/package.json +31 -0
- package/generators/h5-react/templates/packages/common-intl/src/index.ts +3 -0
- package/generators/h5-react/templates/packages/common-intl/src/intl.ts +100 -0
- package/generators/h5-react/templates/packages/common-intl/tsconfig.json +3 -0
- package/generators/h5-react/templates/packages/components/eslint.config.ts +12 -0
- package/generators/h5-react/templates/packages/components/package.json +32 -0
- package/generators/h5-react/templates/packages/components/src/Layout/ImmersiveHeader.tsx +126 -0
- package/generators/h5-react/templates/packages/components/src/Layout/LayoutFooter.tsx +72 -0
- package/generators/h5-react/templates/packages/components/src/Layout/index.tsx +121 -0
- package/generators/h5-react/templates/packages/components/src/assets/image/back.png +0 -0
- package/generators/h5-react/templates/packages/components/src/index.ts +0 -0
- package/generators/h5-react/templates/packages/components/tsconfig.json +13 -0
- package/generators/h5-react/templates/packages/components/typings.d.ts +1 -0
- package/generators/h5-react/templates/packages/constant/eslint.config.ts +12 -0
- package/generators/h5-react/templates/packages/constant/package.json +19 -0
- package/generators/h5-react/templates/packages/constant/src/index.ts +0 -0
- package/generators/h5-react/templates/packages/constant/src/member.ts +8 -0
- package/generators/h5-react/templates/packages/constant/tsconfig.json +3 -0
- package/generators/h5-react/templates/packages/deeplink/eslint.config.ts +12 -0
- package/generators/h5-react/templates/packages/deeplink/package.json +18 -0
- package/generators/h5-react/templates/packages/deeplink/src/index.ts +7 -0
- package/generators/h5-react/templates/packages/deeplink/tsconfig.json +3 -0
- package/generators/h5-react/templates/packages/domain/eslint.config.ts +12 -0
- package/generators/h5-react/templates/packages/domain/package.json +18 -0
- package/generators/h5-react/templates/packages/domain/src/index.ts +29 -0
- package/generators/h5-react/templates/packages/domain/tsconfig.json +3 -0
- package/generators/h5-react/templates/packages/domain/types.d.ts +11 -0
- package/generators/h5-react/templates/packages/eslint/eslint.config.base.ts +36 -0
- package/generators/h5-react/templates/packages/eslint/eslint.config.react.ts +33 -0
- package/generators/h5-react/templates/packages/eslint/package.json +22 -0
- package/generators/h5-react/templates/packages/js-bridge/eslint.config.ts +17 -0
- package/generators/h5-react/templates/packages/js-bridge/package.json +23 -0
- package/generators/h5-react/templates/packages/js-bridge/src/call.ts +126 -0
- package/generators/h5-react/templates/packages/js-bridge/src/closeH5Page.ts +9 -0
- package/generators/h5-react/templates/packages/js-bridge/src/getUserInfo.ts +96 -0
- package/generators/h5-react/templates/packages/js-bridge/src/index.ts +15 -0
- package/generators/h5-react/templates/packages/js-bridge/tsconfig.json +3 -0
- package/generators/h5-react/templates/packages/js-bridge/type.d.ts +24 -0
- package/generators/h5-react/templates/packages/request/axios.d.ts +42 -0
- package/generators/h5-react/templates/packages/request/eslint.config.ts +17 -0
- package/generators/h5-react/templates/packages/request/package.json +22 -0
- package/generators/h5-react/templates/packages/request/src/index.ts +165 -0
- package/generators/h5-react/templates/packages/request/src/interceptors.ts +126 -0
- package/generators/h5-react/templates/packages/request/src/types.ts +101 -0
- package/generators/h5-react/templates/packages/request/src/url-resolver.ts +66 -0
- package/generators/h5-react/templates/packages/request/src/utils.ts +12 -0
- package/generators/h5-react/templates/packages/request/tsconfig.json +3 -0
- package/generators/h5-react/templates/packages/request/umi.d.ts +94 -0
- package/generators/h5-react/templates/packages/typescript/package.json +11 -0
- package/generators/h5-react/templates/packages/typescript/tsconfig.base.json +23 -0
- package/generators/h5-react/templates/packages/typescript/tsconfig.react.json +7 -0
- package/generators/h5-react/templates/packages/umi-config/eslint.config.ts +12 -0
- package/generators/h5-react/templates/packages/umi-config/package.json +31 -0
- package/generators/h5-react/templates/packages/umi-config/src/config.dev.ts +34 -0
- package/generators/h5-react/templates/packages/umi-config/src/config.prod.development.ts +17 -0
- package/generators/h5-react/templates/packages/umi-config/src/config.prod.production.ts +42 -0
- package/generators/h5-react/templates/packages/umi-config/src/config.prod.testing.ts +17 -0
- package/generators/h5-react/templates/packages/umi-config/src/config.prod.ts +56 -0
- package/generators/h5-react/templates/packages/umi-config/src/config.ts +86 -0
- package/generators/h5-react/templates/packages/umi-config/src/index.ts +25 -0
- package/generators/h5-react/templates/packages/umi-config/src/plugins/apply-sentry-plugin.ts +57 -0
- package/generators/h5-react/templates/packages/umi-config/src/type.d.ts +3 -0
- package/generators/h5-react/templates/packages/umi-config/tsconfig.json +3 -0
- package/generators/h5-react/templates/packages/utils/eslint.config.ts +12 -0
- package/generators/h5-react/templates/packages/utils/package.json +27 -0
- package/generators/h5-react/templates/packages/utils/src/date.ts +21 -0
- package/generators/h5-react/templates/packages/utils/src/env.ts +40 -0
- package/generators/h5-react/templates/packages/utils/src/index.ts +3 -0
- package/generators/h5-react/templates/packages/utils/src/md5.ts +17 -0
- package/generators/h5-react/templates/packages/utils/src/mock.ts +83 -0
- package/generators/h5-react/templates/packages/utils/src/number.ts +23 -0
- package/generators/h5-react/templates/packages/utils/src/tailwind.ts +12 -0
- package/generators/h5-react/templates/packages/utils/src/url.ts +19 -0
- package/generators/h5-react/templates/packages/utils/tsconfig.json +9 -0
- package/generators/h5-react/templates/page.config.ts +1 -0
- package/generators/h5-react/templates/pnpm-workspace.yaml +17 -0
- package/generators/h5-react/templates/scripts/collect-dist.js +78 -0
- package/generators/h5-react/templates/scripts/dev-preset.js +265 -0
- package/generators/h5-react/templates/scripts/dev-preset.schema.json +39 -0
- package/generators/h5-react/templates/scripts/dev.js +133 -0
- package/generators/h5-react/templates/scripts/gateway.ts +241 -0
- package/generators/h5-react/templates/turbo.json +86 -0
- package/generators/subapp-h5/ignore-list.json +1 -0
- package/generators/subapp-h5/index.js +424 -0
- package/generators/subapp-h5/meta.json +10 -0
- package/generators/subapp-h5/templates/.env +1 -0
- package/generators/subapp-h5/templates/.stylelintrc.js +22 -0
- package/generators/subapp-h5/templates/config/config.dev.ts +7 -0
- package/generators/subapp-h5/templates/config/config.prod.development.ts +7 -0
- package/generators/subapp-h5/templates/config/config.prod.production.ts +10 -0
- package/generators/subapp-h5/templates/config/config.prod.testing.ts +7 -0
- package/generators/subapp-h5/templates/config/config.prod.ts +7 -0
- package/generators/subapp-h5/templates/config/config.ts +6 -0
- package/generators/subapp-h5/templates/config/routes.ts +13 -0
- package/generators/subapp-h5/templates/eslint.config.ts +12 -0
- package/generators/subapp-h5/templates/mock/user.ts +34 -0
- package/generators/subapp-h5/templates/package.json +42 -0
- package/generators/subapp-h5/templates/src/app.tsx +14 -0
- package/generators/subapp-h5/templates/src/assets/yay.jpg +0 -0
- package/generators/subapp-h5/templates/src/intl.ts +37 -0
- package/generators/subapp-h5/templates/src/layouts/index.tsx +10 -0
- package/generators/subapp-h5/templates/src/pages/index.tsx +22 -0
- package/generators/subapp-h5/templates/src/services/user.ts +38 -0
- package/generators/subapp-h5/templates/tailwind.config.js +16 -0
- package/generators/subapp-h5/templates/tailwind.css +7 -0
- package/generators/subapp-h5/templates/tsconfig.json +3 -0
- package/generators/subapp-h5/templates/typings.d.ts +1 -0
- package/lib/setup-multica-desktop.js +154 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,16 +4,26 @@
|
|
|
4
4
|
|
|
5
5
|
## 文档索引
|
|
6
6
|
|
|
7
|
+
### 项目总览与设计
|
|
8
|
+
|
|
7
9
|
| 文档 | 说明 |
|
|
8
10
|
|---|---|
|
|
11
|
+
| [docs/mico-cli.md](docs/mico-cli.md) | `mico` CLI 整体能力、命令清单(`create` / `list` / `doctor` / `--verbose` / `--dry-run`)与子进程调用约定 |
|
|
9
12
|
| [docs/architecture.md](docs/architecture.md) | 项目架构、模块职责、关键约定、依赖关系 |
|
|
10
|
-
| [docs/generators.md](docs/generators.md) |
|
|
11
|
-
| [docs/configuration.md](docs/configuration.md) | `.micorc`
|
|
12
|
-
| [docs/testing.md](docs/testing.md) | Vitest + yeoman-test
|
|
13
|
-
| [docs/scripts.md](docs/scripts.md) | `sync:subapp-react-template` 与 `verify:micro-react` |
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
| [docs/generators.md](docs/generators.md) | 各生成器的 prompt / 模板变量 / 联动修改细节(生成器之间的协作总览) |
|
|
14
|
+
| [docs/configuration.md](docs/configuration.md) | `.micorc` / `.micorc.json` 配置字段、加载顺序与默认值 |
|
|
15
|
+
| [docs/testing.md](docs/testing.md) | Vitest + yeoman-test 测试体系、目录结构与 Mock 策略 |
|
|
16
|
+
| [docs/scripts.md](docs/scripts.md) | `sync:subapp-react-template` 与 `verify:micro-react` 辅助脚本 |
|
|
17
|
+
|
|
18
|
+
### 各生成器使用说明(按生成器拆分,建议先于代码改动阅读)
|
|
19
|
+
|
|
20
|
+
| 生成器 | 使用说明 | 仓库内就近说明 |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| `micro-react`(qiankun Monorepo 基座) | [docs/micro-react-generator.md](docs/micro-react-generator.md) | [generators/micro-react/README.md](generators/micro-react/README.md) |
|
|
23
|
+
| `subapp-react`(在已有 Monorepo 中新增 React 子应用) | [docs/subapp-react-generator.md](docs/subapp-react-generator.md) | [generators/subapp-react/README.md](generators/subapp-react/README.md) |
|
|
24
|
+
| `h5-react`(Umi 4 H5 Monorepo 基座 + 联动 `subapp-h5`) | [docs/h5-react-generator.md](docs/h5-react-generator.md) | —(模板内置 README,由生成器写入目标项目根目录) |
|
|
25
|
+
| `subapp-h5`(在 H5 Monorepo 中新增 Umi 子应用) | [docs/subapp-h5-generator.md](docs/subapp-h5-generator.md) | —(无独立 README,约定见上文与 `templates/.cursor/rules/`) |
|
|
26
|
+
| `subapp-umd`(UMD 组件包,`<script>` 加载场景) | —(详见本 README 「UMD 组件包生成器」一节) | [generators/subapp-umd/README.md](generators/subapp-umd/README.md) |
|
|
17
27
|
|
|
18
28
|
## 要求
|
|
19
29
|
|
|
@@ -57,6 +67,14 @@ mico create micro-react --dry-run
|
|
|
57
67
|
mico doctor
|
|
58
68
|
```
|
|
59
69
|
|
|
70
|
+
执行配置任务(如配置自托管 Multica Desktop):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
mico setup multica-desktop
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
详见下文 [Multica Desktop 自托管配置](#multica-desktop-自托管配置setup-multica-desktop)。
|
|
77
|
+
|
|
60
78
|
## 配置文件
|
|
61
79
|
|
|
62
80
|
可以在项目目录或用户主目录创建 `.micorc` 或 `.micorc.json` 文件来预设默认值。
|
|
@@ -74,6 +92,8 @@ mico doctor
|
|
|
74
92
|
"packageScope": "@my-company",
|
|
75
93
|
"cdnPrefix": "portal",
|
|
76
94
|
"author": "Team <team@example.com>",
|
|
95
|
+
"initialSubAppName": "app",
|
|
96
|
+
"initialSubAppDevPort": "8000",
|
|
77
97
|
"defaultSubappName": "subapp",
|
|
78
98
|
"devPort": "8010",
|
|
79
99
|
"defaultUmdName": "my-widget",
|
|
@@ -83,13 +103,15 @@ mico doctor
|
|
|
83
103
|
|
|
84
104
|
| 字段 | 类型 | 适用生成器 | 说明 | 默认值 |
|
|
85
105
|
|------|------|-----------|------|--------|
|
|
86
|
-
| `projectName` | string | micro-react | 项目名称 | 当前目录名 |
|
|
106
|
+
| `projectName` | string | micro-react、h5-react | 项目名称 | 当前目录名 |
|
|
87
107
|
| `appId` | string | micro-react | 开发环境 `window.__MICO_CONFIG__.appId`(请求代理等) | `portal_dev` |
|
|
88
|
-
| `packageScope` | string | 所有 | 包作用域(如 `@my-company`) | micro-react:
|
|
89
|
-
| `cdnPrefix` | string | micro-react | CDN 路径前缀(如 `portal`、`admin/v2
|
|
90
|
-
| `author` | string | micro-react | 作者信息 |
|
|
91
|
-
| `
|
|
92
|
-
| `
|
|
108
|
+
| `packageScope` | string | 所有 | 包作用域(如 `@my-company`) | micro-react / h5-react: 见各生成器提示;其他: 多从根 `package.json` 检测 |
|
|
109
|
+
| `cdnPrefix` | string | micro-react、h5-react | CDN 路径前缀(如 `portal`、`admin/v2`),写入 CICD 脚本中的 `CDN_PUBLIC_PATH` 等 | 空字符串 |
|
|
110
|
+
| `author` | string | micro-react、h5-react、subapp-h5 | 作者信息 | 见各生成器提示 |
|
|
111
|
+
| `initialSubAppName` | string | h5-react | 首个子应用目录名(`apps/` 下) | `app` |
|
|
112
|
+
| `initialSubAppDevPort` | string | h5-react | 首个子应用独立 `pnpm dev` 端口 | `8000` |
|
|
113
|
+
| `defaultSubappName` | string | subapp-react、subapp-h5 | 子应用默认名称 | subapp-react: `subapp`;subapp-h5: `app` |
|
|
114
|
+
| `devPort` | string | subapp-react、subapp-h5 | 子应用开发端口 | subapp-react: `8010`;subapp-h5: `8000` |
|
|
93
115
|
| `defaultUmdName` | string | subapp-umd | UMD 包默认名称 | `my-widget` |
|
|
94
116
|
| `umdDevPort` | string | subapp-umd | UMD 包开发端口 | `9100` |
|
|
95
117
|
|
|
@@ -111,7 +133,9 @@ mico create micro-react
|
|
|
111
133
|
- Husky + Commitlint
|
|
112
134
|
- @common-web/sentry 错误监控与 SourceMap 上传
|
|
113
135
|
|
|
114
|
-
|
|
136
|
+
若需要 **Umi 4 H5 多应用 + 开发网关 / dev 预设**,请使用 **h5-react**(见 [docs/h5-react-generator.md](docs/h5-react-generator.md))。
|
|
137
|
+
|
|
138
|
+
## React 子应用生成器(subapp-react)
|
|
115
139
|
|
|
116
140
|
该生成器会复制 `apps/homepage` 模板为新的子应用,并替换标识字符串。
|
|
117
141
|
`config/` 目录下的多环境配置会完整保留。
|
|
@@ -121,6 +145,39 @@ cd <monorepo-root>
|
|
|
121
145
|
mico create subapp-react
|
|
122
146
|
```
|
|
123
147
|
|
|
148
|
+
详见 [docs/subapp-react-generator.md](docs/subapp-react-generator.md)。
|
|
149
|
+
|
|
150
|
+
## H5 Monorepo 生成器(h5-react)
|
|
151
|
+
|
|
152
|
+
用于创建 **Umi 4** 多子应用 H5 仓库:pnpm workspace、Turborepo、开发网关(`page.config.ts`)、dev 预设,并**联动** **`subapp-h5`** 生成首个 `apps/<名>/` 子应用。内部包含 11 个 workspace 包:**`domain`**(API/CDN/多语言基址)、**`js-bridge`**(H5 ↔ 原生通信)、**`request`**(基于 Umi 的统一请求;`isShowLoading` 默认 `true`)、**`common-intl`**(`init()` 经 `js-bridge.getUserInfo` 取语言)、**`components`**(沉浸式 H5 布局)、**`constant`** / **`deeplink`**、**`umi-config`**(**子应用 `config/*.ts` 全部委托到此包的工厂**,并内置 Sentry sourcemap 上传插件 **`src/plugins/apply-sentry-plugin.ts`**)、**`utils`**、**`eslint`**、**`typescript`**。模板内已接入 **`@common-web/sentry`**(子应用布局错误边界、生产构建 externals),根目录提供 **`build` / `build:development` / `build:testing` / `build:production`** 与 CICD 各环境对应;环境变量 **`.env.development` / `.env.testing` / `.env.production`** 集中维护在仓库根,`lint-staged` 通过 **`.lintstagedrc.js`** 集中维护。`pnpm-workspace.yaml` 的 **catalog** 钉扎 `umi`、`react*`、`tailwindcss`、`tailwindcss-safe-area`、`@umijs/plugins`、`cross-env`、`@common-web/sentry` 等版本(**`@sentry/webpack-plugin`** 仅装在 `packages/umi-config`,不在仓库根、不在子应用)。
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
mkdir my-h5 && cd my-h5
|
|
156
|
+
mico create h5-react
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
若当前目录已存在 `pnpm-workspace.yaml`,需使用 **`mico create h5-react --force`**(会覆盖已有文件,请谨慎)。
|
|
160
|
+
|
|
161
|
+
详见 [docs/h5-react-generator.md](docs/h5-react-generator.md)。
|
|
162
|
+
|
|
163
|
+
## H5 子应用生成器(subapp-h5)
|
|
164
|
+
|
|
165
|
+
在由 **h5-react** 初始化的 Monorepo **根目录**执行,在 `apps/<名>/` 下新增 Umi 子应用,并更新根目录 **`page.config.ts`**、**`dev.preset.json`**。子应用模板默认:
|
|
166
|
+
|
|
167
|
+
- **`config/`** 全部委托到 **`<%= packageScope %>/umi-config`**(`createBaseConfig` / `createDevConfig` / `createProConfig` / `createDevelopmentConfig` / `createTestingConfig` / `createProductionConfig`);不再在子应用里重抄 `plugins`、`request: {}`、`externals` 或 Sentry 上传逻辑——`createProductionConfig` 自动接入 sourcemap 上传(需 `SENTRY_AUTH_TOKEN`)
|
|
168
|
+
- **`src/intl.ts` + `src/app.tsx`**:`init({ tag, indexedDBParams })` 取得 `{ fetchMultilingualData, i18n }`,首屏前 `fetchMultilingualData()`;`init()` 内部经 `<%= packageScope %>/js-bridge` 的 `getUserInfo()` 取语言
|
|
169
|
+
- **`src/layouts/index.tsx`**:`<SentryErrorBoundary><Outlet/></SentryErrorBoundary>`
|
|
170
|
+
- **`src/services/<域>.ts`** 就近定义请求/响应 interface 与服务函数;**`mock/<域>.ts`** 复用 `<%= packageScope %>/utils/mock` 的 `baseUrl` / `tryProxy`(zod 入参校验、mockjs 占位、可选 `?remote=` 透传到真实后端)
|
|
171
|
+
- **Tailwind 3 + `tailwindcss-safe-area`**:`tailwind.css`(含 `font-size: 16px;` + `1vw` 适配)、`tailwind.config.js`(**ESM**,扫描 `./src/**` + `packages/components/src`,挂安全区插件)
|
|
172
|
+
- **`config/routes.ts`** 仅含静态基础路由;动态菜单可与 `window.__MICO_MENUS__` 等配合
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
cd <h5-monorepo-root>
|
|
176
|
+
mico create subapp-h5
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
详见 [docs/subapp-h5-generator.md](docs/subapp-h5-generator.md)。
|
|
180
|
+
|
|
124
181
|
## UMD 组件包生成器
|
|
125
182
|
|
|
126
183
|
在 Monorepo 的 `packages/` 目录下创建 UMD 格式的组件包,使用 Webpack 构建。适用于通过 `<script>` 标签加载的场景(如主应用菜单挂载组件、第三方系统嵌入 Widget 等)。
|
|
@@ -149,6 +206,63 @@ mico create subapp-umd
|
|
|
149
206
|
|
|
150
207
|
DevTools Sources 面板中可在 `webpack://<name>/src/` 下定位原始 TypeScript 源码进行断点调试。
|
|
151
208
|
|
|
209
|
+
## Multica Desktop 自托管配置(`setup multica-desktop`)
|
|
210
|
+
|
|
211
|
+
[Multica Desktop](https://multica.ai/docs/zh/desktop-app) 默认连接 Multica Cloud;要让它指向公司自托管实例,需要在用户目录写入 `~/.multica/desktop.json`([配置规范见官方文档](https://github.com/multica-ai/multica/blob/main/apps/docs/content/docs/desktop-app.zh.mdx))。`mico setup multica-desktop` 把这个一次性配置封装成了跨平台命令:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
mico setup multica-desktop
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
写入的默认内容(指向米可自托管地址):
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"schemaVersion": 1,
|
|
222
|
+
"apiUrl": "https://multica-api.micoplatform.com",
|
|
223
|
+
"appUrl": "https://multica.micoplatform.com"
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
`wsUrl` 不写,由 Desktop 按官方规则从 `apiUrl` 自动推导为 `wss://multica-api.micoplatform.com/ws`。
|
|
228
|
+
|
|
229
|
+
### 目标路径(跨平台)
|
|
230
|
+
|
|
231
|
+
| 平台 | 实际路径 |
|
|
232
|
+
|---|---|
|
|
233
|
+
| macOS | `/Users/<Username>/.multica/desktop.json` |
|
|
234
|
+
| Linux | `/home/<Username>/.multica/desktop.json` |
|
|
235
|
+
| Windows | `C:\Users\<Username>\.multica\desktop.json` |
|
|
236
|
+
|
|
237
|
+
路径统一通过 `os.homedir()` 解析,三平台无需任何额外参数。
|
|
238
|
+
|
|
239
|
+
### 默认行为
|
|
240
|
+
|
|
241
|
+
- 如果文件**不存在**:创建 `.multica` 目录,写入默认配置。
|
|
242
|
+
- 如果文件**已存在**:先备份为 `desktop.json.bak.<时间戳>`,再覆盖。
|
|
243
|
+
- 完成后需要**重启 Multica Desktop** 让配置生效。
|
|
244
|
+
|
|
245
|
+
### 可选参数
|
|
246
|
+
|
|
247
|
+
| 参数 | 说明 |
|
|
248
|
+
|---|---|
|
|
249
|
+
| `--dry-run` | 仅预览输出内容,不写盘 |
|
|
250
|
+
| `--no-backup` | 已存在时直接覆盖,不生成 `.bak` |
|
|
251
|
+
| `--force` | 同 `--no-backup`,沿用全局 `--force` 语义 |
|
|
252
|
+
| `--api-url=<url>` | 覆盖默认 `apiUrl` |
|
|
253
|
+
| `--app-url=<url>` | 覆盖默认 `appUrl` |
|
|
254
|
+
| `--ws-url=<url>` | 显式设置 `wsUrl`(不传则由 Desktop 自动推导) |
|
|
255
|
+
|
|
256
|
+
示例:
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
mico setup multica-desktop --dry-run
|
|
260
|
+
mico setup multica-desktop --no-backup
|
|
261
|
+
mico setup multica-desktop \
|
|
262
|
+
--api-url=https://api.your-domain \
|
|
263
|
+
--app-url=https://your-domain
|
|
264
|
+
```
|
|
265
|
+
|
|
152
266
|
## 开发指南
|
|
153
267
|
|
|
154
268
|
### 环境准备
|
|
@@ -174,6 +288,12 @@ mico create micro-react
|
|
|
174
288
|
# 测试 subapp-react 生成器(需在已有 monorepo 中执行)
|
|
175
289
|
mico create subapp-react
|
|
176
290
|
|
|
291
|
+
# 测试 h5-react(空目录)
|
|
292
|
+
mico create h5-react
|
|
293
|
+
|
|
294
|
+
# 测试 subapp-h5(需在含 apps/ 的 H5 monorepo 根目录执行)
|
|
295
|
+
mico create subapp-h5
|
|
296
|
+
|
|
177
297
|
# 测试 subapp-umd 生成器(需在已有 monorepo 中执行)
|
|
178
298
|
mico create subapp-umd
|
|
179
299
|
```
|
|
@@ -201,10 +321,13 @@ pnpm test:watch
|
|
|
201
321
|
| 目录/文件 | 说明 |
|
|
202
322
|
|----------|------|
|
|
203
323
|
| `tests/unit/utils.test.js` | `lib/utils.js` 的单元测试 |
|
|
324
|
+
| `tests/unit/setup-multica-desktop.test.js` | `lib/setup-multica-desktop.js` 单元测试(隔离 home 目录,覆盖首次写入 / 备份 / `--no-backup` / `--dry-run`) |
|
|
204
325
|
| `tests/integration/micro-react.test.js` | micro-react 生成器集成测试 |
|
|
205
326
|
| `tests/integration/subapp-react.test.js` | subapp-react 生成器集成测试 |
|
|
327
|
+
| `tests/integration/h5-react.test.js` | h5-react 生成器集成测试 |
|
|
328
|
+
| `tests/integration/subapp-h5.test.js` | subapp-h5 生成器集成测试 |
|
|
206
329
|
| `tests/integration/subapp-umd.test.js` | subapp-umd 生成器集成测试 |
|
|
207
|
-
| `tests/integration/mico-cli.test.js` | `mico` 入口子进程测试(help / version / list / create / doctor) |
|
|
330
|
+
| `tests/integration/mico-cli.test.js` | `mico` 入口子进程测试(help / version / list / create / doctor / setup) |
|
|
208
331
|
| `tests/helpers/setup.js` | 测试共享工具(路径常量、monorepo fixture 工厂) |
|
|
209
332
|
| `tests/helpers/mico-subprocess.js` | 子进程运行 `bin/mico.js` 工具函数 |
|
|
210
333
|
|
|
@@ -245,11 +368,15 @@ pnpm run sync:subapp-react-template -- <source-path>
|
|
|
245
368
|
|
|
246
369
|
```
|
|
247
370
|
mico-cli/
|
|
248
|
-
├── bin/mico.js # CLI
|
|
249
|
-
├── lib/
|
|
371
|
+
├── bin/mico.js # CLI 入口(命令解析、生成器调度、setup 子命令分发)
|
|
372
|
+
├── lib/
|
|
373
|
+
│ ├── utils.js # 共享工具函数(字符串转换、文件处理、npm 版本查询、配置加载)
|
|
374
|
+
│ └── setup-multica-desktop.js # `mico setup multica-desktop` 核心实现
|
|
250
375
|
├── generators/
|
|
251
|
-
│ ├── micro-react/ # Monorepo
|
|
376
|
+
│ ├── micro-react/ # Monorepo 项目生成器(qiankun)
|
|
252
377
|
│ ├── subapp-react/ # React 子应用生成器
|
|
378
|
+
│ ├── h5-react/ # H5 Monorepo(Umi + 网关 / 预设)
|
|
379
|
+
│ ├── subapp-h5/ # H5 Umi 子应用
|
|
253
380
|
│ └── subapp-umd/ # UMD 组件包生成器
|
|
254
381
|
├── scripts/ # 辅助脚本
|
|
255
382
|
├── tests/ # 测试文件
|
package/bin/mico.js
CHANGED
|
@@ -25,6 +25,7 @@ Usage: mico <command> [options]
|
|
|
25
25
|
Commands:
|
|
26
26
|
create <generator> Run a generator (e.g., mico create subapp-react)
|
|
27
27
|
list List all available generators
|
|
28
|
+
setup <target> Run a setup task (e.g., mico setup multica-desktop)
|
|
28
29
|
update Update mico-cli to the latest version
|
|
29
30
|
doctor Check environment dependencies
|
|
30
31
|
|
|
@@ -36,12 +37,25 @@ Options:
|
|
|
36
37
|
--force Overwrite all existing files without confirmation
|
|
37
38
|
--no-update-check Skip update check
|
|
38
39
|
|
|
40
|
+
Setup targets:
|
|
41
|
+
multica-desktop Write ~/.multica/desktop.json for self-hosted Multica
|
|
42
|
+
Options:
|
|
43
|
+
--api-url=<url> override apiUrl
|
|
44
|
+
--app-url=<url> override appUrl
|
|
45
|
+
--ws-url=<url> override wsUrl (auto-derived if omitted)
|
|
46
|
+
--no-backup skip creating .bak before overwrite
|
|
47
|
+
--dry-run preview without writing
|
|
48
|
+
|
|
39
49
|
Examples:
|
|
40
50
|
mico create subapp-react
|
|
41
51
|
mico create micro-react --verbose
|
|
42
52
|
mico create micro-react --dry-run
|
|
43
53
|
mico create micro-react --force
|
|
54
|
+
mico create subapp-h5
|
|
55
|
+
mico create h5-react
|
|
44
56
|
mico list
|
|
57
|
+
mico setup multica-desktop
|
|
58
|
+
mico setup multica-desktop --dry-run
|
|
45
59
|
mico update
|
|
46
60
|
mico doctor
|
|
47
61
|
|
|
@@ -338,6 +352,50 @@ function performUpdate(latestVersion) {
|
|
|
338
352
|
}
|
|
339
353
|
}
|
|
340
354
|
|
|
355
|
+
/**
|
|
356
|
+
* 解析形如 `--key=value` 的带值标志(仅识别白名单 key)。
|
|
357
|
+
* @param {string[]} args
|
|
358
|
+
* @param {string[]} keys
|
|
359
|
+
* @returns {Record<string, string>}
|
|
360
|
+
*/
|
|
361
|
+
function parseValueFlags(args, keys) {
|
|
362
|
+
const result = {};
|
|
363
|
+
for (const raw of args) {
|
|
364
|
+
if (!raw.startsWith('--')) continue;
|
|
365
|
+
const eq = raw.indexOf('=');
|
|
366
|
+
if (eq === -1) continue;
|
|
367
|
+
const key = raw.slice(2, eq);
|
|
368
|
+
if (!keys.includes(key)) continue;
|
|
369
|
+
result[key] = raw.slice(eq + 1);
|
|
370
|
+
}
|
|
371
|
+
return result;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* 运行 `mico setup multica-desktop`,把仓库根的 lib 模块作为单一实现源。
|
|
376
|
+
* @param {string[]} extraArgs setup 后剩余的参数
|
|
377
|
+
* @param {{ dryRun?: boolean, force?: boolean }} globalFlags 来自 main 的全局标志
|
|
378
|
+
*/
|
|
379
|
+
async function runSetupMulticaDesktop(extraArgs, globalFlags = {}) {
|
|
380
|
+
const { runSetupMulticaDesktop: run } = require('../lib/setup-multica-desktop');
|
|
381
|
+
const noBackup = extraArgs.includes('--no-backup');
|
|
382
|
+
const values = parseValueFlags(extraArgs, ['api-url', 'app-url', 'ws-url']);
|
|
383
|
+
|
|
384
|
+
try {
|
|
385
|
+
run({
|
|
386
|
+
apiUrl: values['api-url'],
|
|
387
|
+
appUrl: values['app-url'],
|
|
388
|
+
wsUrl: values['ws-url'],
|
|
389
|
+
dryRun: Boolean(globalFlags.dryRun),
|
|
390
|
+
force: Boolean(globalFlags.force),
|
|
391
|
+
noBackup,
|
|
392
|
+
});
|
|
393
|
+
} catch (err) {
|
|
394
|
+
console.error(`❌ Error: ${err.message}`);
|
|
395
|
+
process.exit(1);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
341
399
|
/**
|
|
342
400
|
* 运行 Yeoman 生成器
|
|
343
401
|
* @param {string} generator - 生成器名称
|
|
@@ -460,6 +518,24 @@ async function main() {
|
|
|
460
518
|
process.exit(success ? 0 : 1);
|
|
461
519
|
}
|
|
462
520
|
|
|
521
|
+
// 处理 setup 命令
|
|
522
|
+
if (command === 'setup') {
|
|
523
|
+
const target = rest[0];
|
|
524
|
+
if (!target) {
|
|
525
|
+
console.error('❌ Error: missing setup target.');
|
|
526
|
+
console.error(' Available targets: multica-desktop');
|
|
527
|
+
printHelp();
|
|
528
|
+
process.exit(1);
|
|
529
|
+
}
|
|
530
|
+
if (target === 'multica-desktop') {
|
|
531
|
+
await runSetupMulticaDesktop(rest.slice(1), { dryRun: isDryRun, force: isForce });
|
|
532
|
+
process.exit(0);
|
|
533
|
+
}
|
|
534
|
+
console.error(`❌ Unknown setup target: ${target}`);
|
|
535
|
+
console.error(' Available targets: multica-desktop');
|
|
536
|
+
process.exit(1);
|
|
537
|
+
}
|
|
538
|
+
|
|
463
539
|
// 处理 update 命令
|
|
464
540
|
if (command === 'update') {
|
|
465
541
|
const updateInfo = await checkForUpdate();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
["node_modules", "dist", ".umi", ".umi-production", ".turbo", "pnpm-lock.yaml", ".gitkeep"]
|