@moluoxixi/create-app 2.0.4 → 2.0.402

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 (259) hide show
  1. package/LICENSE.txt +21 -21
  2. package/README.md +129 -129
  3. package/dist/commands/create.d.ts +2 -1
  4. package/dist/commands/create.js +12 -8
  5. package/dist/commands/index.d.ts +1 -2
  6. package/dist/commands/index.js +1 -2
  7. package/dist/constants/index.d.ts +17 -0
  8. package/dist/constants/index.js +17 -0
  9. package/dist/generators/index.d.ts +3 -4
  10. package/dist/generators/index.js +3 -4
  11. package/dist/generators/project.d.ts +3 -2
  12. package/dist/generators/project.js +5 -4
  13. package/dist/generators/react.d.ts +4 -2
  14. package/dist/generators/react.js +10 -30
  15. package/dist/generators/vue.d.ts +4 -2
  16. package/dist/generators/vue.js +10 -31
  17. package/dist/index.d.ts +0 -1
  18. package/dist/index.js +21 -3
  19. package/dist/test.d.ts +5 -2
  20. package/dist/test.js +252 -206
  21. package/dist/types/ejs.d.ts +0 -1
  22. package/dist/types/ejs.js +0 -1
  23. package/dist/types/features.d.ts +0 -1
  24. package/dist/types/features.js +0 -1
  25. package/dist/types/index.d.ts +2 -4
  26. package/dist/types/index.js +2 -4
  27. package/dist/types/packageJson.d.ts +24 -0
  28. package/dist/types/packageJson.js +4 -0
  29. package/dist/types/viteConfig.d.ts +11 -9
  30. package/dist/types/viteConfig.js +0 -1
  31. package/dist/utils/deepMerge.d.ts +3 -1
  32. package/dist/utils/deepMerge.js +8 -1
  33. package/dist/utils/ejs.d.ts +3 -2
  34. package/dist/utils/ejs.js +2 -1
  35. package/dist/utils/featureMapping.d.ts +44 -0
  36. package/dist/utils/featureMapping.js +119 -0
  37. package/dist/utils/file.d.ts +22 -2
  38. package/dist/utils/file.js +35 -2
  39. package/dist/utils/generateFrameworkProject.d.ts +27 -0
  40. package/dist/utils/generateFrameworkProject.js +47 -0
  41. package/dist/utils/index.d.ts +11 -9
  42. package/dist/utils/index.js +11 -9
  43. package/dist/utils/install.d.ts +7 -4
  44. package/dist/utils/install.js +55 -12
  45. package/dist/utils/npmConfig.d.ts +15 -0
  46. package/dist/utils/npmConfig.js +79 -0
  47. package/dist/utils/prompts.d.ts +3 -2
  48. package/dist/utils/prompts.js +51 -5
  49. package/dist/utils/renderFeatures.d.ts +3 -2
  50. package/dist/utils/renderFeatures.js +41 -37
  51. package/dist/utils/renderTemplate.d.ts +13 -1
  52. package/dist/utils/renderTemplate.js +128 -61
  53. package/dist/utils/sortDependencies.d.ts +3 -2
  54. package/dist/utils/sortDependencies.js +3 -2
  55. package/dist/utils/viteConfigRender.d.ts +11 -14
  56. package/dist/utils/viteConfigRender.js +10 -173
  57. package/package.json +4 -2
  58. package/templates/common/base/.env +7 -7
  59. package/templates/common/base/.env.development +5 -5
  60. package/templates/common/base/.env.production +5 -5
  61. package/templates/common/base/package.json +23 -27
  62. package/templates/common/base/scripts/build.mts +37 -31
  63. package/templates/common/base/src/apis/index.ts +8 -8
  64. package/templates/common/base/src/apis/request.ts +43 -43
  65. package/templates/common/base/src/apis/services/example.ts +61 -40
  66. package/templates/common/base/src/apis/services/user.ts +33 -23
  67. package/templates/common/base/src/apis/types/common.ts +43 -28
  68. package/templates/common/base/src/apis/types/example.ts +15 -3
  69. package/templates/common/base/src/apis/types/index.ts +7 -7
  70. package/templates/common/base/src/apis/types/user.ts +39 -24
  71. package/templates/common/base/src/assets/fonts/index.css +7 -7
  72. package/templates/common/base/src/assets/styles/base.scss +72 -72
  73. package/templates/common/base/src/assets/styles/custom.scss +7 -7
  74. package/templates/common/base/src/assets/styles/tailwind.scss +6 -6
  75. package/templates/common/base/src/constants/index.ts +29 -29
  76. package/templates/common/base/src/utils/index.ts +88 -83
  77. package/templates/{vue/base/vite.config.ts → common/base/vite.config.ts.ejs} +28 -11
  78. package/templates/common/features/husky/.cz-config.cjs +35 -35
  79. package/templates/common/features/husky/commitlint.config.ts +32 -32
  80. package/templates/common/features/husky/node_modules/.bin/commitizen +17 -0
  81. package/templates/common/features/husky/node_modules/.bin/commitizen.CMD +12 -0
  82. package/templates/common/features/husky/node_modules/.bin/commitizen.ps1 +41 -0
  83. package/templates/common/features/husky/node_modules/.bin/commitlint +17 -0
  84. package/templates/common/features/husky/node_modules/.bin/commitlint.CMD +12 -0
  85. package/templates/common/features/husky/node_modules/.bin/commitlint.ps1 +41 -0
  86. package/templates/common/features/husky/node_modules/.bin/cz +17 -0
  87. package/templates/common/features/husky/node_modules/.bin/cz-cust +17 -0
  88. package/templates/common/features/husky/node_modules/.bin/cz-cust.CMD +12 -0
  89. package/templates/common/features/husky/node_modules/.bin/cz-cust.ps1 +41 -0
  90. package/templates/common/features/husky/node_modules/.bin/cz-customizable +17 -0
  91. package/templates/common/features/husky/node_modules/.bin/cz-customizable.CMD +12 -0
  92. package/templates/common/features/husky/node_modules/.bin/cz-customizable.ps1 +41 -0
  93. package/templates/common/features/husky/node_modules/.bin/cz.CMD +12 -0
  94. package/templates/common/features/husky/node_modules/.bin/cz.ps1 +41 -0
  95. package/templates/common/features/husky/node_modules/.bin/git-cz +17 -0
  96. package/templates/common/features/husky/node_modules/.bin/git-cz.CMD +12 -0
  97. package/templates/common/features/husky/node_modules/.bin/git-cz.ps1 +41 -0
  98. package/templates/common/features/husky/node_modules/.bin/husky +17 -0
  99. package/templates/common/features/husky/node_modules/.bin/husky.CMD +12 -0
  100. package/templates/common/features/husky/node_modules/.bin/husky.ps1 +41 -0
  101. package/templates/common/features/husky/node_modules/.bin/lint-staged +17 -0
  102. package/templates/common/features/husky/node_modules/.bin/lint-staged.CMD +12 -0
  103. package/templates/common/features/husky/node_modules/.bin/lint-staged.ps1 +41 -0
  104. package/templates/common/features/husky/package.json +6 -6
  105. package/templates/react/base/env.d.ts +19 -19
  106. package/templates/react/base/index.html +14 -14
  107. package/templates/react/base/node_modules/.bin/vite +17 -0
  108. package/templates/react/base/node_modules/.bin/vite.CMD +12 -0
  109. package/templates/react/base/node_modules/.bin/vite.ps1 +41 -0
  110. package/templates/react/base/package.json +18 -15
  111. package/templates/react/base/src/App.tsx +18 -18
  112. package/templates/react/base/src/assets/styles/main.scss +8 -8
  113. package/templates/react/base/src/pages/about/index.tsx +14 -14
  114. package/templates/react/base/src/pages/home/index.tsx +14 -14
  115. package/templates/react/base/tsconfig.app.json +17 -17
  116. package/templates/react/base/tsconfig.base.json +23 -23
  117. package/templates/react/base/tsconfig.json +12 -12
  118. package/templates/react/base/tsconfig.node.json +15 -15
  119. package/templates/react/features/ant-design/package.json +6 -7
  120. package/templates/react/features/eslint/node_modules/.bin/eslint +17 -0
  121. package/templates/react/features/eslint/node_modules/.bin/eslint.CMD +12 -0
  122. package/templates/react/features/eslint/node_modules/.bin/eslint.ps1 +41 -0
  123. package/templates/react/features/eslint/package.json +3 -3
  124. package/templates/react/features/i18n/package.json +6 -7
  125. package/templates/react/features/i18n/src/locales/index.ts +7 -0
  126. package/templates/{common/base → react/features/i18n}/src/locales/lang/en.ts +30 -30
  127. package/templates/{common/base → react/features/i18n}/src/locales/lang/es.ts +30 -30
  128. package/templates/{common/base → react/features/i18n}/src/locales/lang/zh.ts +30 -30
  129. package/templates/react/features/manualRoutes/src/router/routes.tsx +13 -0
  130. package/templates/react/features/pageRoutes/package.json +1 -2
  131. package/templates/react/features/router/package.json +1 -1
  132. package/templates/react/features/sentry/package.json +6 -7
  133. package/templates/react/features/sentry/src/utils/sentry.ts +10 -0
  134. package/templates/react/features/zustand/package.json +1 -1
  135. package/templates/react/features/zustand/src/stores/user.ts +42 -6
  136. package/templates/react/features/zustand/src/types/stores.ts +8 -1
  137. package/templates/vue/base/env.d.ts +27 -27
  138. package/templates/vue/base/index.html +14 -14
  139. package/templates/vue/base/node_modules/.bin/vite +17 -0
  140. package/templates/vue/base/node_modules/.bin/vite.CMD +12 -0
  141. package/templates/vue/base/node_modules/.bin/vite.ps1 +41 -0
  142. package/templates/vue/base/node_modules/.bin/vue-tsc +17 -0
  143. package/templates/vue/base/node_modules/.bin/vue-tsc.CMD +12 -0
  144. package/templates/vue/base/node_modules/.bin/vue-tsc.ps1 +41 -0
  145. package/templates/vue/base/package.json +16 -13
  146. package/templates/vue/base/src/App.vue +13 -13
  147. package/templates/vue/base/src/assets/styles/main.scss +9 -9
  148. package/templates/vue/base/src/directives/index.ts +36 -36
  149. package/templates/vue/base/src/layouts/index.ts +5 -7
  150. package/templates/vue/base/src/pages/about/index.vue +31 -31
  151. package/templates/vue/base/src/pages/home/index.vue +31 -31
  152. package/templates/vue/base/tsconfig.app.json +17 -17
  153. package/templates/vue/base/tsconfig.base.json +23 -23
  154. package/templates/vue/base/tsconfig.json +12 -12
  155. package/templates/vue/base/tsconfig.node.json +15 -15
  156. package/templates/vue/features/ant-design-vue/package.json +6 -7
  157. package/templates/vue/{base → features/ant-design-vue}/src/layouts/AntDesign.vue +86 -86
  158. package/templates/vue/features/element-plus/package.json +6 -7
  159. package/templates/vue/{base → features/element-plus}/src/assets/styles/element/index.scss +27 -27
  160. package/templates/vue/features/element-plus/src/components/SubMenu/index.ts +9 -0
  161. package/templates/vue/{base → features/element-plus}/src/components/SubMenu/src/_types/index.ts +6 -6
  162. package/templates/vue/{base → features/element-plus}/src/components/SubMenu/src/_types/props.ts +11 -11
  163. package/templates/vue/{base → features/element-plus}/src/components/SubMenu/src/index.vue +24 -24
  164. package/templates/vue/{base → features/element-plus}/src/layouts/element.vue +81 -81
  165. package/templates/vue/features/eslint/node_modules/.bin/eslint +17 -0
  166. package/templates/vue/features/eslint/node_modules/.bin/eslint.CMD +12 -0
  167. package/templates/vue/features/eslint/node_modules/.bin/eslint.ps1 +41 -0
  168. package/templates/vue/features/eslint/package.json +3 -3
  169. package/templates/vue/features/i18n/package.json +5 -5
  170. package/templates/vue/features/i18n/src/locales/index.ts +23 -16
  171. package/templates/vue/features/i18n/src/locales/lang/en.ts +30 -0
  172. package/templates/vue/features/i18n/src/locales/lang/es.ts +30 -0
  173. package/templates/vue/features/i18n/src/locales/lang/zh.ts +30 -0
  174. package/templates/vue/features/manualRoutes/src/router/routes.ts +35 -27
  175. package/templates/vue/features/pageRoutes/package.json +5 -5
  176. package/templates/vue/features/pinia/package.json +3 -2
  177. package/templates/vue/features/pinia/src/stores/index.ts +8 -0
  178. package/templates/vue/features/pinia/src/stores/system.ts +60 -0
  179. package/templates/vue/features/pinia/src/stores/user.ts +33 -13
  180. package/templates/vue/features/qiankun/package.json +5 -5
  181. package/templates/vue/features/qiankun/src/qiankun/index.ts +19 -0
  182. package/templates/vue/features/router/package.json +1 -1
  183. package/templates/vue/features/sentry/package.json +6 -6
  184. package/templates/vue/features/sentry/src/utils/sentry.ts +12 -0
  185. package/dist/commands/create.d.ts.map +0 -1
  186. package/dist/commands/create.js.map +0 -1
  187. package/dist/commands/index.d.ts.map +0 -1
  188. package/dist/commands/index.js.map +0 -1
  189. package/dist/generators/index.d.ts.map +0 -1
  190. package/dist/generators/index.js.map +0 -1
  191. package/dist/generators/project.d.ts.map +0 -1
  192. package/dist/generators/project.js.map +0 -1
  193. package/dist/generators/react.d.ts.map +0 -1
  194. package/dist/generators/react.js.map +0 -1
  195. package/dist/generators/vue.d.ts.map +0 -1
  196. package/dist/generators/vue.js.map +0 -1
  197. package/dist/index.d.ts.map +0 -1
  198. package/dist/index.js.map +0 -1
  199. package/dist/test.d.ts.map +0 -1
  200. package/dist/test.js.map +0 -1
  201. package/dist/types/ejs.d.ts.map +0 -1
  202. package/dist/types/ejs.js.map +0 -1
  203. package/dist/types/features.d.ts.map +0 -1
  204. package/dist/types/features.js.map +0 -1
  205. package/dist/types/index.d.ts.map +0 -1
  206. package/dist/types/index.js.map +0 -1
  207. package/dist/types/viteConfig.d.ts.map +0 -1
  208. package/dist/types/viteConfig.js.map +0 -1
  209. package/dist/utils/deepMerge.d.ts.map +0 -1
  210. package/dist/utils/deepMerge.js.map +0 -1
  211. package/dist/utils/ejs.d.ts.map +0 -1
  212. package/dist/utils/ejs.js.map +0 -1
  213. package/dist/utils/file.d.ts.map +0 -1
  214. package/dist/utils/file.js.map +0 -1
  215. package/dist/utils/index.d.ts.map +0 -1
  216. package/dist/utils/index.js.map +0 -1
  217. package/dist/utils/install.d.ts.map +0 -1
  218. package/dist/utils/install.js.map +0 -1
  219. package/dist/utils/prompts.d.ts.map +0 -1
  220. package/dist/utils/prompts.js.map +0 -1
  221. package/dist/utils/renderFeatures.d.ts.map +0 -1
  222. package/dist/utils/renderFeatures.js.map +0 -1
  223. package/dist/utils/renderTemplate.d.ts.map +0 -1
  224. package/dist/utils/renderTemplate.js.map +0 -1
  225. package/dist/utils/sortDependencies.d.ts.map +0 -1
  226. package/dist/utils/sortDependencies.js.map +0 -1
  227. package/dist/utils/viteConfigRender.d.ts.map +0 -1
  228. package/dist/utils/viteConfigRender.js.map +0 -1
  229. package/templates/common/base/pnpm-workspace.yaml +0 -37
  230. package/templates/common/features/husky/pnpm-workspace.yaml +0 -9
  231. package/templates/react/base/pnpm-workspace.yaml +0 -9
  232. package/templates/react/base/src/stores/user.ts +0 -39
  233. package/templates/react/base/vite.config.ts +0 -52
  234. package/templates/react/features/ant-design/pnpm-workspace.yaml +0 -5
  235. package/templates/react/features/eslint/pnpm-workspace.yaml +0 -6
  236. package/templates/react/features/i18n/pnpm-workspace.yaml +0 -5
  237. package/templates/react/features/pageRoutes/pnpm-workspace.yaml +0 -4
  238. package/templates/react/features/pageRoutes/vite.config.data.ts +0 -10
  239. package/templates/react/features/router/pnpm-workspace.yaml +0 -3
  240. package/templates/react/features/sentry/pnpm-workspace.yaml +0 -5
  241. package/templates/react/features/sentry/vite.config.data.ts +0 -23
  242. package/templates/react/features/zustand/pnpm-workspace.yaml +0 -3
  243. package/templates/vue/base/pnpm-workspace.yaml +0 -6
  244. package/templates/vue/base/src/components/SubMenu/index.ts +0 -9
  245. package/templates/vue/base/src/stores/index.ts +0 -16
  246. package/templates/vue/base/src/stores/modules/system.ts +0 -52
  247. package/templates/vue/base/src/stores/modules/user.ts +0 -48
  248. package/templates/vue/features/ant-design-vue/pnpm-workspace.yaml +0 -5
  249. package/templates/vue/features/element-plus/pnpm-workspace.yaml +0 -5
  250. package/templates/vue/features/element-plus/vite.config.data.ts +0 -15
  251. package/templates/vue/features/eslint/pnpm-workspace.yaml +0 -6
  252. package/templates/vue/features/i18n/pnpm-workspace.yaml +0 -3
  253. package/templates/vue/features/pageRoutes/pnpm-workspace.yaml +0 -4
  254. package/templates/vue/features/pageRoutes/vite.config.data.ts +0 -9
  255. package/templates/vue/features/pinia/pnpm-workspace.yaml +0 -4
  256. package/templates/vue/features/qiankun/pnpm-workspace.yaml +0 -3
  257. package/templates/vue/features/router/pnpm-workspace.yaml +0 -3
  258. package/templates/vue/features/sentry/pnpm-workspace.yaml +0 -4
  259. package/templates/vue/features/sentry/vite.config.data.ts +0 -23
