@farris/cli 2.3.7 → 2.3.9

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 (171) hide show
  1. package/lib/commands/add-app.js +5 -5
  2. package/lib/commands/add-app.js.map +1 -1
  3. package/lib/commands/add-lib.js +5 -5
  4. package/lib/commands/add-lib.js.map +1 -1
  5. package/lib/commands/add-micro.js +12 -0
  6. package/lib/commands/add-micro.js.map +1 -0
  7. package/lib/commands/add-project.js +196 -194
  8. package/lib/commands/add-project.js.map +1 -1
  9. package/lib/commands/build-components.js +60 -60
  10. package/lib/commands/build-components.js.map +1 -1
  11. package/lib/commands/build-css.js +38 -38
  12. package/lib/commands/build-css.js.map +1 -1
  13. package/lib/commands/build-lib.js +30 -30
  14. package/lib/commands/build-lib.js.map +1 -1
  15. package/lib/commands/build.js +19 -19
  16. package/lib/commands/build.js.map +1 -1
  17. package/lib/commands/create-app-options.js +85 -74
  18. package/lib/commands/create-app-options.js.map +1 -1
  19. package/lib/commands/create-app.js +131 -131
  20. package/lib/commands/create-app.js.map +1 -1
  21. package/lib/commands/create-options.js +58 -32
  22. package/lib/commands/create-options.js.map +1 -1
  23. package/lib/commands/create.js +341 -331
  24. package/lib/commands/create.js.map +1 -1
  25. package/lib/commands/dev-serve.js +18 -18
  26. package/lib/commands/extract-i18n.js +74 -74
  27. package/lib/commands/extract-i18n.js.map +1 -1
  28. package/lib/commands/generate/api.js +124 -124
  29. package/lib/commands/generate/api.js.map +1 -1
  30. package/lib/commands/generate/common.js +101 -101
  31. package/lib/commands/generate/common.js.map +1 -1
  32. package/lib/commands/generate/component.js +156 -156
  33. package/lib/commands/generate/component.js.map +1 -1
  34. package/lib/commands/generate/view.js +168 -168
  35. package/lib/commands/generate/view.js.map +1 -1
  36. package/lib/commands/preview-serve.js +16 -16
  37. package/lib/commands/workspace/add-app.js +15 -15
  38. package/lib/commands/workspace/add-app.js.map +1 -1
  39. package/lib/commands/workspace/create.js +62 -62
  40. package/lib/commands/workspace/create.js.map +1 -1
  41. package/lib/commands/workspace/inspect.js +30 -30
  42. package/lib/commands/workspace/inspect.js.map +1 -1
  43. package/lib/commands/workspace/verify.js +38 -38
  44. package/lib/commands/workspace/verify.js.map +1 -1
  45. package/lib/common/agents-doc.js +33 -33
  46. package/lib/common/agents-doc.js.map +1 -1
  47. package/lib/common/apply-catalog-deps.js +15 -15
  48. package/lib/common/apply-catalog-deps.js.map +1 -1
  49. package/lib/common/component-file-name.js +3 -3
  50. package/lib/common/constant.js +85 -84
  51. package/lib/common/constant.js.map +1 -1
  52. package/lib/common/create-app-target.js +46 -46
  53. package/lib/common/create-app-target.js.map +1 -1
  54. package/lib/common/generate-app.js +106 -109
  55. package/lib/common/generate-app.js.map +1 -1
  56. package/lib/common/get-dependencies.js +9 -9
  57. package/lib/common/get-farris-config.js +25 -25
  58. package/lib/common/get-farris-config.js.map +1 -1
  59. package/lib/common/get-version.js +6 -6
  60. package/lib/common/get-vite-config.js +192 -192
  61. package/lib/common/get-vite-config.js.map +1 -1
  62. package/lib/common/lib-package-exports.js +24 -24
  63. package/lib/common/lib-package-exports.js.map +1 -1
  64. package/lib/common/list-lib-components.js +23 -23
  65. package/lib/common/list-lib-components.js.map +1 -1
  66. package/lib/common/output.js +164 -164
  67. package/lib/common/output.js.map +1 -1
  68. package/lib/common/project-layout.js +155 -183
  69. package/lib/common/project-layout.js.map +1 -1
  70. package/lib/common/safety.js +172 -173
  71. package/lib/common/safety.js.map +1 -1
  72. package/lib/common/template-manifest.js +18 -14
  73. package/lib/common/template-manifest.js.map +1 -1
  74. package/lib/common/template-renderer.js +114 -114
  75. package/lib/common/template-renderer.js.map +1 -1
  76. package/lib/common/transaction.js +83 -83
  77. package/lib/common/transaction.js.map +1 -1
  78. package/lib/common/verifier.js +187 -201
  79. package/lib/common/verifier.js.map +1 -1
  80. package/lib/common/workspace-contract.js +191 -157
  81. package/lib/common/workspace-contract.js.map +1 -1
  82. package/lib/config/vite-app.js +13 -13
  83. package/lib/config/vite-common.js +20 -20
  84. package/lib/config/vite-common.js.map +1 -1
  85. package/lib/config/vite-component.js +32 -32
  86. package/lib/config/vite-component.js.map +1 -1
  87. package/lib/config/vite-lib.js +26 -26
  88. package/lib/config/vite-lib.js.map +1 -1
  89. package/lib/index.js +261 -238
  90. package/lib/index.js.map +1 -1
  91. package/lib/plugins/create-app-package-json.js +23 -23
  92. package/lib/plugins/create-component-style.js +44 -44
  93. package/lib/plugins/create-package-json.js +48 -48
  94. package/lib/plugins/create-package-json.js.map +1 -1
  95. package/lib/plugins/dts.js +8 -8
  96. package/lib/plugins/html-system.js +9 -9
  97. package/lib/plugins/mock.js +240 -292
  98. package/lib/plugins/mock.js.map +1 -1
  99. package/lib/plugins/msw-adapter.js +141 -0
  100. package/lib/plugins/msw-adapter.js.map +1 -0
  101. package/lib/plugins/replace.js +17 -17
  102. package/lib/plugins/systemjs-bundle.js +15 -15
  103. package/lib/plugins/systemjs-bundle.js.map +1 -1
  104. package/package.json +6 -1
  105. package/templates/create/.gitignore.tpl +28 -8
  106. package/templates/create/AGENTS.md +76 -45
  107. package/templates/create/README.md +44 -11
  108. package/templates/create/package.json +2 -1
  109. package/templates/lib/.gitignore.tpl +31 -1
  110. package/templates/lib/.gitlab-ci.yml +2 -2
  111. package/templates/lib/README.md +24 -1
  112. package/templates/lib/{test → components/__tests__}/index.spec.ts +1 -1
  113. package/templates/lib/{test → components/__tests__}/index.spec.tsx +2 -2
  114. package/templates/lib/farris.config.mjs +2 -2
  115. package/templates/lib/package.json +1 -1
  116. package/templates/lib/tsconfig.json +1 -2
  117. package/templates/lib/vitest.config.ts +4 -2
  118. package/templates/micro/.eslintrc.cjs +15 -0
  119. package/templates/micro/.gitignore.tpl +33 -0
  120. package/templates/micro/.gitlab-ci.yml +59 -0
  121. package/templates/micro/.prettierrc.json +8 -0
  122. package/templates/micro/farris.config.mjs +34 -0
  123. package/templates/micro/index.html +12 -0
  124. package/templates/micro/mock/README.md +53 -0
  125. package/templates/micro/mock/tsconfig.json +10 -0
  126. package/templates/micro/package.json +47 -0
  127. package/templates/micro/src/App.tsx +25 -0
  128. package/templates/micro/src/locales/index.ts +5 -0
  129. package/templates/micro/src/locales/zh-CHS.json +1 -0
  130. package/templates/micro/src/main.ts +47 -0
  131. package/templates/micro/src/router/index.ts +24 -0
  132. package/templates/micro/src/views/AboutView.tsx +12 -0
  133. package/templates/micro/src/views/HomeView.tsx +13 -0
  134. package/templates/micro/src/views/__tests__/AboutView.spec.tsx +11 -0
  135. package/templates/micro/src/views/__tests__/HomeView.spec.tsx +11 -0
  136. package/templates/micro/tsconfig.json +18 -0
  137. package/templates/micro/vitest.config.ts +12 -0
  138. package/templates/mobile/.gitignore.tpl +25 -24
  139. package/templates/mobile/farris.config.mjs +2 -2
  140. package/templates/mobile/mock/README.md +39 -20
  141. package/templates/mobile/mock/tsconfig.json +10 -0
  142. package/templates/mobile/package.json +5 -2
  143. package/templates/mobile/src/main.ts +5 -40
  144. package/templates/mobile/src/views/HomeView.tsx +2 -2
  145. package/templates/mobile/src/views/__tests__/AboutView.spec.tsx +11 -0
  146. package/templates/mobile/src/views/__tests__/HomeView.spec.tsx +11 -0
  147. package/templates/mobile/tsconfig.json +1 -2
  148. package/templates/mobile/vitest.config.ts +4 -2
  149. package/templates/web/.gitignore.tpl +25 -24
  150. package/templates/web/farris.config.mjs +2 -2
  151. package/templates/web/mock/README.md +39 -20
  152. package/templates/web/mock/tsconfig.json +10 -0
  153. package/templates/web/package.json +5 -2
  154. package/templates/web/src/App.tsx +0 -4
  155. package/templates/web/src/main.ts +5 -40
  156. package/templates/web/src/views/HomeView.tsx +2 -2
  157. package/templates/web/src/views/__tests__/AboutView.spec.tsx +11 -0
  158. package/templates/web/src/views/__tests__/HomeView.spec.tsx +11 -0
  159. package/templates/web/tsconfig.json +1 -2
  160. package/templates/web/vitest.config.ts +4 -2
  161. package/templates/mobile/src/components/TheButton.tsx +0 -9
  162. package/templates/mobile/test/src/components/TheButton.spec.ts +0 -15
  163. package/templates/mobile/test/src/components/TheButton.spec.tsx +0 -15
  164. package/templates/web/src/components/TheButton.tsx +0 -9
  165. package/templates/web/src/micro-app.d.ts +0 -20
  166. package/templates/web/src/styles/index.css +0 -0
  167. package/templates/web/test/src/components/TheButton.spec.ts +0 -15
  168. package/templates/web/test/src/components/TheButton.spec.tsx +0 -15
  169. /package/templates/{web → micro}/src/micro/context.ts +0 -0
  170. /package/templates/{mobile → micro}/src/micro-app.d.ts +0 -0
  171. /package/templates/{mobile/src/styles/index.css → micro/src/styles/index.scss} +0 -0
