@farris/cli 2.2.5 → 2.3.0

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 (165) hide show
  1. package/lib/commands/add-app.js +6 -0
  2. package/lib/commands/add-app.js.map +1 -0
  3. package/lib/commands/add-lib.js +6 -0
  4. package/lib/commands/add-lib.js.map +1 -0
  5. package/lib/commands/add-project.js +194 -0
  6. package/lib/commands/add-project.js.map +1 -0
  7. package/lib/commands/build-components.js +57 -50
  8. package/lib/commands/build-components.js.map +1 -1
  9. package/lib/commands/build-css.js +38 -38
  10. package/lib/commands/build-css.js.map +1 -1
  11. package/lib/commands/build-lib.js +30 -25
  12. package/lib/commands/build-lib.js.map +1 -1
  13. package/lib/commands/build.js +19 -14
  14. package/lib/commands/build.js.map +1 -1
  15. package/lib/commands/create-app-options.js +72 -74
  16. package/lib/commands/create-app-options.js.map +1 -1
  17. package/lib/commands/create-app.js +131 -126
  18. package/lib/commands/create-app.js.map +1 -1
  19. package/lib/commands/create-options.js +32 -29
  20. package/lib/commands/create-options.js.map +1 -1
  21. package/lib/commands/create.js +277 -224
  22. package/lib/commands/create.js.map +1 -1
  23. package/lib/commands/dev-serve.js +18 -18
  24. package/lib/commands/extract-i18n.js +74 -74
  25. package/lib/commands/extract-i18n.js.map +1 -1
  26. package/lib/commands/generate/api.js +124 -124
  27. package/lib/commands/generate/api.js.map +1 -1
  28. package/lib/commands/generate/common.js +101 -100
  29. package/lib/commands/generate/common.js.map +1 -1
  30. package/lib/commands/generate/component.js +156 -156
  31. package/lib/commands/generate/component.js.map +1 -1
  32. package/lib/commands/generate/view.js +168 -168
  33. package/lib/commands/generate/view.js.map +1 -1
  34. package/lib/commands/preview-serve.js +16 -16
  35. package/lib/commands/workspace/add-app.js +15 -180
  36. package/lib/commands/workspace/add-app.js.map +1 -1
  37. package/lib/commands/workspace/create.js +62 -379
  38. package/lib/commands/workspace/create.js.map +1 -1
  39. package/lib/commands/workspace/inspect.js +30 -30
  40. package/lib/commands/workspace/inspect.js.map +1 -1
  41. package/lib/commands/workspace/verify.js +38 -38
  42. package/lib/commands/workspace/verify.js.map +1 -1
  43. package/lib/common/agents-doc.js +34 -0
  44. package/lib/common/agents-doc.js.map +1 -0
  45. package/lib/common/apply-catalog-deps.js +15 -15
  46. package/lib/common/apply-catalog-deps.js.map +1 -1
  47. package/lib/common/component-file-name.js +3 -3
  48. package/lib/common/constant.js +64 -64
  49. package/lib/common/constant.js.map +1 -1
  50. package/lib/common/create-app-target.js +46 -46
  51. package/lib/common/create-app-target.js.map +1 -1
  52. package/lib/common/generate-app.js +109 -85
  53. package/lib/common/generate-app.js.map +1 -1
  54. package/lib/common/get-dependencies.js +9 -9
  55. package/lib/common/get-farris-config.js +25 -25
  56. package/lib/common/get-farris-config.js.map +1 -1
  57. package/lib/common/get-version.js +6 -6
  58. package/lib/common/get-vite-config.js +106 -106
  59. package/lib/common/get-vite-config.js.map +1 -1
  60. package/lib/common/lib-package-exports.js +24 -24
  61. package/lib/common/lib-package-exports.js.map +1 -1
  62. package/lib/common/list-lib-components.js +23 -23
  63. package/lib/common/list-lib-components.js.map +1 -1
  64. package/lib/common/output.js +164 -94
  65. package/lib/common/output.js.map +1 -1
  66. package/lib/common/project-layout.js +143 -0
  67. package/lib/common/project-layout.js.map +1 -0
  68. package/lib/common/safety.js +173 -171
  69. package/lib/common/safety.js.map +1 -1
  70. package/lib/common/template-manifest.js +14 -16
  71. package/lib/common/template-manifest.js.map +1 -1
  72. package/lib/common/template-renderer.js +114 -114
  73. package/lib/common/template-renderer.js.map +1 -1
  74. package/lib/common/transaction.js +83 -83
  75. package/lib/common/transaction.js.map +1 -1
  76. package/lib/common/verifier.js +194 -150
  77. package/lib/common/verifier.js.map +1 -1
  78. package/lib/common/workspace-contract.js +86 -0
  79. package/lib/common/workspace-contract.js.map +1 -0
  80. package/lib/config/vite-app.js +13 -13
  81. package/lib/config/vite-common.js +20 -20
  82. package/lib/config/vite-common.js.map +1 -1
  83. package/lib/config/vite-component.js +32 -32
  84. package/lib/config/vite-component.js.map +1 -1
  85. package/lib/config/vite-lib.js +26 -26
  86. package/lib/index.js +234 -205
  87. package/lib/index.js.map +1 -1
  88. package/lib/plugins/create-app-package-json.js +24 -0
  89. package/lib/plugins/create-app-package-json.js.map +1 -0
  90. package/lib/plugins/create-component-style.js +44 -44
  91. package/lib/plugins/create-package-json.js +48 -48
  92. package/lib/plugins/create-package-json.js.map +1 -1
  93. package/lib/plugins/dts.js +8 -8
  94. package/lib/plugins/html-system.js +9 -9
  95. package/lib/plugins/replace.js +17 -17
  96. package/lib/plugins/systemjs-bundle.js +15 -15
  97. package/lib/plugins/systemjs-bundle.js.map +1 -1
  98. package/package.json +53 -52
  99. package/templates/create/.gitignore.tpl +12 -0
  100. package/templates/create/.npmrc.tpl +1 -0
  101. package/templates/create/AGENTS.md +62 -0
  102. package/templates/create/CLAUDE.md +1 -0
  103. package/templates/create/README.md +14 -1
  104. package/templates/create/package.json +11 -3
  105. package/templates/create/pnpm-workspace.yaml +2 -1
  106. package/templates/lib/.eslintrc.cjs +15 -0
  107. package/templates/lib/.gitignore.tpl +3 -0
  108. package/templates/lib/.prettierrc.json +8 -0
  109. package/templates/lib/index.html +1 -1
  110. package/templates/lib/package.json +39 -4
  111. package/templates/lib/{components → test/components}/button/button.spec.ts +3 -2
  112. package/templates/lib/test/components/button/button.spec.tsx +11 -0
  113. package/templates/lib/tsconfig.json +5 -1
  114. package/templates/lib/vitest.config.ts +1 -1
  115. package/templates/mobile/.gitignore.tpl +31 -0
  116. package/templates/mobile/.gitlab-ci.yml +3 -9
  117. package/templates/mobile/index.html +1 -1
  118. package/templates/mobile/package.json +14 -10
  119. package/templates/mobile/src/main.ts +5 -4
  120. package/templates/mobile/src/router/index.ts +17 -17
  121. package/templates/mobile/test/src/components/TheButton.spec.ts +15 -0
  122. package/templates/mobile/test/src/components/TheButton.spec.tsx +15 -0
  123. package/templates/mobile/tsconfig.json +3 -2
  124. package/templates/mobile/vitest.config.ts +2 -1
  125. package/templates/web/.gitignore.tpl +31 -0
  126. package/templates/web/.gitlab-ci.yml +3 -9
  127. package/templates/web/index.html +1 -1
  128. package/templates/web/package.json +14 -10
  129. package/templates/web/src/locales/index.ts +5 -0
  130. package/templates/web/src/locales/zh-CN.json +1 -0
  131. package/templates/web/src/main.ts +5 -2
  132. package/templates/web/src/router/index.ts +17 -17
  133. package/templates/web/src/styles/index.css +0 -0
  134. package/templates/web/src/styles/index.scss +0 -0
  135. package/templates/web/test/src/components/TheButton.spec.ts +15 -0
  136. package/templates/web/test/src/components/TheButton.spec.tsx +15 -0
  137. package/templates/web/tsconfig.json +3 -2
  138. package/templates/web/vitest.config.ts +2 -1
  139. package/lib/common/project-package-name.js +0 -5
  140. package/lib/common/project-package-name.js.map +0 -1
  141. package/templates/mobile/.changeset/README.md +0 -4
  142. package/templates/mobile/.changeset/config.json +0 -11
  143. package/templates/mobile/project.json +0 -4
  144. package/templates/mobile/src/components/TheButton.spec.ts +0 -8
  145. package/templates/web/.changeset/README.md +0 -4
  146. package/templates/web/.changeset/config.json +0 -11
  147. package/templates/web/project.json +0 -4
  148. package/templates/web/src/components/TheButton.spec.ts +0 -8
  149. package/templates/workspace/app/farris.config.mjs +0 -13
  150. package/templates/workspace/app/index.html +0 -12
  151. package/templates/workspace/app/package.json +0 -22
  152. package/templates/workspace/app/src/App.tsx +0 -11
  153. package/templates/workspace/app/src/main.ts +0 -12
  154. package/templates/workspace/app/src/router/index.ts +0 -16
  155. package/templates/workspace/app/src/views/home/composables/use-home.ts +0 -7
  156. package/templates/workspace/app/src/views/home/home.component.tsx +0 -15
  157. package/templates/workspace/app/src/views/home/index.ts +0 -4
  158. package/templates/workspace/app/tsconfig.json +0 -21
  159. package/templates/workspace/root/README.md +0 -28
  160. package/templates/workspace/root/package.json +0 -13
  161. package/templates/workspace/root/pnpm-workspace.yaml +0 -12
  162. /package/templates/{workspace/app → mobile}/src/locales/index.ts +0 -0
  163. /package/templates/{workspace/app → mobile}/src/locales/zh-CN.json +0 -0
  164. /package/templates/{workspace/app → mobile}/src/styles/index.css +0 -0
  165. /package/templates/{workspace/app → mobile}/src/styles/index.scss +0 -0