@@ -2,16 +2,18 @@
2
2
  * Vite 配置数据类型定义
3
3
  * 用于 features 中的 vite.config.data.ts
4
4
  */
5
+ /**
6
+ * Vite 配置数据接口
7
+ */
5
8
  export interface ViteConfigData {
6
- /** 导入语句 */
9
+ /** 导入语句字符串数组(完整的 import 语句) */
7
10
  imports?: string[];
8
- /** ViteConfig 选项 */
9
- options?: Record<string, unknown>;
10
- /** 插件配置 */
11
+ /** 插件初始化字符串数组 */
11
12
  plugins?: string[];
12
- /** CSS 配置 */
13
- css?: {
14
- additionalData?: string;
15
- };
13
+ /** JSON 数据配置(包含 server, build, resolve 等静态配置) */
14
+ config?: Record<string, unknown>;
15
+ /** ViteConfig 顶层选项(如 pageRoutes) */
16
+ options?: Record<string, unknown>;
17
+ /** 函数逻辑分片映射,Key 为配置项的深度访问路径(如 'css.preprocessorOptions.scss.additionalData') */
18
+ hooks?: Record<string, string>;
16
19
  }
17
- //# sourceMappingURL=viteConfig.d.ts.map
@@ -3,4 +3,3 @@
3
3
  * 用于 features 中的 vite.config.data.ts
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=viteConfig.js.map
@@ -3,6 +3,8 @@
3
3
  * - 对象会递归合并