@@ -11,8 +11,8 @@ export default {
11
11
  return `index.${format}.js`;
12
12
  }
13
13
  },
14
- outDir: './lib',
15
- componentOutDir: './lib/components',
14
+ outDir: './dist',
15
+ componentOutDir: './dist/components',
16
16
  externalDependencies: true,
17
17
  minify: true
18
18
  };
@@ -16,7 +16,7 @@
16
16
  "url": "git@gitee.com:ubml/farris-vue.git"
17
17
  },
18
18
  "files": [
19
- "lib"
19
+ "dist"
20
20
  ],
21
21
  "sideEffects": [
22
22
  "**/*.css",
@@ -2,8 +2,7 @@
2
2
  "extends": "@vue/tsconfig/tsconfig.dom.json",
3
3
  "include": [
4
4
  "components/**/*",
5
- "src/**/*",
6
- "test/**/*"
5
+ "src/**/*"
7
6
  ],
8
7
  "compilerOptions": {
9
8
  "strict": true
@@ -1,10 +1,12 @@
1
1
  import vue from '@vitejs/plugin-vue';
2
- import { defineConfig } from 'vitest/config';
2
+ import { configDefaults, defineConfig } from 'vitest/config';
3
3
 
4
4
  export default defineConfig({
5
5
  plugins: [vue()],
6
6
  test: {
7
7
  environment: 'jsdom',
8
- include: ['test/**/*.spec.{ts,tsx}']
8
+ // 官方默认收集范围(**/*.{test,spec}.*),源码旁的测试才会被收集
9
+ include: [...configDefaults.include],
10
+ exclude: [...configDefaults.exclude, '**/__sandbox_*/**']
9
11
  }
10
12
  });
@@ -0,0 +1,15 @@
1
+ /* eslint-env node */
2
+ require('@rushstack/eslint-patch/modern-module-resolution');
3
+
4
+ module.exports = {
5
+ root: true,
6
+ 'extends': [
7
+ 'plugin:vue/vue3-essential',
8
+ 'eslint:recommended',
9
+ '@vue/eslint-config-typescript',
10
+ '@vue/eslint-config-prettier/skip-formatting'
11
+ ],
12
+ parserOptions: {
13
+ ecmaVersion: 'latest'
14
+ }
15
+ };
@@ -0,0 +1,33 @@
1
+ # 依赖与产物
2
+ node_modules/
3
+ dist/
4
+ dist-es/
5
+ dist-ssr/
6
+ coverage/
7
+ *.tsbuildinfo
8
+ .pnpm-store/
9
+
10
+ # 日志与本地文件
11
+ *.log
12
+ .DS_Store
13
+ *.local
14
+ .env
15
+ .env.*
16
+ !.env.example
17
+ package-lock.json
18
+
19
+ # 编辑器
20
+ .vscode/*
21
+ !.vscode/extensions.json
22
+ !.vscode/settings.json
23
+ .idea/
24
+ .history
25
+ *.sw?
26
+
27
+ # AI 工具
28
+ .codebuddy/
29
+ .cursor/
30
+ .claude/
31
+ .windsurf/
32
+ .trae/
33
+ .opencode/
@@ -0,0 +1,59 @@
1
+ image: registry.inspures.com/public/docker.io/library/node:22
2
+
3
+ variables:
4
+ NPM_REGISTRY: "https://repos.iec.io/repository/npm-igix/"
5
+ NPM_RELEASE_REGISTRY: "https://repos.iec.io/repository/npm-igix-release/"
6
+
7
+ stages:
8
+ - build
9
+ - publishproject
10
+
11
+ build-job:
12
+ stage: build
13
+ tags:
14
+ - environment:cloud
15
+ before_script:
16
+ - |
17
+ if [ -z "${ARTIFACTS_REPO_USERNAME}" ] || [ -z "${ARTIFACTS_REPO_PASSWORD}" ]; then
18
+ echo "ARTIFACTS_REPO_USERNAME or ARTIFACTS_REPO_PASSWORD is empty on ${CI_COMMIT_REF_NAME}."
19
+ echo "If these GitLab CI/CD variables are Protected, they are not available on unprotected branches."
20
+ exit 1
21
+ fi
22
+ - if [ ! -f .npmrc ]; then wget -O - https://repos.iec.io/gitlab-ci/template/experimental/script/npmrc | sh; fi
23
+ - echo _auth=$(echo -n ${ARTIFACTS_REPO_USERNAME}:${ARTIFACTS_REPO_PASSWORD} | base64) >> .npmrc
24
+ - echo always-auth=true >> .npmrc
25
+ - sed -i "s#registry=.*#registry=$NPM_REGISTRY#g" $CI_PROJECT_DIR/.npmrc
26
+ - cp .npmrc ~/
27
+ - npm config fix
28
+ script:
29
+ - npm i --no-package-lock
30
+ - npm test
31
+ - npm run build
32
+ artifacts:
33
+ expire_in: '5days'
34
+ name: 'dist'
35
+ paths:
36
+ - $CI_PROJECT_DIR/dist
37
+
38
+ publish-project:
39
+ stage: publishproject
40
+ tags:
41
+ - environment:cloud
42
+ rules:
43
+ - if: $CI_COMMIT_TAG =~ /^v\d/
44
+ before_script:
45
+ - |
46
+ if [ -z "${ARTIFACTS_REPO_USERNAME}" ] || [ -z "${ARTIFACTS_REPO_PASSWORD}" ]; then
47
+ echo "ARTIFACTS_REPO_USERNAME or ARTIFACTS_REPO_PASSWORD is empty on ${CI_COMMIT_REF_NAME}."
48
+ echo "If these GitLab CI/CD variables are Protected, they are not available on unprotected branches."
49
+ exit 1
50
+ fi
51
+ - if [ ! -f .npmrc ]; then wget -O - https://repos.iec.io/gitlab-ci/template/experimental/script/npmrc | sh; fi
52
+ - echo _auth=$(echo -n ${ARTIFACTS_REPO_USERNAME}:${ARTIFACTS_REPO_PASSWORD} | base64) >> .npmrc
53
+ - echo always-auth=true >> .npmrc
54
+ - sed -i "s#registry=.*#registry=$NPM_RELEASE_REGISTRY#g" $CI_PROJECT_DIR/.npmrc
55
+ - cp .npmrc ~/
56
+ - npm config fix
57
+ script:
58
+ - npm config set //repos.iec.io/repository/npm-igix-release/:_auth=$(echo -n ${ARTIFACTS_REPO_USERNAME}:${ARTIFACTS_REPO_PASSWORD} | base64)
59
+ - cd dist && npm publish
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/prettierrc",
3
+ "semi": false,
4
+ "tabWidth": 2,
5
+ "singleQuote": true,
6
+ "printWidth": 100,
7
+ "trailingComma": "none"
8
+ }
@@ -0,0 +1,34 @@
1
+ import { fileURLToPath, URL } from 'node:url';
2
+
3
+ export default {
4
+ // 相对路径 base:微前端(IBP)与 iframe 嵌入场景都适用
5
+ base: './',
6
+ routerMode: 'hash',
7
+ // 微应用交付:默认 iife 单文件(IBP 微前端);需要普通 ESM 产物时执行 pnpm build:es
8
+ format: "<%= format %>",
9
+ // 输出目录 App/Lib 模式默认值均为 './dist'
10
+ // outDir: fileURLToPath(new URL('./dist', import.meta.url)),
11
+ // 最小化 默认值 true
12
+ minify: true,
13
+ // 外部依赖排除项 默认值 { include: [], exclude: [] }
14
+ // externals: {
15
+ // include: [],
16
+ // exclude: []
17
+ // },
18
+ // 是否排除 package.json 中 dependencies和 peerDependencies 依赖的包; App模式默认值 false Lib模式默认值 true
19
+ externalDependencies: false,
20
+ // 路径别名 默认值 null
21
+ alias: [
22
+ { find: '@', replacement: fileURLToPath(new URL('./src', import.meta.url)) }
23
+ ],
24
+ // 插件 默认值 [vue(), vueJsx()] 不要重复添加
25
+ // plugins: [],
26
+ // 开发期 mock 默认开启:接口数据来自工程内 mock/ 目录,未命中的请求按下方 proxy 转发
27
+ // mock: true,
28
+ // 开发代理:未命中 mock 的接口转发到真实后端;联调时执行 pnpm dev --no-mock 可整体关闭 mock
29
+ // proxy: {
30
+ // '/api': { target: 'http://localhost:8080', changeOrigin: true }
31
+ // },
32
+ // viteConfig 配置项
33
+ viteConfig: {}
34
+ };
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title><%= title %></title>
7
+ </head>
8
+ <body>
9
+ <div id="app"></div>
10
+ <script type="module" src="/src/main.ts"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,53 @@
1
+ # mock 目录
2
+
3
+ 开发期接口数据。用 MSW 写法,库本身的用法见 MSW 官方文档。一个领域一个文件,命名 `*.mock.ts`,只导出 handler 数组:
4
+
5
+ ```ts
6
+ import { http, HttpResponse, delay } from 'msw';
7
+
8
+ export const handlers = [
9
+ http.get('/api/v1/users', async ({ request }) => {
10
+ const keyword = new URL(request.url).searchParams.get('keyword') ?? '';
11
+ await delay(300); // 可选:模拟延迟,单位毫秒
12
+ return HttpResponse.json({ data: [], total: 0 }); // 形状跟客户端出口走
13
+ }),
14
+ http.get('/api/v1/users/:id', ({ params }) => HttpResponse.json({ data: { id: params.id } })),
15
+ http.post('/api/v1/users', async ({ request }) => {
16
+ const body = await request.json();
17
+ return HttpResponse.json({ id: 'u-new', ...body }, { status: 201 });
18
+ })
19
+ ];
20
+ ```
21
+
22
+ ## 加一条 mock 并验证
23
+
24
+ 1. 先在 `src/api/` 里确认实际请求路径(例如 `/api/v1/users`),逐字抄进 handler 路径,前缀也要带上。
25
+ 2. 新建或追加 `mock/<领域>.mock.ts`,按上面的形状写 handler;同一前缀下字面量路径写在 `:参数名` 之前。
26
+ 3. 在工程目录执行 `pnpm dev`,打开用到该接口的页面,**验证**返回的是 mock 数据。
27
+ 4. 需要联调真实后端时执行 `pnpm dev --no-mock`(或 `MOCK=none pnpm dev`),业务代码不改。
28
+
29
+ 规则:
30
+
31
+ - url 必须与代码实际发出的请求路径逐字一致,前缀也要带上;请求路径见 `src/api/` 下的接口模块。
32
+ - url 只写路径,以 `/` 开头,不要写协议与主机。写 `/api/v1/users`,不要写 `http://localhost:3000/api/v1/users`;主机或端口不同时不会命中。
33
+ - 路径参数在 url 里用 `:参数名` 表示,例如 `/api/v1/users/:id`。查询参数不写进 url,用 `new URL(request.url).searchParams` 读取。
34
+ - 同一前缀下同时有字面量路径与 `:参数名` 路径时,字面量写在前面。MSW 取第一个匹配的 handler,`/api/v1/users/current` 排在 `/api/v1/users/:id` 后面会被 `:id` 接走。
35
+ - 响应体必须能被工程的 HTTP 客户端正确消费,形状跟着客户端出口走。数据要有业务语义,用中文姓名、机构、单据号这类内容,不要用占位文本。
36
+ - 关键场景要模拟:空态、错误、慢响应。错误用 `HttpResponse.json(..., { status: 500 })`;慢响应用 `delay`。
37
+ - 目录里只放 handler 文件。共享数据或工具函数要放进 `_` 开头的文件,例如 `_data.ts`,加载时会跳过;其他文件会被当作 handler 文件加载,导出内容不是 handler 就会报错。
38
+ - 同一路径不允许在多个 mock 文件中重复定义,重复时开发服务启动或请求即报错。
39
+ - 文件只导出 handler 数组,写 `export const handlers = [...]` 或 `export default [...]`。不需要 `setupServer` / `setupWorker` 接线;接线由脚手架完成。
40
+ - `msw` 已由模板放进应用 `devDependencies`,版本随工作区 catalog 统一。不要把它加到 `dependencies`,也不要在 `mock/` 之外引用它,否则构建期会报错。
41
+ - mock 只用于开发期,不参与构建,也不要在组件里散落假数据。
42
+
43
+ 行为:
44
+
45
+ - 命中 mock 时返回 mock 数据。
46
+ - 未命中时按 `farris.config.mjs` 的 `proxy` 配置转发真实后端。
47
+ - 未命中且未配代理的 `/api` 路径返回 404 并提示,便于排查漏配。
48
+
49
+ 开关:在工程目录执行 `pnpm dev` 默认生效;`pnpm dev --no-mock` 或 `MOCK=none pnpm dev` 进入真实后端联调。
50
+
51
+ 类型:本目录附带独立的 `tsconfig.json`,只服务于编辑器与按需类型检查。应用自身的 `typecheck` 不包含本目录,mock 也不参与构建。
52
+
53
+ 约定版本 2026-09。本文件随 `@farris/cli` 模板发布,AI 协作以本文件为准。
@@ -0,0 +1,10 @@
1
+ {
2
+ // mock 目录的独立 TS 工程:只服务于编辑器与按需类型检查(应用自身的 typecheck 不含本目录)。
3
+ // msw 是应用的开发期依赖(见 package.json 的 devDependencies),按常规模块解析即可。
4
+ "extends": "../tsconfig.json",
5
+ "compilerOptions": {
6
+ "composite": false,
7
+ "noEmit": true
8
+ },
9
+ "include": ["**/*.ts", "**/*.d.ts"]
10
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "<%= name %>",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "farris": {
7
+ "type": "micro"
8
+ },
9
+ "scripts": {
10
+ "dev": "farris-cli dev",
11
+ "build": "farris-cli build -ep --format iife",
12
+ "build:es": "farris-cli build -ep --format es",
13
+ "preview": "farris-cli preview",
14
+ "test": "vitest run",
15
+ "test:watch": "vitest",
16
+ "typecheck": "vue-tsc --noEmit",
17
+ "lint": "eslint . --ext .vue,.ts,.tsx --fix",
18
+ "format": "prettier --write src/",
19
+ "i18n": "farris-cli extract-i18n"
20
+ },
21
+ "dependencies": {
22
+ "@farris/ui-vue": "latest",
23
+ "vue": "^3.4.29",
24
+ "vue-router": "^4.3.0"
25
+ },
26
+ "devDependencies": {
27
+ "@farris/cli": "<%= cliVersion %>",
28
+ "@rushstack/eslint-patch": "^1.8.0",
29
+ "@vitejs/plugin-vue": "^5.2.4",
30
+ "@vitejs/plugin-vue-jsx": "^3.0.0",
31
+ "@vue/eslint-config-prettier": "^9.0.0",
32
+ "@vue/eslint-config-typescript": "^13.0.0",
33
+ "@vue/test-utils": "^2.4.6",
34
+ "@vue/tsconfig": "^0.5.1",
35
+ "eslint": "^8.57.0",
36
+ "eslint-plugin-vue": "^9.23.0",
37
+ "jsdom": "^25.0.1",
38
+ "msw": "^2.15.0",
39
+ "prettier": "^3.2.5",
40
+ "typescript": "~5.4.0",
41
+ "vite": "^5.4.19",
42
+ "vite-plugin-css-injected-by-js": "^3.5.2",
43
+ "vitest": "^3.2.4",
44
+ "vue-tsc": "^2.2.0",
45
+ "sass": "^1.90.0"
46
+ }
47
+ }
@@ -0,0 +1,25 @@
1
+ import { defineComponent } from 'vue';
2
+ import { RouterLink, RouterView } from 'vue-router';
3
+ import { setupMicroAppContext } from './micro/context';
4
+
5
+ export default defineComponent({
6
+ name: 'App',
7
+ setup() {
8
+ // 微前端环境:订阅主应用下发的上下文(语言 / 主题)
9
+ setupMicroAppContext();
10
+
11
+ return () => (
12
+ <>
13
+ <header>
14
+ <div class="wrapper">
15
+ <nav>
16
+ <RouterLink to="/">Home</RouterLink>
17
+ <RouterLink to="/about">About</RouterLink>
18
+ </nav>
19
+ </div>
20
+ </header>
21
+ <RouterView />
22
+ </>
23
+ );
24
+ }
25
+ });
@@ -0,0 +1,5 @@
1
+ import zhCHS from './zh-CHS.json';
2
+
3
+ export const localResources = {
4
+ 'zh-CHS': zhCHS
5
+ };
@@ -0,0 +1,47 @@
1
+ import { createApp, type App as VueApp } from 'vue';
2
+ import FarrisVue from '@farris/ui-vue';
3
+ import '@farris/ui-vue/index.css';
4
+ import App from './App';
5
+ import router from './router';<%= styleImport %>
6
+ import { localResources } from './locales';
7
+
8
+ let app: VueApp | null = null;
9
+
10
+ /** 挂载应用(微前端宿主会调用 window.mount) */
11
+ function mount(): void {
12
+ if (app) {
13
+ return;
14
+ }
15
+ app = createApp(App);
16
+ app.use(FarrisVue, { basePath: '', locale: 'zh-CHS', localResources });
17
+ app.use(router);
18
+ app.mount('#app');
19
+
20
+ // 微前端环境:按平台下发的 initialPath 定位菜单配置的页面(fullPath)
21
+ // hash 路由必须保留这段兜底;history 路由下平台 defaultPage 已能直接命中,这里是幂等兜底
22
+ if (window.__MICRO_APP_ENVIRONMENT__) {
23
+ const rawPath = window.microApp?.getData?.()?.initialPath;
24
+ if (typeof rawPath === 'string' && rawPath !== '') {
25
+ // 平台下发的 initialPath 通常不带前导斜杠(如 'form'),这里统一归一化
26
+ const initialPath = rawPath.startsWith('/') ? rawPath : '/' + rawPath;
27
+ if (initialPath !== '/') {
28
+ router.isReady().then(() => router.replace(initialPath)).catch(() => undefined);
29
+ }
30
+ }
31
+ }
32
+ }
33
+
34
+ /** 卸载应用(微前端宿主会调用 window.unmount) */
35
+ function unmount(): void {
36
+ app?.unmount();
37
+ app = null;
38
+ }
39
+
40
+ // 微前端(micro-app)生命周期契约:必须暴露到 window
41
+ window.mount = mount;
42
+ window.unmount = unmount;
43
+
44
+ // 独立运行(浏览器直接访问 / iframe 嵌入)时自动挂载
45
+ if (!window.__MICRO_APP_ENVIRONMENT__) {
46
+ mount();
47
+ }
@@ -0,0 +1,24 @@
1
+ import { createRouter, createWebHashHistory, type RouteRecordRaw } from 'vue-router';
2
+
3
+ // 生成器(farris-cli generate view --with-route)依赖下面的 routes 数组赋值形式;
4
+ // 改动结构会导致路由无法自动注册。
5
+ export const routes: RouteRecordRaw[] = [
6
+ {
7
+ path: '/',
8
+ name: 'Home',
9
+ component: () => import('../views/HomeView')
10
+ },
11
+ {
12
+ path: '/about',
13
+ name: 'About',
14
+ component: () => import('../views/AboutView')
15
+ }
16
+ ];
17
+
18
+ const router = createRouter({
19
+ // hash 路由:微前端(IBP)下子应用 location 由宿主接管,hash 模式最稳妥
20
+ history: createWebHashHistory(),
21
+ routes
22
+ });
23
+
24
+ export default router;
@@ -0,0 +1,12 @@
1
+ import { defineComponent } from 'vue';
2
+
3
+ export default defineComponent({
4
+ name: 'AboutView',
5
+ setup() {
6
+ return () => (
7
+ <div class="about">
8
+ <h1>This is an about page</h1>
9
+ </div>
10
+ );
11
+ }
12
+ });
@@ -0,0 +1,13 @@
1
+ import { defineComponent } from 'vue';
2
+
3
+ export default defineComponent({
4
+ name: 'HomeView',
5
+ setup() {
6
+ return () => (
7
+ <main>
8
+ <h1>Home</h1>
9
+ <p>在 src/views/ 下新增页面;通用组件按需创建在 src/components/ 下。</p>
10
+ </main>
11
+ );
12
+ }
13
+ });
@@ -0,0 +1,11 @@
1
+ import { mount } from '@vue/test-utils';
2
+ import { describe, expect, it } from 'vitest';
3
+ import AboutView from '../AboutView';
4
+
5
+ describe('AboutView', () => {
6
+ it('mounts', () => {
7
+ const wrapper = mount(AboutView);
8
+
9
+ expect(wrapper.exists()).toBe(true);
10
+ });
11
+ });
@@ -0,0 +1,11 @@
1
+ import { mount } from '@vue/test-utils';
2
+ import { describe, expect, it } from 'vitest';
3
+ import HomeView from '../HomeView';
4
+
5
+ describe('HomeView', () => {
6
+ it('mounts', () => {
7
+ const wrapper = mount(HomeView);
8
+
9
+ expect(wrapper.exists()).toBe(true);
10
+ });
11
+ });
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "@vue/tsconfig/tsconfig.dom.json",
3
+ "include": [
4
+ "env.d.ts",
5
+ "src/**/*",
6
+ "src/**/*.vue"
7
+ ],
8
+ "compilerOptions": {
9
+ "composite": true,
10
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
11
+ "baseUrl": ".",
12
+ "paths": {
13
+ "@/*": [
14
+ "./src/*"
15
+ ]
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,12 @@
1
+ import vue from '@vitejs/plugin-vue';
2
+ import { configDefaults, defineConfig } from 'vitest/config';
3
+
4
+ export default defineConfig({
5
+ plugins: [vue()],
6
+ test: {
7
+ environment: 'jsdom',
8
+ // 官方默认收集范围(**/*.{test,spec}.*),源码旁的测试才会被收集
9
+ include: [...configDefaults.include],
10
+ exclude: [...configDefaults.exclude, '**/__sandbox_*/**']
11
+ }
12
+ });
@@ -1,32 +1,33 @@
1
- # Logs
2
- logs
3
- *.log
4
- npm-debug.log*
5
- yarn-debug.log*
6
- yarn-error.log*
7
- pnpm-debug.log*
8
- lerna-debug.log*
1
+ # 依赖与产物
2
+ node_modules/
3
+ dist/
4
+ dist-es/
5
+ dist-ssr/
6
+ coverage/
7
+ *.tsbuildinfo
8
+ .pnpm-store/
9
9
 
10
- node_modules
11
- package-lock.json
10
+ # 日志与本地文件
11
+ *.log
12
12
  .DS_Store
13
- dist
14
- dist-es
15
- dist-ssr
16
- coverage
17
13
  *.local
14
+ .env
15
+ .env.*
16
+ !.env.example
17
+ package-lock.json
18
18
 
19
- /cypress/videos/
20
- /cypress/screenshots/
21
-
22
- # Editor directories and files
19
+ # 编辑器
23
20
  .vscode/*
24
21
  !.vscode/extensions.json
25
- .idea
26
- *.suo
27
- *.ntvs*
28
- *.njsproj
29
- *.sln
22
+ !.vscode/settings.json
23
+ .idea/
24
+ .history
30
25
  *.sw?
31
26
 
32
- *.tsbuildinfo
27
+ # AI 工具
28
+ .codebuddy/
29
+ .cursor/
30
+ .claude/
31
+ .windsurf/
32
+ .trae/
33
+ .opencode/
@@ -4,9 +4,9 @@ export default {
4
4
  // 相对路径 base:微前端(IBP)与 iframe 嵌入场景都适用
5
5
  base: './',
6
6
  routerMode: 'hash',
7
- // iife: IBP 微前端单文件产物(默认);如需普通 ESM 站点产物,执行 pnpm build:es
7
+ // 默认交付格式;pnpm build 会依次产出 es / umd / systemjs(iife 见 --format iife)
8
8
  format: "<%= format %>",
9
- // 输出目录 App模式默认值 './dist' Lib模式 './lib'
9
+ // 输出目录 App/Lib 模式默认值均为 './dist'
10
10
  // outDir: fileURLToPath(new URL('./dist', import.meta.url)),
11
11
  // 最小化 默认值 true
12
12
  minify: true,