@@ -1,33 +1,33 @@
1
- import { mergeConfig } from 'vite';
2
- import CommonConfig from './vite-common.js';
3
- import { replace } from '../plugins/replace.js';
4
- import { createComponentStyle } from '../plugins/create-component-style.js';
5
- import { getPackageName } from '../common/constant.js';
6
- import { componentFileName } from '../common/component-file-name.js';
7
- export default mergeConfig(CommonConfig, {
8
- logLevel: 'silent',
9
- plugins: [createComponentStyle(), replace((format, args) => `../${args[0]}/index.${format}.js`)],
10
- build: {
11
- emptyOutDir: false,
12
- lib: {
13
- fileName: (format, entryName) => componentFileName(format, entryName),
14
- formats: ['es']
15
- },
16
- rollupOptions: {
17
- output: {
18
- exports: 'named',
19
- globals: (id) => {
20
- if (id.includes(getPackageName())) {
21
- const name = id.split('/').pop() || '';
22
- return name.slice(0, 1).toUpperCase() + name.slice(1);
23
- }
24
- const map = {
25
- vue: 'Vue'
26
- };
27
- return map[id];
28
- }
29
- }
30
- }
31
- }
32
- });
1
+ import { mergeConfig } from 'vite';
2
+ import CommonConfig from './vite-common.js';
3
+ import { replace } from '../plugins/replace.js';
4
+ import { createComponentStyle } from '../plugins/create-component-style.js';
5
+ import { getPackageName } from '../common/constant.js';
6
+ import { componentFileName } from '../common/component-file-name.js';
7
+ export default mergeConfig(CommonConfig, {
8
+ logLevel: 'silent',
9
+ plugins: [createComponentStyle(), replace((format, args) => `../${args[0]}/index.${format}.js`)],
10
+ build: {
11
+ emptyOutDir: false,
12
+ lib: {
13
+ fileName: (format, entryName) => componentFileName(format, entryName),
14
+ formats: ['es']
15
+ },
16
+ rollupOptions: {
17
+ output: {
18
+ exports: 'named',
19
+ globals: (id) => {
20
+ if (id.includes(getPackageName())) {
21
+ const name = id.split('/').pop() || '';
22
+ return name.slice(0, 1).toUpperCase() + name.slice(1);
23
+ }
24
+ const map = {
25
+ vue: 'Vue'
26
+ };
27
+ return map[id];
28
+ }
29
+ }
30
+ }
31
+ }
32
+ });
33
33
  //# sourceMappingURL=vite-component.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite-component.js","sourceRoot":"","sources":["../../src/config/vite-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAErE,eAAe,WAAW,CAAC,YAAY,EAAE;IACvC,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,CAAC,oBAAoB,EAAE,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,UAAU,MAAM,KAAK,CAAC,CAAC;IAChG,KAAK,EAAE;QACL,WAAW,EAAE,KAAK;QAClB,GAAG,EAAE;YACH,QAAQ,EAAE,CAAC,MAAc,EAAE,SAAiB,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,EAAE,SAAS,CAAC;YACrF,OAAO,EAAE,CAAC,IAAI,CAAC;SAChB;QACD,aAAa,EAAE;YACb,MAAM,EAAE;gBACN,OAAO,EAAE,OAAO;gBAChB,OAAO,EAAE,CAAC,EAAU,EAAE,EAAE;oBACtB,IAAI,EAAE,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,EAAE,CAAC;wBAClC,MAAM,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;wBACvC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;oBACxD,CAAC;oBACD,MAAM,GAAG,GAA2B;wBAClC,GAAG,EAAE,KAAK;qBACX,CAAC;oBACF,OAAO,GAAG,CAAC,EAAE,CAAC,CAAC;gBACjB,CAAC;aACF;SACF;KACF;CACF,CAAC,CAAC"}