4
4
  * - 数组会合并并去重
5
5
  * - 基本类型后者覆盖前者
6
+ * @param target 目标对象
7
+ * @param source 源对象
8
+ * @returns 合并后的对象
6
9
  */
7
10
  export declare function deepMerge<T extends Record<string, unknown>>(target: T, source: Partial<T>): T;
8
- //# sourceMappingURL=deepMerge.d.ts.map
@@ -3,6 +3,9 @@
3
3
  * - 对象会递归合并
4
4
  * - 数组会合并并去重
5
5
  * - 基本类型后者覆盖前者
6
+ * @param target 目标对象
7
+ * @param source 源对象
8
+ * @returns 合并后的对象
6
9
  */
7
10
  export function deepMerge(target, source) {
8
11
  const result = { ...target };
@@ -27,7 +30,11 @@ export function deepMerge(target, source) {
27
30
  }
28
31
  return result;
29
32
  }
33
+ /**
34
+ * 判断值是否为对象(非数组、非 null)
35
+ * @param val 待判断的值
36
+ * @returns 是否为对象
37
+ */
30
38
  function isObject(val) {
31
39
  return val !== null && typeof val === 'object' && !Array.isArray(val);
32
40
  }
33
- //# sourceMappingURL=deepMerge.js.map
@@ -1,12 +1,13 @@
1
1
  /**
2
2
  * EJS 模板渲染工具
3
3
  */
4
- import type { EjsDataType } from '../types';
4
+ import type { EjsDataType } from '../types/index.ts';
5
5
  /**
6
6
  * 渲染 EJS 模板文件
7
7
  * @param templatePath 模板文件路径
8
8
  * @param data 模板数据
9
9
  * @returns 渲染后的字符串内容
10
+ * @throws {Error} 如果模板文件不存在或渲染失败
10
11
  */
11
12
  export declare function renderEjsFile(templatePath: string, data: EjsDataType): string;
12
13
  /**
@@ -14,6 +15,6 @@ export declare function renderEjsFile(templatePath: string, data: EjsDataType):
14
15
  * @param templatePath 模板文件路径
15
16
  * @param targetPath 目标文件路径
16
17
  * @param data 模板数据
18
+ * @throws {Error} 如果模板文件不存在、渲染失败或写入失败
17
19
  */
18
20
  export declare function renderEjsToFile(templatePath: string, targetPath: string, data: EjsDataType): void;
19
- //# sourceMappingURL=ejs.d.ts.map
package/dist/utils/ejs.js CHANGED
@@ -9,6 +9,7 @@ import ejs from 'ejs';
9
9
  * @param templatePath 模板文件路径
10
10
  * @param data 模板数据
11
11
  * @returns 渲染后的字符串内容
12
+ * @throws {Error} 如果模板文件不存在或渲染失败
12
13
  */