1
+ {"version":3,"file":"vite-component.js","sourceRoot":"","sources":["../../src/config/vite-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAErE,eAAe,WAAW,CAAC,YAAY,EAAE;IACvC,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,CAAC,oBAAoB,EAAE,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,UAAU,MAAM,KAAK,CAAC,CAAC;IAChG,KAAK,EAAE;QACL,WAAW,EAAE,KAAK;QAClB,GAAG,EAAE;YACH,QAAQ,EAAE,CAAC,MAAc,EAAE,SAAiB,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,EAAE,SAAS,CAAC;YACrF,OAAO,EAAE,CAAC,IAAI,CAAC;SAChB;QACD,aAAa,EAAE;YACb,MAAM,EAAE;gBACN,OAAO,EAAE,OAAO;gBAChB,OAAO,EAAE,CAAC,EAAU,EAAE,EAAE;oBACtB,IAAI,EAAE,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,EAAE;wBACjC,MAAM,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;wBACvC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;qBACvD;oBACD,MAAM,GAAG,GAA2B;wBAClC,GAAG,EAAE,KAAK;qBACX,CAAC;oBACF,OAAO,GAAG,CAAC,EAAE,CAAC,CAAC;gBACjB,CAAC;aACF;SACF;KACF;CACF,CAAC,CAAC"}
@@ -1,27 +1,27 @@
1
- import { mergeConfig } from 'vite';
2
- import { resolve } from "node:path";
3
- import { CWD, getPackageName } from '../common/constant.js';
4
- import { systemjsBundle } from '../plugins/systemjs-bundle.js';
5
- import CommonConfig from "./vite-common.js";
6
- export default mergeConfig(CommonConfig, {
7
- logLevel: 'silent',
8
- plugins: [systemjsBundle()],
9
- build: {
10
- lib: {
11
- entry: resolve(CWD, `./src/main.ts`),
12
- fileName: "index",
13
- },
14
- target: 'es2019',
15
- outDir: resolve(CWD, `./lib`),
16
- rollupOptions: {
17
- output: {
18
- exports: "named",
19
- globals: {
20
- vue: "Vue",
21
- [getPackageName()]: getPackageName()
22
- }
23
- }
24
- },
25
- }
26
- });
1
+ import { mergeConfig } from 'vite';
2
+ import { resolve } from "node:path";
3
+ import { CWD, getPackageName } from '../common/constant.js';
4
+ import { systemjsBundle } from '../plugins/systemjs-bundle.js';
5
+ import CommonConfig from "./vite-common.js";
6
+ export default mergeConfig(CommonConfig, {
7
+ logLevel: 'silent',
8
+ plugins: [systemjsBundle()],
9
+ build: {
10
+ lib: {
11
+ entry: resolve(CWD, `./src/main.ts`),
12
+ fileName: "index",
13
+ },
14
+ target: 'es2019',
15
+ outDir: resolve(CWD, `./lib`),
16
+ rollupOptions: {
17
+ output: {
18
+ exports: "named",
19
+ globals: {
20
+ vue: "Vue",
21
+ [getPackageName()]: getPackageName()
22
+ }
23
+ }
24
+ },
25
+ }
26
+ });
27
27
  //# sourceMappingURL=vite-lib.js.map
package/lib/index.js CHANGED
@@ -1,206 +1,235 @@
1
- #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { getVersion } from './common/get-version.js';
4
- const program = new Command();
5
- program.version(`@farris/cli ${getVersion()}`);
6
- // ==========================================
7
- // 存量命令 (保持向后兼容)
8
- // ==========================================
9
- program
10
- .command('build')
11
- .description('构建应用产物')
12
- .option('-c, --configFile [configFile]', 'Farris 配置文件路径')
13
- .option('-vc, --viteConfigFile [viteConfigFile]', 'Vite 配置文件路径')
14
- .option('-b, --base [base]', '覆盖构建公共路径 Base (如 / 或 ./ 或 /apps/xxx/)')
15
- .action(async (options) => {
16
- process.env.BUILD_TYPE = 'app';
17
- const { buildCommon } = await import('./commands/build.js');
18
- await buildCommon(options);
19
- });
20
- program
21
- .command('build-lib')
22
- .description('构建 Library 产物')
23
- .option('-c, --configFile [configFile]', 'Farris 配置文件路径')
24
- .option('-vc, --viteConfigFile [viteConfigFile]', 'Vite 配置文件路径')
25
- .option('-f, --format [format]', '产物格式 (es | umd | systemjs)')
26
- .option('-d, --dts', '是否生成类型声明文件')
27
- .option('-ep, --emitPackage', '是否生成 package.json')
28
- .action(async (options) => {
29
- process.env.BUILD_TYPE = 'lib';
30
- const { buildLib } = await import('./commands/build-lib.js');
31
- await buildLib(options);
32
- });
33
- program
34
- .command('build-components')
35
- .description('构建组件库产物')
36
- .option('-c, --configFile [configFile]', 'Farris 配置文件路径')
37
- .option('-vc, --viteConfigFile [viteConfigFile]', 'Vite 配置文件路径')
38
- .action(async (options) => {
39
- process.env.BUILD_TYPE = 'components';
40
- const { buildComponents } = await import('./commands/build-components.js');
41
- await buildComponents(options);
42
- });
43
- program
44
- .command('build-css')
45
- .description('构建样式产物')
46
- .option('-e, --entry [entry]', '样式入口文件')
47
- .option('-o, --outfile [outfile]', '样式输出文件')
48
- .option('-m, --minify [minify]', '是否压缩')
49
- .action(async (options) => {
50
- process.env.BUILD_TYPE = 'css';
51
- const { buildCss } = await import('./commands/build-css.js');
52
- await buildCss(options);
53
- });
54
- program
55
- .command('create [name]')
56
- .description('新建 pnpm workspace,可选创建一个工程')
57
- .option('-y, --yes', '使用默认值,跳过问答')
58
- .option('--json', '以 JSON 格式输出结果')
59
- .option('--app <appName>', '非交互时指定工程目录名')
60
- .option('--no-app', '不创建工程')
61
- .option('--install', '生成后执行 pnpm install')
62
- .action(async (name, options) => {
63
- const { create } = await import('./commands/create.js');
64
- const noApp = options.noApp === true || options.app === false;
65
- const app = typeof options.app === 'string' ? options.app : undefined;
66
- await create(name, {
67
- yes: options.yes,
68
- json: options.json,
69
- install: options.install,
70
- app,
71
- noApp
72
- });
73
- });
74
- program
75
- .command('create-app [name]')
76
- .description('新建 App / Lib 模板')
77
- .option('--type <type>', '工程类型 (app | lib)')
78
- .option('--platform <platform>', '应用平台 (web | mobile)')
79
- .option('--formats <formats>', 'lib 产物格式,逗号分隔 (es,cjs,umd,systemjs)')
80
- .option('--format <format>', 'app 产物格式 (es | umd | systemjs)')
81
- .option('-y, --yes', '使用默认值,跳过问答')
82
- .option('--json', '以 JSON 格式输出结果')
83
- .action(async (name, options) => {
84
- const { createApp } = await import('./commands/create-app.js');
85
- await createApp(name, options);
86
- });
87
- program
88
- .command('dev')
89
- .description('创建 Dev Server')
90
- .option('-p, --port [port]', '开发服务器端口')
91
- .action(async (options) => {
92
- process.env.BUILD_TYPE = 'app';
93
- const { devServe } = await import('./commands/dev-serve.js');
94
- await devServe(options);
95
- });
96
- program
97
- .command('preview')
98
- .description('创建 Preview Server')
99
- .option('-p, --port [port]', '预览服务器端口')
100
- .action(async (options) => {
101
- process.env.BUILD_TYPE = 'app';
102
- const { previewServe } = await import('./commands/preview-serve.js');
103
- await previewServe(options);
104
- });
105
- program
106
- .command('extract-i18n')
107
- .description('抽取国际化资源到 JSON 文件')
108
- .option('-c, --configFile [configFile]', '国际化配置文件路径')
109
- .action(async (options) => {
110
- const { extractI18n } = await import('./commands/extract-i18n.js');
111
- await extractI18n(options);
112
- });
113
- // ==========================================
114
- // Workspace 命令组
115
- // ==========================================
116
- const workspaceCmd = program.command('workspace').description('Farris pnpm workspace 规范管理');
117
- workspaceCmd
118
- .command('inspect [target]')
119
- .description('检查目标目录安全状态')
120
- .option('--json', '以 JSON 格式输出结果')
121
- .action(async (target = '.', options) => {
122
- const { inspectWorkspace } = await import('./commands/workspace/inspect.js');
123
- await inspectWorkspace(target, options);
124
- });
125
- workspaceCmd
126
- .command('create [target]')
127
- .description('初始化标准 Farris Vue pnpm workspace')
128
- .option('-n, --name <name>', '应用名称 (package name)')
129
- .option('-t, --title <title>', '应用展示标题')
130
- .option('--router', '启用 Vue Router')
131
- .option('--router-mode <mode>', '路由模式 (hash | history)', 'hash')
132
- .option('--format <format>', '产物交付格式 (es | systemjs)', 'es')
133
- .option('--style <style>', '应用全局样式 (none | css | scss)', 'css')
134
- .option('--json', '以 JSON 格式输出结果')
135
- .option('--force', '确认覆盖与模板同名的已有文件(非交互模式必须显式指定)')
136
- .option('--install', '是否在初始化完成后自动安装依赖 (pnpm install)', false)
137
- .option('-y, --yes', '接受默认配置')
138
- .action(async (target = '.', options) => {
139
- const { createWorkspace } = await import('./commands/workspace/create.js');
140
- await createWorkspace(target, options);
141
- });
142
- workspaceCmd
143
- .command('add-app <name>')
144
- .description('在现有 Workspace 中添加新应用')
145
- .option('-t, --title <title>', '应用展示标题')
146
- .option('--router', '启用 Vue Router')
147
- .option('--router-mode <mode>', '路由模式 (hash | history)', 'hash')
148
- .option('--format <format>', '产物交付格式 (es | systemjs)', 'es')
149
- .option('--style <style>', '应用全局样式 (none | css | scss)', 'css')
150
- .option('--json', '以 JSON 格式输出结果')
151
- .action(async (name, options) => {
152
- const { addAppToWorkspace } = await import('./commands/workspace/add-app.js');
153
- await addAppToWorkspace(name, options);
154
- });
155
- workspaceCmd
156
- .command('verify [target]')
157
- .description('验证 Workspace 结构与规范合规性')
158
- .option('--json', '以 JSON 格式输出结果')
159
- .action(async (target = '.', options) => {
160
- const { verifyWorkspaceCommand } = await import('./commands/workspace/verify.js');
161
- await verifyWorkspaceCommand(target, options);
162
- });
163
- // ==========================================
164
- // Generate 命令组
165
- // ==========================================
166
- const generateCmd = program.command('generate').alias('g').description('应用级代码生成器');
167
- generateCmd
168
- .command('view <name>')
169
- .description('生成 View 页面 (含必须调用的 composable)')
170
- .option('-t, --title <title>', '页面展示标题')
171
- .option('--with-route', '自动在路由中注册页面')
172
- .option('--with-props', '生成页面 Props 文件')
173
- .option('--json', '以 JSON 格式输出结果')
174
- .action(async (name, options) => {
175
- const { generateView } = await import('./commands/generate/view.js');
176
- await generateView(name, options);
177
- });
178
- generateCmd
179
- .command('component <name>')
180
- .description('生成通用组件 (位于 src/components/)')
181
- .option('--with-props', '生成组件 Props 文件')
182
- .option('--no-props', '不生成组件 Props 文件')
183
- .option('--style <style>', '组件样式方案 (none | css | scss)', 'none')
184
- .option('--json', '以 JSON 格式输出结果')
185
- .action(async (name, options) => {
186
- const { generateComponent } = await import('./commands/generate/component.js');
187
- await generateComponent(name, options);
188
- });
189
- generateCmd
190
- .command('api <name>')
191
- .description('生成 API 模块 (位于 src/api/)')
192
- .option('-e, --endpoint <endpoint>', 'API 请求路径 (如 /api/v1/orders)')
193
- .option('-m, --method <method>', 'HTTP 请求方法 (get | post | put | patch | delete)', 'get')
194
- .option('--client <client>', '指定已有 HTTP 客户端路径')
195
- .option('--init-client', '若不存在则初始化标准 HTTP 客户端')
196
- .option('--json', '以 JSON 格式输出结果')
197
- .action(async (name, options) => {
198
- const { generateApi } = await import('./commands/generate/api.js');
199
- await generateApi(name, options);
200
- });
201
- program.parseAsync(process.argv).catch((err) => {
202
- const message = err instanceof Error ? err.message : String(err);
203
- console.error(message);
204
- process.exit(1);
205
- });
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { getVersion } from './common/get-version.js';
4
+ const program = new Command();
5
+ program.version(`@farris/cli ${getVersion()}`);
6
+ // ==========================================
7
+ // 存量命令 (保持向后兼容)
8
+ // ==========================================
9
+ program
10
+ .command('build')
11
+ .description('构建应用产物')
12
+ .option('-c, --configFile [configFile]', 'Farris 配置文件路径')
13
+ .option('-vc, --viteConfigFile [viteConfigFile]', 'Vite 配置文件路径')
14
+ .option('-b, --base [base]', '覆盖构建公共路径 Base (如 / 或 ./ 或 /apps/xxx/)')
15
+ .option('-ep, --emitPackage', '是否生成 dist/package.json 发布清单')
16
+ .action(async (options) => {
17
+ process.env.BUILD_TYPE = 'app';
18
+ const { buildCommon } = await import('./commands/build.js');
19
+ await buildCommon(options);
20
+ });
21
+ program
22
+ .command('build-lib')
23
+ .description('构建 Library 产物')
24
+ .option('-c, --configFile [configFile]', 'Farris 配置文件路径')
25
+ .option('-vc, --viteConfigFile [viteConfigFile]', 'Vite 配置文件路径')
26
+ .option('-f, --format [format]', '产物格式 (es | umd | systemjs)')
27
+ .option('-d, --dts', '是否生成类型声明文件')
28
+ .option('-ep, --emitPackage', '是否生成 package.json')
29
+ .action(async (options) => {
30
+ process.env.BUILD_TYPE = 'lib';
31
+ const { buildLib } = await import('./commands/build-lib.js');
32
+ await buildLib(options);
33
+ });
34
+ program
35
+ .command('build-components')
36
+ .description('构建组件库产物')
37
+ .option('-c, --configFile [configFile]', 'Farris 配置文件路径')
38
+ .option('-vc, --viteConfigFile [viteConfigFile]', 'Vite 配置文件路径')
39
+ .action(async (options) => {
40
+ process.env.BUILD_TYPE = 'components';
41
+ const { buildComponents } = await import('./commands/build-components.js');
42
+ await buildComponents(options);
43
+ });
44
+ program
45
+ .command('build-css')
46
+ .description('构建样式产物')
47
+ .option('-e, --entry [entry]', '样式入口文件')
48
+ .option('-o, --outfile [outfile]', '样式输出文件')
49
+ .option('-m, --minify [minify]', '是否压缩')
50
+ .action(async (options) => {
51
+ process.env.BUILD_TYPE = 'css';
52
+ const { buildCss } = await import('./commands/build-css.js');
53
+ await buildCss(options);
54
+ });
55
+ program
56
+ .command('create [name]')
57
+ .description('新建 pnpm workspace,可选创建一个工程')
58
+ .option('-y, --yes', '使用默认值,跳过问答')
59
+ .option('--json', '以 JSON 格式输出结果')
60
+ .option('--app <appName>', '非交互时指定工程目录名')
61
+ .option('--no-app', '不创建工程')
62
+ .option('--install', '生成后执行 pnpm install')
63
+ .option('--force', '确认覆盖与模板同名的已有文件(非交互模式必须显式指定)')
64
+ .action(async (name, options) => {
65
+ const { create } = await import('./commands/create.js');
66
+ const noApp = options.noApp === true || options.app === false;
67
+ const app = typeof options.app === 'string' ? options.app : undefined;
68
+ await create(name, {
69
+ yes: options.yes,
70
+ json: options.json,
71
+ install: options.install,
72
+ app,
73
+ noApp,
74
+ force: options.force
75
+ });
76
+ });
77
+ program
78
+ .command('add-app [name]')
79
+ .description('向当前 workspace 添加应用 → applications/<name>')
80
+ .option('-t, --title <title>', '应用展示标题')
81
+ .option('--platform <platform>', '应用平台 (web | mobile)', 'web')
82
+ .option('--style <style>', '应用全局样式 (none | css | scss)', 'css')
83
+ .option('--format <format>', '产物交付格式 (es | systemjs)', 'es')
84
+ .option('--json', '以 JSON 格式输出结果')
85
+ .option('--force', '确认覆盖与模板同名的已有文件')
86
+ .option('--install', '添加后执行 pnpm install', false)
87
+ .action(async (name, options) => {
88
+ const { addApp } = await import('./commands/add-app.js');
89
+ await addApp(name, options);
90
+ });
91
+ program
92
+ .command('add-lib [name]')
93
+ .description('向当前 workspace 添加组件库 → libraries/<name>')
94
+ .option('-t, --title <title>', '组件库展示标题')
95
+ .option('--formats <formats>', 'lib 产物格式,逗号分隔 (es,cjs,umd,systemjs)')
96
+ .option('--json', '以 JSON 格式输出结果')
97
+ .option('--force', '确认覆盖与模板同名的已有文件')
98
+ .option('--install', '添加后执行 pnpm install', false)
99
+ .action(async (name, options) => {
100
+ const { addLib } = await import('./commands/add-lib.js');
101
+ await addLib(name, options);
102
+ });
103
+ program
104
+ .command('create-app [name]')
105
+ .description('新建 App / Lib 模板')
106
+ .option('--type <type>', '工程类型 (app | lib)')
107
+ .option('--platform <platform>', '应用平台 (web | mobile)')
108
+ .option('--formats <formats>', 'lib 产物格式,逗号分隔 (es,cjs,umd,systemjs)')
109
+ .option('--format <format>', 'app 产物格式 (es | umd | systemjs)')
110
+ .option('-y, --yes', '使用默认值,跳过问答')
111
+ .option('--json', '以 JSON 格式输出结果')
112
+ .action(async (name, options) => {
113
+ const { createApp } = await import('./commands/create-app.js');
114
+ await createApp(name, options);
115
+ });
116
+ program
117
+ .command('dev')
118
+ .description('创建 Dev Server')
119
+ .option('-p, --port [port]', '开发服务器端口')
120
+ .action(async (options) => {
121
+ process.env.BUILD_TYPE = 'app';
122
+ const { devServe } = await import('./commands/dev-serve.js');
123
+ await devServe(options);
124
+ });
125
+ program
126
+ .command('preview')
127
+ .description('创建 Preview Server')
128
+ .option('-p, --port [port]', '预览服务器端口')
129
+ .action(async (options) => {
130
+ process.env.BUILD_TYPE = 'app';
131
+ const { previewServe } = await import('./commands/preview-serve.js');
132
+ await previewServe(options);
133
+ });
134
+ program
135
+ .command('extract-i18n')
136
+ .description('抽取国际化资源到 JSON 文件')
137
+ .option('-c, --configFile [configFile]', '国际化配置文件路径')
138
+ .action(async (options) => {
139
+ const { extractI18n } = await import('./commands/extract-i18n.js');
140
+ await extractI18n(options);
141
+ });
142
+ // ==========================================
143
+ // Workspace 命令组
144
+ // ==========================================
145
+ const workspaceCmd = program.command('workspace').description('Farris pnpm workspace 规范管理');
146
+ workspaceCmd
147
+ .command('inspect [target]')
148
+ .description('检查目标目录安全状态')
149
+ .option('--json', '以 JSON 格式输出结果')
150
+ .action(async (target = '.', options) => {
151
+ const { inspectWorkspace } = await import('./commands/workspace/inspect.js');
152
+ await inspectWorkspace(target, options);
153
+ });
154
+ workspaceCmd
155
+ .command('create [target]')
156
+ .description('初始化标准 Farris Vue pnpm workspace')
157
+ .option('-n, --name <name>', '应用名称 (package name)')
158
+ .option('-t, --title <title>', '应用展示标题')
159
+ .option('--router', '启用 Vue Router')
160
+ .option('--router-mode <mode>', '路由模式 (hash | history)', 'hash')
161
+ .option('--format <format>', '产物交付格式 (es | systemjs)', 'es')
162
+ .option('--style <style>', '应用全局样式 (none | css | scss)', 'css')
163
+ .option('--json', '以 JSON 格式输出结果')
164
+ .option('--force', '确认覆盖与模板同名的已有文件(非交互模式必须显式指定)')
165
+ .option('--install', '是否在初始化完成后自动安装依赖 (pnpm install)', false)
166
+ .option('-y, --yes', '接受默认配置')
167
+ .action(async (target = '.', options) => {
168
+ const { createWorkspace } = await import('./commands/workspace/create.js');
169
+ await createWorkspace(target, options);
170
+ });
171
+ workspaceCmd
172
+ .command('add-app <name>')
173
+ .description('[已废弃] 请改用 farris-cli add-app')
174
+ .option('-t, --title <title>', '应用展示标题')
175
+ .option('--router', '启用 Vue Router')
176
+ .option('--router-mode <mode>', '路由模式 (hash | history)', 'hash')
177
+ .option('--format <format>', '产物交付格式 (es | systemjs)', 'es')
178
+ .option('--style <style>', '应用全局样式 (none | css | scss)', 'css')
179
+ .option('--json', '以 JSON 格式输出结果')
180
+ .action(async (name, options) => {
181
+ const { addAppToWorkspace } = await import('./commands/workspace/add-app.js');
182
+ await addAppToWorkspace(name, options);
183
+ });
184
+ workspaceCmd
185
+ .command('verify [target]')
186
+ .description('验证 Workspace 结构与规范合规性')
187
+ .option('--json', '以 JSON 格式输出结果')
188
+ .action(async (target = '.', options) => {
189
+ const { verifyWorkspaceCommand } = await import('./commands/workspace/verify.js');
190
+ await verifyWorkspaceCommand(target, options);
191
+ });
192
+ // ==========================================
193
+ // Generate 命令组
194
+ // ==========================================
195
+ const generateCmd = program.command('generate').alias('g').description('应用级代码生成器');
196
+ generateCmd
197
+ .command('view <name>')
198
+ .description('生成 View 页面 (含必须调用的 composable)')
199
+ .option('-t, --title <title>', '页面展示标题')
200
+ .option('--with-route', '自动在路由中注册页面')
201
+ .option('--with-props', '生成页面 Props 文件')
202
+ .option('--json', '以 JSON 格式输出结果')
203
+ .action(async (name, options) => {
204
+ const { generateView } = await import('./commands/generate/view.js');
205
+ await generateView(name, options);
206
+ });
207
+ generateCmd
208
+ .command('component <name>')
209
+ .description('生成通用组件 (位于 src/components/)')
210
+ .option('--with-props', '生成组件 Props 文件')
211
+ .option('--no-props', '不生成组件 Props 文件')
212
+ .option('--style <style>', '组件样式方案 (none | css | scss)', 'none')
213
+ .option('--json', '以 JSON 格式输出结果')
214
+ .action(async (name, options) => {
215
+ const { generateComponent } = await import('./commands/generate/component.js');
216
+ await generateComponent(name, options);
217
+ });
218
+ generateCmd
219
+ .command('api <name>')
220
+ .description('生成 API 模块 (位于 src/api/)')
221
+ .option('-e, --endpoint <endpoint>', 'API 请求路径 (如 /api/v1/orders)')
222
+ .option('-m, --method <method>', 'HTTP 请求方法 (get | post | put | patch | delete)', 'get')
223
+ .option('--client <client>', '指定已有 HTTP 客户端路径')
224
+ .option('--init-client', '若不存在则初始化标准 HTTP 客户端')
225
+ .option('--json', '以 JSON 格式输出结果')
226
+ .action(async (name, options) => {
227
+ const { generateApi } = await import('./commands/generate/api.js');
228
+ await generateApi(name, options);
229
+ });
230
+ program.parseAsync(process.argv).catch((err) => {
231
+ const message = err instanceof Error ? err.message : String(err);
232
+ console.error(message);
233
+ process.exit(1);
234
+ });
206
235
  //# sourceMappingURL=index.js.map