13
14
  export function renderEjsFile(templatePath, data) {
14
15
  const template = fs.readFileSync(templatePath, 'utf-8');
@@ -21,10 +22,10 @@ export function renderEjsFile(templatePath, data) {
21
22
  * @param templatePath 模板文件路径
22
23
  * @param targetPath 目标文件路径
23
24
  * @param data 模板数据
25
+ * @throws {Error} 如果模板文件不存在、渲染失败或写入失败
24
26
  */
25
27
  export function renderEjsToFile(templatePath, targetPath, data) {
26
28
  const content = renderEjsFile(templatePath, data);
27
29
  fs.mkdirSync(path.dirname(targetPath), { recursive: true });
28
30
  fs.writeFileSync(targetPath, content);
29
31
  }
30
- //# sourceMappingURL=ejs.js.map
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Features 映射工具
3
+ * 统一管理配置项到 feature 目录的映射关系
4
+ */
5
+ import type { FrameworkType } from '../types/index.ts';
6
+ /**
7
+ * 扫描所有 features(框架的 + 公共的)
8
+ * @param framework 框架类型
9
+ * @returns 所有 feature 名称数组(UI 库按优先级排序)
10
+ */
11
+ export declare function scanAllFeatures(framework: FrameworkType): string[];
12
+ /**
13
+ * 配置项到 feature 目录的映射(从 renderFeatures 提取)
14
+ * @param framework 框架类型
15
+ * @returns 配置键到 feature 名称的映射对象
16
+ */
17
+ export declare function getConfigToFeatureMap(framework: FrameworkType): Record<string, string>;
18
+ /**
19
+ * 公共 features 映射
20
+ * @returns 公共配置键到 feature 名称的映射对象
21
+ */
22
+ export declare function getCommonFeatureMap(): Record<string, string>;
23
+ /**
24
+ * 路由模式映射
25
+ * @param routeMode 路由模式('manual' 或 'file-system')
26
+ * @returns feature 名称
27
+ */
28
+ export declare function getRouteModeFeature(routeMode: string): string;
29
+ /**
30
+ * UI 库映射
31
+ * @param uiLibrary UI 库名称
32
+ * @returns feature 名称(通常与 UI 库名称相同)
33
+ */
34
+ export declare function getUILibraryFeature(uiLibrary: string): string;
35
+ /**
36
+ * Feature 名称转换为配置键和值(用于测试用例生成)
37
+ * @param feature feature 名称
38
+ * @param framework 框架类型
39
+ * @returns 配置键值对,如果无法映射则返回 null
40
+ */
41
+ export declare function featureToConfig(feature: string, framework: FrameworkType): {
42
+ key: string;
43
+ value: string | boolean;
44
+ } | null;
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Features 映射工具
3
+ * 统一管理配置项到 feature 目录的映射关系
4
+ */
5
+ import fs from 'fs-extra';
6
+ import path from 'node:path';
7
+ import { getTemplatesDir } from "./file.js";
8
+ /**
9
+ * UI 库优先级顺序(用于排序,确保默认选择)
10
+ */
11
+ const UI_LIBRARY_PRIORITY = {
12
+ 'element-plus': 1,
13
+ 'ant-design-vue': 2,
14
+ 'ant-design': 1,
15
+ };
16
+ /**
17
+ * 扫描所有 features(框架的 + 公共的)
18
+ * @param framework 框架类型
19
+ * @returns 所有 feature 名称数组(UI 库按优先级排序)
20
+ */
21
+ export function scanAllFeatures(framework) {
22
+ const frameworkDir = path.join(getTemplatesDir(), framework, 'features');
23
+ const commonDir = path.join(getTemplatesDir(), 'common', 'features');
24
+ const features = [];
25
+ if (fs.existsSync(frameworkDir)) {
26
+ features.push(...fs.readdirSync(frameworkDir).filter(f => fs.statSync(path.join(frameworkDir, f)).isDirectory()));
27
+ }
28
+ if (fs.existsSync(commonDir)) {
29
+ features.push(...fs.readdirSync(commonDir).filter(f => fs.statSync(path.join(commonDir, f)).isDirectory()));
30
+ }
31
+ // 对 UI 库进行排序,确保 element-plus 优先(优先级数字越小越靠前)
32
+ return features.sort((a, b) => {
33
+ const priorityA = UI_LIBRARY_PRIORITY[a] ?? 999;
34
+ const priorityB = UI_LIBRARY_PRIORITY[b] ?? 999;
35
+ if (priorityA !== priorityB) {
36
+ return priorityA - priorityB;
37
+ }
38
+ // 相同优先级时保持字母顺序
39
+ return a.localeCompare(b);
40
+ });
41
+ }
42
+ /**
43
+ * 配置项到 feature 目录的映射(从 renderFeatures 提取)
44
+ * @param framework 框架类型
45
+ * @returns 配置键到 feature 名称的映射对象
46
+ */
47
+ export function getConfigToFeatureMap(framework) {
48
+ return {
49
+ router: 'router',
50
+ stateManagement: framework === 'vue' ? 'pinia' : 'zustand',
51
+ eslint: 'eslint',
52
+ i18n: 'i18n',
53
+ sentry: 'sentry',
54
+ qiankun: 'qiankun',
55
+ };
56
+ }
57
+ /**
58
+ * 公共 features 映射
59
+ * @returns 公共配置键到 feature 名称的映射对象
60
+ */
61
+ export function getCommonFeatureMap() {
62
+ return {
63
+ gitHooks: 'husky',
64
+ };
65
+ }
66
+ /**
67
+ * 路由模式映射
68
+ * @param routeMode 路由模式('manual' 或 'file-system')
69
+ * @returns feature 名称
70
+ */
71
+ export function getRouteModeFeature(routeMode) {
72
+ return routeMode === 'manual' ? 'manualRoutes' : 'pageRoutes';
73
+ }
74
+ /**
75
+ * UI 库映射
76
+ * @param uiLibrary UI 库名称
77
+ * @returns feature 名称(通常与 UI 库名称相同)
78
+ */
79
+ export function getUILibraryFeature(uiLibrary) {
80
+ return uiLibrary;
81
+ }
82
+ /**
83
+ * Feature 名称转换为配置键和值(用于测试用例生成)
84
+ * @param feature feature 名称
85
+ * @param framework 框架类型
86
+ * @returns 配置键值对,如果无法映射则返回 null
87
+ */
88
+ export function featureToConfig(feature, framework) {
89
+ // 路由模式
90
+ if (feature === 'manualRoutes')
91
+ return { key: 'routeMode', value: 'manual' };
92
+ if (feature === 'pageRoutes')
93
+ return { key: 'routeMode', value: 'file-system' };
94
+ // UI 库
95
+ const uiLibraries = ['element-plus', 'ant-design-vue', 'ant-design'];
96
+ if (uiLibraries.includes(feature))
97
+ return { key: 'uiLibrary', value: feature };
98
+ // 状态管理(反向映射)
99
+ const stateManagementMap = {
100
+ pinia: 'stateManagement',
101
+ zustand: 'stateManagement',
102
+ };
103
+ if (stateManagementMap[feature])
104
+ return { key: stateManagementMap[feature], value: true };
105
+ // Git Hooks(公共 feature)
106
+ if (feature === 'husky')
107
+ return { key: 'gitHooks', value: true };
108
+ // 其他布尔 features(通过映射查找)
109
+ const configMap = getConfigToFeatureMap(framework);
110
+ const configKey = Object.keys(configMap).find(key => configMap[key] === feature);
111
+ if (configKey)
112
+ return { key: configKey, value: true };
113
+ // 公共 features
114
+ const commonMap = getCommonFeatureMap();
115
+ const commonKey = Object.keys(commonMap).find(key => commonMap[key] === feature);
116
+ if (commonKey)
117
+ return { key: commonKey, value: true };
118
+ return null;
119
+ }
@@ -2,69 +2,89 @@
2
2
  * 文件操作工具
3
3
  * 文件和目录操作相关函数
4
4
  */
5
+ /**
6
+ * 验证路径安全性,防止路径遍历攻击
7
+ * @param filePath 文件路径
8
+ * @param baseDir 基础目录(可选,用于限制路径范围)
9
+ * @throws {Error} 如果路径不安全
10
+ */
11
+ export declare function validatePath(filePath: string, baseDir?: string): void;
5
12
  /**
6
13
  * 创建目录
7
14
  * @param dirPath 目录路径
15
+ * @throws {Error} 如果目录创建失败
8
16
  */
9
17
  export declare function createDir(dirPath: string): void;
10
18
  /**
11
19
  * 清空并重新创建目录
12
20
  * @param dirPath 目录路径
21
+ * @throws {Error} 如果目录操作失败
13
22
  */
14
23
  export declare function emptyDir(dirPath: string): void;
15
24
  /**
16
25
  * 检查路径是否存在
17
26
  * @param filePath 文件路径
27
+ * @returns 路径是否存在
18
28
  */
19
29
  export declare function pathExists(filePath: string): boolean;
20
30
  /**
21
31
  * 复制文件
22
32
  * @param src 源文件路径
23
33
  * @param dest 目标文件路径
34
+ * @throws {Error} 如果文件复制失败
24
35
  */
25
36
  export declare function copyFile(src: string, dest: string): void;
26
37
  /**
27
38
  * 复制目录
28
39
  * @param src 源目录路径
29
40
  * @param dest 目标目录路径
41
+ * @throws {Error} 如果目录复制失败
30
42
  */
31
43
  export declare function copyDir(src: string, dest: string): void;
32
44
  /**
33
45
  * 写入文件
34
46
  * @param filePath 文件路径
35
47
  * @param content 文件内容
48
+ * @throws {Error} 如果文件写入失败
36
49
  */
37
50
  export declare function writeFile(filePath: string, content: string): void;
38
51
  /**
39
52
  * 读取文件
40
53
  * @param filePath 文件路径
54
+ * @returns 文件内容
55
+ * @throws {Error} 如果文件不存在或读取失败
41
56
  */
42
57
  export declare function readFile(filePath: string): string;
43
58
  /**
44
59
  * 读取 JSON 文件
45
60
  * @param filePath 文件路径
61
+ * @returns 解析后的 JSON 对象
62
+ * @throws {Error} 如果文件不存在、读取失败或 JSON 解析失败
46
63
  */
47
64
  export declare function readJsonFile<T = Record<string, unknown>>(filePath: string): T;
48
65
  /**
49
66
  * 写入 JSON 文件
50
67
  * @param filePath 文件路径
51
68
  * @param data 数据
69
+ * @throws {Error} 如果文件写入失败
52
70
  */
53
71
  export declare function writeJsonFile(filePath: string, data: unknown): void;
54
72
  /**
55
73
  * 获取目录下所有文件
56
74
  * @param dirPath 目录路径
57
- * @param recursive 是否递归
75
+ * @param recursive 是否递归,默认为 true
76
+ * @returns 文件路径数组
58
77
  */
59
78
  export declare function getFiles(dirPath: string, recursive?: boolean): string[];
60
79
  /**
61
80
  * 获取模板目录路径
81
+ * @returns 模板目录的绝对路径
62
82
  */
63
83
  export declare function getTemplatesDir(): string;
64
84
  /**
65
85
  * 获取相对路径
66
86
  * @param from 起始路径
67
87
  * @param to 目标路径
88
+ * @returns 相对路径字符串
68
89
  */
69
90
  export declare function getRelativePath(from: string, to: string): string;
70
- //# sourceMappingURL=file.d.ts.map
@@ -5,11 +5,32 @@
5
5
  import path from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
7
  import fs from 'fs-extra';
8
+ /**
9
+ * 验证路径安全性,防止路径遍历攻击
10
+ * @param filePath 文件路径
11
+ * @param baseDir 基础目录(可选,用于限制路径范围)
12
+ * @throws {Error} 如果路径不安全
13
+ */
14
+ export function validatePath(filePath, baseDir) {
15
+ // 检查路径遍历攻击(.. 和 ~)
16
+ if (filePath.includes('..') || filePath.includes('~')) {
17
+ throw new Error(`不安全的路径: ${filePath}`);
18
+ }
19
+ // 如果提供了基础目录,确保路径在基础目录内
20
+ if (baseDir) {
21
+ const resolvedPath = path.resolve(filePath);
22
+ const resolvedBase = path.resolve(baseDir);
23
+ if (!resolvedPath.startsWith(resolvedBase)) {
24
+ throw new Error(`路径超出允许范围: ${filePath}`);
25
+ }
26
+ }
27
+ }
8
28
  const __filename = fileURLToPath(import.meta.url);
9
29
  const __dirname = path.dirname(__filename);
10
30
  /**
11
31
  * 创建目录
12
32
  * @param dirPath 目录路径
33
+ * @throws {Error} 如果目录创建失败
13
34
  */
14
35
  export function createDir(dirPath) {
15
36
  fs.ensureDirSync(dirPath);
@@ -17,6 +38,7 @@ export function createDir(dirPath) {
17
38
  /**
18
39
  * 清空并重新创建目录
19
40
  * @param dirPath 目录路径
41
+ * @throws {Error} 如果目录操作失败
20
42
  */
21
43
  export function emptyDir(dirPath) {
22
44
  fs.emptyDirSync(dirPath);
@@ -24,6 +46,7 @@ export function emptyDir(dirPath) {
24
46
  /**
25
47
  * 检查路径是否存在
26
48
  * @param filePath 文件路径
49
+ * @returns 路径是否存在
27
50
  */
28
51
  export function pathExists(filePath) {
29
52
  return fs.existsSync(filePath);
@@ -32,6 +55,7 @@ export function pathExists(filePath) {
32
55
  * 复制文件
33
56
  * @param src 源文件路径
34
57
  * @param dest 目标文件路径
58
+ * @throws {Error} 如果文件复制失败
35
59
  */
36
60
  export function copyFile(src, dest) {
37
61
  fs.ensureDirSync(path.dirname(dest));
@@ -41,6 +65,7 @@ export function copyFile(src, dest) {
41
65
  * 复制目录
42
66
  * @param src 源目录路径
43
67
  * @param dest 目标目录路径
68
+ * @throws {Error} 如果目录复制失败
44
69
  */
45
70
  export function copyDir(src, dest) {
46
71
  fs.copySync(src, dest);
@@ -49,6 +74,7 @@ export function copyDir(src, dest) {
49
74
  * 写入文件
50
75
  * @param filePath 文件路径
51
76
  * @param content 文件内容
77
+ * @throws {Error} 如果文件写入失败
52
78
  */
53
79
  export function writeFile(filePath, content) {
54
80
  fs.ensureDirSync(path.dirname(filePath));
@@ -57,6 +83,8 @@ export function writeFile(filePath, content) {
57
83
  /**
58
84
  * 读取文件
59
85
  * @param filePath 文件路径
86
+ * @returns 文件内容
87
+ * @throws {Error} 如果文件不存在或读取失败
60
88
  */
61
89
  export function readFile(filePath) {
62
90
  return fs.readFileSync(filePath, 'utf-8');
@@ -64,6 +92,8 @@ export function readFile(filePath) {
64
92
  /**
65
93
  * 读取 JSON 文件
66
94
  * @param filePath 文件路径
95
+ * @returns 解析后的 JSON 对象
96
+ * @throws {Error} 如果文件不存在、读取失败或 JSON 解析失败
67
97
  */
68
98
  export function readJsonFile(filePath) {
69
99
  return fs.readJsonSync(filePath);
@@ -72,6 +102,7 @@ export function readJsonFile(filePath) {
72
102
  * 写入 JSON 文件
73
103
  * @param filePath 文件路径
74
104
  * @param data 数据
105
+ * @throws {Error} 如果文件写入失败
75
106
  */
76
107
  export function writeJsonFile(filePath, data) {
77
108
  fs.ensureDirSync(path.dirname(filePath));
@@ -80,7 +111,8 @@ export function writeJsonFile(filePath, data) {
80
111
  /**
81
112
  * 获取目录下所有文件
82
113
  * @param dirPath 目录路径
83
- * @param recursive 是否递归
114
+ * @param recursive 是否递归,默认为 true
115
+ * @returns 文件路径数组
84
116
  */
85
117
  export function getFiles(dirPath, recursive = true) {
86
118
  const files = [];
@@ -104,6 +136,7 @@ export function getFiles(dirPath, recursive = true) {
104
136
  }
105
137
  /**
106
138
  * 获取模板目录路径
139
+ * @returns 模板目录的绝对路径
107
140
  */
108
141
  export function getTemplatesDir() {
109
142
  return path.resolve(__dirname, '../../templates');
@@ -112,8 +145,8 @@ export function getTemplatesDir() {
112
145
  * 获取相对路径
113
146
  * @param from 起始路径
114
147
  * @param to 目标路径
148
+ * @returns 相对路径字符串
115
149
  */
116
150
  export function getRelativePath(from, to) {
117
151
  return path.relative(from, to);
118
152
  }
119
- //# sourceMappingURL=file.js.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 框架项目生成通用工具
3
+ * 抽离 react.ts 和 vue.ts 的公共逻辑
4
+ */
5
+ import type { ProjectConfigType } from '../types/index.ts';
6
+ /**
7
+ * EJS 模板配置接口
8
+ * 定义框架项目生成所需的模板路径配置
9
+ */
10
+ interface EjsTemplateConfig {
11
+ /** 主入口文件模板路径(相对于框架 base 目录) */
12
+ mainTemplate: string;
13
+ /** 主入口文件输出路径(相对于目标目录) */
14
+ mainOutput: string;
15
+ /** 路由文件模板路径(相对于框架 base 目录) */
16
+ routerTemplate: string;
17
+ /** 路由文件输出路径(相对于目标目录) */
18
+ routerOutput: string;
19
+ }
20
+ /**
21
+ * 生成框架项目的通用函数
22
+ * @param config 项目配置
23
+ * @param ejsConfig EJS 模板配置
24
+ * @throws {Error} 如果模板渲染失败、文件写入失败或配置生成失败
25
+ */
26
+ export declare function generateFrameworkProject(config: ProjectConfigType, ejsConfig: EjsTemplateConfig): void;
27
+ export {};
@@ -0,0 +1,47 @@
1
+ /**
2
+ * 框架项目生成通用工具
3
+ * 抽离 react.ts 和 vue.ts 的公共逻辑
4
+ */
5
+ import path from 'node:path';
6
+ import { FILE_CONSTANTS } from "../constants/index.js";
7
+ import { renderEjsToFile } from "./ejs.js";
8
+ import { getTemplatesDir } from "./file.js";
9
+ import { renderCommonFeatures, renderFrameworkFeatures } from "./renderFeatures.js";
10
+ import { renderTemplate, updatePackageJsonMetadata } from "./index.js";
11
+ import { getViteConfigEjsData } from "./viteConfigRender.js";
12
+ /**
13
+ * 生成框架项目的通用函数
14
+ * @param config 项目配置
15
+ * @param ejsConfig EJS 模板配置
16
+ * @throws {Error} 如果模板渲染失败、文件写入失败或配置生成失败
17
+ */
18
+ export function generateFrameworkProject(config, ejsConfig) {
19
+ const { targetDir, framework } = config;
20
+ const templatesDir = getTemplatesDir();
21
+ // 1. 渲染 L0 公共基础模板
22
+ renderTemplate(path.join(templatesDir, 'common', 'base'), targetDir);
23
+ // 2. 渲染公共特性模板
24
+ renderCommonFeatures(config, targetDir);
25
+ // 3. 渲染 L1 框架基础模板
26
+ renderTemplate(path.join(templatesDir, framework, 'base'), targetDir);
27
+ // 4. 渲染 L2 特性模板(统一处理)
28
+ renderFrameworkFeatures(config, targetDir);
29
+ // 5. 渲染 EJS 模板
30
+ const ejsData = {
31
+ i18n: config.i18n,
32
+ sentry: config.sentry,
33
+ qiankun: config.qiankun,
34
+ routeMode: config.routeMode,
35
+ uiLibrary: config.uiLibrary,
36
+ };
37
+ const frameworkBasePath = path.join(templatesDir, framework, 'base');
38
+ renderEjsToFile(path.join(frameworkBasePath, ejsConfig.mainTemplate), path.join(targetDir, ejsConfig.mainOutput), ejsData);
39
+ renderEjsToFile(path.join(frameworkBasePath, ejsConfig.routerTemplate), path.join(targetDir, ejsConfig.routerOutput), ejsData);
40
+ // 6. 数据驱动生成 vite.config.ts(使用 EJS 模板)
41
+ const viteConfigEjsData = getViteConfigEjsData(config);
42
+ const commonBasePath = path.join(templatesDir, 'common', 'base');
43
+ renderEjsToFile(path.join(commonBasePath, 'vite.config.ts.ejs'), path.join(targetDir, 'vite.config.ts'), viteConfigEjsData);
44
+ // 7. 更新 package.json 的元数据字段
45
+ const packageJsonPath = path.join(targetDir, FILE_CONSTANTS.PACKAGE_JSON);
46
+ updatePackageJsonMetadata(packageJsonPath, config.projectName, config.description, config.author, config.packageManager);
47
+ }
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * 工具函数导出
3
3
  */
4
- export * from './deepMerge';
5
- export * from './ejs';
6
- export * from './file';
7
- export * from './install';
8
- export * from './prompts';
9
- export * from './renderTemplate';
10
- export * from './sortDependencies';
11
- export * from './viteConfigRender';
12
- //# sourceMappingURL=index.d.ts.map
4
+ export * from './deepMerge.ts';
5
+ export * from './ejs.ts';
6
+ export * from './file.ts';
7
+ export * from './generateFrameworkProject.ts';
8
+ export * from './install.ts';
9
+ export * from './npmConfig.ts';
10
+ export * from './prompts.ts';
11
+ export { updatePackageJsonMetadata } from './renderTemplate.ts';
12
+ export * from './renderTemplate.ts';
13
+ export * from './sortDependencies.ts';
14
+ export * from './viteConfigRender.ts';
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * 工具函数导出
3
3
  */
4
- export * from './deepMerge.js';
5
- export * from './ejs.js';
6
- export * from './file.js';
7
- export * from './install.js';
8
- export * from './prompts.js';
9
- export * from './renderTemplate.js';
10
- export * from './sortDependencies.js';
11
- export * from './viteConfigRender.js';
12
- //# sourceMappingURL=index.js.map
4
+ export * from "./deepMerge.js";
5
+ export * from "./ejs.js";
6
+ export * from "./file.js";
7
+ export * from "./generateFrameworkProject.js";
8
+ export * from "./install.js";
9
+ export * from "./npmConfig.js";
10
+ export * from "./prompts.js";
11
+ export { updatePackageJsonMetadata } from "./renderTemplate.js";
12
+ export * from "./renderTemplate.js";
13
+ export * from "./sortDependencies.js";
14
+ export * from "./viteConfigRender.js";
@@ -2,16 +2,19 @@
2
2
  * 依赖安装工具
3
3
  * 执行包管理器安装依赖
4
4
  */
5
- import type { PackageManagerType } from '../types';
5
+ import type { PackageManagerType } from '../types/index.ts';
6
6
  /**
7
7
  * 安装依赖
8
8
  * @param packageManager 包管理器
9
9
  * @param cwd 工作目录
10
+ * @param retries 重试次数,默认 0(不重试)
11
+ * @returns Promise<void>
12
+ * @throws {Error} 如果安装失败
10
13
  */
11
- export declare function installDependencies(packageManager: PackageManagerType, cwd: string): void;
14
+ export declare function installDependencies(packageManager: PackageManagerType, cwd: string, retries?: number): Promise<void>;
12
15
  /**
13
16
  * 初始化 Git 仓库
14
17
  * @param cwd 工作目录
18
+ * @returns Promise<void>
15
19
  */
16
- export declare function initGit(cwd: string): void;
17
- //# sourceMappingURL=install.d.ts.map
20
+ export declare function initGit(cwd: string): Promise<void>;