@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.
- package/LICENSE.txt +21 -21
- package/README.md +129 -129
- package/dist/commands/create.d.ts +2 -1
- package/dist/commands/create.js +12 -8
- package/dist/commands/index.d.ts +1 -2
- package/dist/commands/index.js +1 -2
- package/dist/constants/index.d.ts +17 -0
- package/dist/constants/index.js +17 -0
- package/dist/generators/index.d.ts +3 -4
- package/dist/generators/index.js +3 -4
- package/dist/generators/project.d.ts +3 -2
- package/dist/generators/project.js +5 -4
- package/dist/generators/react.d.ts +4 -2
- package/dist/generators/react.js +10 -30
- package/dist/generators/vue.d.ts +4 -2
- package/dist/generators/vue.js +10 -31
- package/dist/index.d.ts +0 -1
- package/dist/index.js +21 -3
- package/dist/test.d.ts +5 -2
- package/dist/test.js +252 -206
- package/dist/types/ejs.d.ts +0 -1
- package/dist/types/ejs.js +0 -1
- package/dist/types/features.d.ts +0 -1
- package/dist/types/features.js +0 -1
- package/dist/types/index.d.ts +2 -4
- package/dist/types/index.js +2 -4
- package/dist/types/packageJson.d.ts +24 -0
- package/dist/types/packageJson.js +4 -0
- package/dist/types/viteConfig.d.ts +11 -9
- package/dist/types/viteConfig.js +0 -1
- package/dist/utils/deepMerge.d.ts +3 -1
- package/dist/utils/deepMerge.js +8 -1
- package/dist/utils/ejs.d.ts +3 -2
- package/dist/utils/ejs.js +2 -1
- package/dist/utils/featureMapping.d.ts +44 -0
- package/dist/utils/featureMapping.js +119 -0
- package/dist/utils/file.d.ts +22 -2
- package/dist/utils/file.js +35 -2
- package/dist/utils/generateFrameworkProject.d.ts +27 -0
- package/dist/utils/generateFrameworkProject.js +47 -0
- package/dist/utils/index.d.ts +11 -9
- package/dist/utils/index.js +11 -9
- package/dist/utils/install.d.ts +7 -4
- package/dist/utils/install.js +55 -12
- package/dist/utils/npmConfig.d.ts +15 -0
- package/dist/utils/npmConfig.js +79 -0
- package/dist/utils/prompts.d.ts +3 -2
- package/dist/utils/prompts.js +51 -5
- package/dist/utils/renderFeatures.d.ts +3 -2
- package/dist/utils/renderFeatures.js +41 -37
- package/dist/utils/renderTemplate.d.ts +13 -1
- package/dist/utils/renderTemplate.js +128 -61
- package/dist/utils/sortDependencies.d.ts +3 -2
- package/dist/utils/sortDependencies.js +3 -2
- package/dist/utils/viteConfigRender.d.ts +11 -14
- package/dist/utils/viteConfigRender.js +10 -173
- package/package.json +4 -2
- package/templates/common/base/.env +7 -7
- package/templates/common/base/.env.development +5 -5
- package/templates/common/base/.env.production +5 -5
- package/templates/common/base/package.json +23 -27
- package/templates/common/base/scripts/build.mts +37 -31
- package/templates/common/base/src/apis/index.ts +8 -8
- package/templates/common/base/src/apis/request.ts +43 -43
- package/templates/common/base/src/apis/services/example.ts +61 -40
- package/templates/common/base/src/apis/services/user.ts +33 -23
- package/templates/common/base/src/apis/types/common.ts +43 -28
- package/templates/common/base/src/apis/types/example.ts +15 -3
- package/templates/common/base/src/apis/types/index.ts +7 -7
- package/templates/common/base/src/apis/types/user.ts +39 -24
- package/templates/common/base/src/assets/fonts/index.css +7 -7
- package/templates/common/base/src/assets/styles/base.scss +72 -72
- package/templates/common/base/src/assets/styles/custom.scss +7 -7
- package/templates/common/base/src/assets/styles/tailwind.scss +6 -6
- package/templates/common/base/src/constants/index.ts +29 -29
- package/templates/common/base/src/utils/index.ts +88 -83
- package/templates/{vue/base/vite.config.ts → common/base/vite.config.ts.ejs} +28 -11
- package/templates/common/features/husky/.cz-config.cjs +35 -35
- package/templates/common/features/husky/commitlint.config.ts +32 -32
- package/templates/common/features/husky/node_modules/.bin/commitizen +17 -0
- package/templates/common/features/husky/node_modules/.bin/commitizen.CMD +12 -0
- package/templates/common/features/husky/node_modules/.bin/commitizen.ps1 +41 -0
- package/templates/common/features/husky/node_modules/.bin/commitlint +17 -0
- package/templates/common/features/husky/node_modules/.bin/commitlint.CMD +12 -0
- package/templates/common/features/husky/node_modules/.bin/commitlint.ps1 +41 -0
- package/templates/common/features/husky/node_modules/.bin/cz +17 -0
- package/templates/common/features/husky/node_modules/.bin/cz-cust +17 -0
- package/templates/common/features/husky/node_modules/.bin/cz-cust.CMD +12 -0
- package/templates/common/features/husky/node_modules/.bin/cz-cust.ps1 +41 -0
- package/templates/common/features/husky/node_modules/.bin/cz-customizable +17 -0
- package/templates/common/features/husky/node_modules/.bin/cz-customizable.CMD +12 -0
- package/templates/common/features/husky/node_modules/.bin/cz-customizable.ps1 +41 -0
- package/templates/common/features/husky/node_modules/.bin/cz.CMD +12 -0
- package/templates/common/features/husky/node_modules/.bin/cz.ps1 +41 -0
- package/templates/common/features/husky/node_modules/.bin/git-cz +17 -0
- package/templates/common/features/husky/node_modules/.bin/git-cz.CMD +12 -0
- package/templates/common/features/husky/node_modules/.bin/git-cz.ps1 +41 -0
- package/templates/common/features/husky/node_modules/.bin/husky +17 -0
- package/templates/common/features/husky/node_modules/.bin/husky.CMD +12 -0
- package/templates/common/features/husky/node_modules/.bin/husky.ps1 +41 -0
- package/templates/common/features/husky/node_modules/.bin/lint-staged +17 -0
- package/templates/common/features/husky/node_modules/.bin/lint-staged.CMD +12 -0
- package/templates/common/features/husky/node_modules/.bin/lint-staged.ps1 +41 -0
- package/templates/common/features/husky/package.json +6 -6
- package/templates/react/base/env.d.ts +19 -19
- package/templates/react/base/index.html +14 -14
- package/templates/react/base/node_modules/.bin/vite +17 -0
- package/templates/react/base/node_modules/.bin/vite.CMD +12 -0
- package/templates/react/base/node_modules/.bin/vite.ps1 +41 -0
- package/templates/react/base/package.json +18 -15
- package/templates/react/base/src/App.tsx +18 -18
- package/templates/react/base/src/assets/styles/main.scss +8 -8
- package/templates/react/base/src/pages/about/index.tsx +14 -14
- package/templates/react/base/src/pages/home/index.tsx +14 -14
- package/templates/react/base/tsconfig.app.json +17 -17
- package/templates/react/base/tsconfig.base.json +23 -23
- package/templates/react/base/tsconfig.json +12 -12
- package/templates/react/base/tsconfig.node.json +15 -15
- package/templates/react/features/ant-design/package.json +6 -7
- package/templates/react/features/eslint/node_modules/.bin/eslint +17 -0
- package/templates/react/features/eslint/node_modules/.bin/eslint.CMD +12 -0
- package/templates/react/features/eslint/node_modules/.bin/eslint.ps1 +41 -0
- package/templates/react/features/eslint/package.json +3 -3
- package/templates/react/features/i18n/package.json +6 -7
- package/templates/react/features/i18n/src/locales/index.ts +7 -0
- package/templates/{common/base → react/features/i18n}/src/locales/lang/en.ts +30 -30
- package/templates/{common/base → react/features/i18n}/src/locales/lang/es.ts +30 -30
- package/templates/{common/base → react/features/i18n}/src/locales/lang/zh.ts +30 -30
- package/templates/react/features/manualRoutes/src/router/routes.tsx +13 -0
- package/templates/react/features/pageRoutes/package.json +1 -2
- package/templates/react/features/router/package.json +1 -1
- package/templates/react/features/sentry/package.json +6 -7
- package/templates/react/features/sentry/src/utils/sentry.ts +10 -0
- package/templates/react/features/zustand/package.json +1 -1
- package/templates/react/features/zustand/src/stores/user.ts +42 -6
- package/templates/react/features/zustand/src/types/stores.ts +8 -1
- package/templates/vue/base/env.d.ts +27 -27
- package/templates/vue/base/index.html +14 -14
- package/templates/vue/base/node_modules/.bin/vite +17 -0
- package/templates/vue/base/node_modules/.bin/vite.CMD +12 -0
- package/templates/vue/base/node_modules/.bin/vite.ps1 +41 -0
- package/templates/vue/base/node_modules/.bin/vue-tsc +17 -0
- package/templates/vue/base/node_modules/.bin/vue-tsc.CMD +12 -0
- package/templates/vue/base/node_modules/.bin/vue-tsc.ps1 +41 -0
- package/templates/vue/base/package.json +16 -13
- package/templates/vue/base/src/App.vue +13 -13
- package/templates/vue/base/src/assets/styles/main.scss +9 -9
- package/templates/vue/base/src/directives/index.ts +36 -36
- package/templates/vue/base/src/layouts/index.ts +5 -7
- package/templates/vue/base/src/pages/about/index.vue +31 -31
- package/templates/vue/base/src/pages/home/index.vue +31 -31
- package/templates/vue/base/tsconfig.app.json +17 -17
- package/templates/vue/base/tsconfig.base.json +23 -23
- package/templates/vue/base/tsconfig.json +12 -12
- package/templates/vue/base/tsconfig.node.json +15 -15
- package/templates/vue/features/ant-design-vue/package.json +6 -7
- package/templates/vue/{base → features/ant-design-vue}/src/layouts/AntDesign.vue +86 -86
- package/templates/vue/features/element-plus/package.json +6 -7
- package/templates/vue/{base → features/element-plus}/src/assets/styles/element/index.scss +27 -27
- package/templates/vue/features/element-plus/src/components/SubMenu/index.ts +9 -0
- package/templates/vue/{base → features/element-plus}/src/components/SubMenu/src/_types/index.ts +6 -6
- package/templates/vue/{base → features/element-plus}/src/components/SubMenu/src/_types/props.ts +11 -11
- package/templates/vue/{base → features/element-plus}/src/components/SubMenu/src/index.vue +24 -24
- package/templates/vue/{base → features/element-plus}/src/layouts/element.vue +81 -81
- package/templates/vue/features/eslint/node_modules/.bin/eslint +17 -0
- package/templates/vue/features/eslint/node_modules/.bin/eslint.CMD +12 -0
- package/templates/vue/features/eslint/node_modules/.bin/eslint.ps1 +41 -0
- package/templates/vue/features/eslint/package.json +3 -3
- package/templates/vue/features/i18n/package.json +5 -5
- package/templates/vue/features/i18n/src/locales/index.ts +23 -16
- package/templates/vue/features/i18n/src/locales/lang/en.ts +30 -0
- package/templates/vue/features/i18n/src/locales/lang/es.ts +30 -0
- package/templates/vue/features/i18n/src/locales/lang/zh.ts +30 -0
- package/templates/vue/features/manualRoutes/src/router/routes.ts +35 -27
- package/templates/vue/features/pageRoutes/package.json +5 -5
- package/templates/vue/features/pinia/package.json +3 -2
- package/templates/vue/features/pinia/src/stores/index.ts +8 -0
- package/templates/vue/features/pinia/src/stores/system.ts +60 -0
- package/templates/vue/features/pinia/src/stores/user.ts +33 -13
- package/templates/vue/features/qiankun/package.json +5 -5
- package/templates/vue/features/qiankun/src/qiankun/index.ts +19 -0
- package/templates/vue/features/router/package.json +1 -1
- package/templates/vue/features/sentry/package.json +6 -6
- package/templates/vue/features/sentry/src/utils/sentry.ts +12 -0
- package/dist/commands/create.d.ts.map +0 -1
- package/dist/commands/create.js.map +0 -1
- package/dist/commands/index.d.ts.map +0 -1
- package/dist/commands/index.js.map +0 -1
- package/dist/generators/index.d.ts.map +0 -1
- package/dist/generators/index.js.map +0 -1
- package/dist/generators/project.d.ts.map +0 -1
- package/dist/generators/project.js.map +0 -1
- package/dist/generators/react.d.ts.map +0 -1
- package/dist/generators/react.js.map +0 -1
- package/dist/generators/vue.d.ts.map +0 -1
- package/dist/generators/vue.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/test.d.ts.map +0 -1
- package/dist/test.js.map +0 -1
- package/dist/types/ejs.d.ts.map +0 -1
- package/dist/types/ejs.js.map +0 -1
- package/dist/types/features.d.ts.map +0 -1
- package/dist/types/features.js.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/viteConfig.d.ts.map +0 -1
- package/dist/types/viteConfig.js.map +0 -1
- package/dist/utils/deepMerge.d.ts.map +0 -1
- package/dist/utils/deepMerge.js.map +0 -1
- package/dist/utils/ejs.d.ts.map +0 -1
- package/dist/utils/ejs.js.map +0 -1
- package/dist/utils/file.d.ts.map +0 -1
- package/dist/utils/file.js.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/install.d.ts.map +0 -1
- package/dist/utils/install.js.map +0 -1
- package/dist/utils/prompts.d.ts.map +0 -1
- package/dist/utils/prompts.js.map +0 -1
- package/dist/utils/renderFeatures.d.ts.map +0 -1
- package/dist/utils/renderFeatures.js.map +0 -1
- package/dist/utils/renderTemplate.d.ts.map +0 -1
- package/dist/utils/renderTemplate.js.map +0 -1
- package/dist/utils/sortDependencies.d.ts.map +0 -1
- package/dist/utils/sortDependencies.js.map +0 -1
- package/dist/utils/viteConfigRender.d.ts.map +0 -1
- package/dist/utils/viteConfigRender.js.map +0 -1
- package/templates/common/base/pnpm-workspace.yaml +0 -37
- package/templates/common/features/husky/pnpm-workspace.yaml +0 -9
- package/templates/react/base/pnpm-workspace.yaml +0 -9
- package/templates/react/base/src/stores/user.ts +0 -39
- package/templates/react/base/vite.config.ts +0 -52
- package/templates/react/features/ant-design/pnpm-workspace.yaml +0 -5
- package/templates/react/features/eslint/pnpm-workspace.yaml +0 -6
- package/templates/react/features/i18n/pnpm-workspace.yaml +0 -5
- package/templates/react/features/pageRoutes/pnpm-workspace.yaml +0 -4
- package/templates/react/features/pageRoutes/vite.config.data.ts +0 -10
- package/templates/react/features/router/pnpm-workspace.yaml +0 -3
- package/templates/react/features/sentry/pnpm-workspace.yaml +0 -5
- package/templates/react/features/sentry/vite.config.data.ts +0 -23
- package/templates/react/features/zustand/pnpm-workspace.yaml +0 -3
- package/templates/vue/base/pnpm-workspace.yaml +0 -6
- package/templates/vue/base/src/components/SubMenu/index.ts +0 -9
- package/templates/vue/base/src/stores/index.ts +0 -16
- package/templates/vue/base/src/stores/modules/system.ts +0 -52
- package/templates/vue/base/src/stores/modules/user.ts +0 -48
- package/templates/vue/features/ant-design-vue/pnpm-workspace.yaml +0 -5
- package/templates/vue/features/element-plus/pnpm-workspace.yaml +0 -5
- package/templates/vue/features/element-plus/vite.config.data.ts +0 -15
- package/templates/vue/features/eslint/pnpm-workspace.yaml +0 -6
- package/templates/vue/features/i18n/pnpm-workspace.yaml +0 -3
- package/templates/vue/features/pageRoutes/pnpm-workspace.yaml +0 -4
- package/templates/vue/features/pageRoutes/vite.config.data.ts +0 -9
- package/templates/vue/features/pinia/pnpm-workspace.yaml +0 -4
- package/templates/vue/features/qiankun/pnpm-workspace.yaml +0 -3
- package/templates/vue/features/router/pnpm-workspace.yaml +0 -3
- package/templates/vue/features/sentry/pnpm-workspace.yaml +0 -4
- package/templates/vue/features/sentry/vite.config.data.ts +0 -23
package/dist/test.d.ts
CHANGED
package/dist/test.js
CHANGED
|
@@ -1,204 +1,196 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 测试脚本
|
|
3
|
-
*
|
|
3
|
+
* 通过文件系统扫描自动生成所有测试用例组合
|
|
4
|
+
*
|
|
5
|
+
* 用法:
|
|
6
|
+
* pnpm test # 生成所有测试用例
|
|
7
|
+
* pnpm test --minimal # 只生成全量和最小配置
|
|
4
8
|
*/
|
|
5
9
|
import path from 'node:path';
|
|
6
10
|
import process from 'node:process';
|
|
7
11
|
import { fileURLToPath } from 'node:url';
|
|
8
12
|
import chalk from 'chalk';
|
|
9
13
|
import fs from 'fs-extra';
|
|
10
|
-
import {
|
|
14
|
+
import { FILE_CONSTANTS } from "./constants/index.js";
|
|
15
|
+
import { generateProject } from "./generators/index.js";
|
|
16
|
+
import { featureToConfig, scanAllFeatures } from "./utils/featureMapping.js";
|
|
11
17
|
const __filename = fileURLToPath(import.meta.url);
|
|
12
18
|
const __dirname = path.dirname(__filename);
|
|
13
19
|
/** 测试输出目录 */
|
|
14
20
|
const TEST_OUTPUT_DIR = path.resolve(__dirname, '../test');
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
name: 'react-antd-minimal',
|
|
157
|
-
config: {
|
|
158
|
-
projectName: 'react-antd-minimal',
|
|
159
|
-
description: 'React + Ant Design 最小配置(无 i18n, 无 sentry)',
|
|
160
|
-
author: 'test',
|
|
161
|
-
framework: 'react',
|
|
162
|
-
uiLibrary: 'ant-design',
|
|
163
|
-
routeMode: 'manual',
|
|
164
|
-
i18n: false,
|
|
165
|
-
qiankun: false,
|
|
166
|
-
sentry: false,
|
|
167
|
-
eslint: true,
|
|
168
|
-
gitHooks: true,
|
|
169
|
-
packageManager: 'pnpm',
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
name: 'react-no-eslint-no-hooks',
|
|
21
|
+
/**
|
|
22
|
+
* 解析命令行参数
|
|
23
|
+
*/
|
|
24
|
+
function parseArgs() {
|
|
25
|
+
const args = process.argv.slice(2);
|
|
26
|
+
const minimalOnly = args.includes('--minimal') || args.includes('--min') || args.includes('-m');
|
|
27
|
+
return { minimalOnly };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 生成所有可能的组合(包括全开、全关)
|
|
31
|
+
*/
|
|
32
|
+
function generateAllCombinations(items) {
|
|
33
|
+
const n = items.length;
|
|
34
|
+
const combinations = [];
|
|
35
|
+
// 生成 2^n 种组合
|
|
36
|
+
for (let i = 0; i < 2 ** n; i++) {
|
|
37
|
+
const combination = [];
|
|
38
|
+
for (let j = 0; j < n; j++) {
|
|
39
|
+
combination.push((i & (1 << j)) !== 0);
|
|
40
|
+
}
|
|
41
|
+
combinations.push(combination);
|
|
42
|
+
}
|
|
43
|
+
return combinations;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 自动生成测试用例配置(基于组合算法)
|
|
47
|
+
* @param minimalOnly 是否只生成全量和最小配置
|
|
48
|
+
*/
|
|
49
|
+
function generateTestConfigs(minimalOnly = false) {
|
|
50
|
+
const configs = [];
|
|
51
|
+
const frameworks = ['vue', 'react'];
|
|
52
|
+
for (const framework of frameworks) {
|
|
53
|
+
const allFeatures = scanAllFeatures(framework);
|
|
54
|
+
// 分离不同类型的 features
|
|
55
|
+
const uiLibraries = [];
|
|
56
|
+
const routeModes = [];
|
|
57
|
+
const booleanFeatures = [];
|
|
58
|
+
for (const feature of allFeatures) {
|
|
59
|
+
const config = featureToConfig(feature, framework);
|
|
60
|
+
if (!config)
|
|
61
|
+
continue;
|
|
62
|
+
if (config.key === 'uiLibrary') {
|
|
63
|
+
uiLibraries.push(feature);
|
|
64
|
+
}
|
|
65
|
+
else if (config.key === 'routeMode') {
|
|
66
|
+
routeModes.push(feature);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
booleanFeatures.push(feature);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (uiLibraries.length === 0)
|
|
73
|
+
continue;
|
|
74
|
+
if (minimalOnly) {
|
|
75
|
+
// 只生成全量和最小配置:每个框架只选择一个 UI 库和一个路由模式
|
|
76
|
+
const uiLibrary = uiLibraries[0]; // 只选择第一个 UI 库
|
|
77
|
+
const routeModeFeature = routeModes.length > 0 ? routeModes[0] : 'manualRoutes'; // 只选择第一个路由模式
|
|
78
|
+
// 只生成全量和最小两种配置
|
|
79
|
+
const allFalse = Array.from({ length: booleanFeatures.length }, () => false);
|
|
80
|
+
const allTrue = Array.from({ length: booleanFeatures.length }, () => true);
|
|
81
|
+
const combinations = [allFalse, allTrue];
|
|
82
|
+
// 为每种包管理器生成测试用例
|
|
83
|
+
const packageManagers = ['pnpm', 'npm', 'yarn'];
|
|
84
|
+
for (const packageManager of packageManagers) {
|
|
85
|
+
for (const combination of combinations) {
|
|
86
|
+
const config = {
|
|
87
|
+
framework,
|
|
88
|
+
uiLibrary: uiLibrary,
|
|
89
|
+
routeMode: featureToConfig(routeModeFeature, framework).value,
|
|
90
|
+
packageManager,
|
|
91
|
+
};
|
|
92
|
+
// 应用布尔 features 的组合
|
|
93
|
+
for (let i = 0; i < booleanFeatures.length; i++) {
|
|
94
|
+
const feature = booleanFeatures[i];
|
|
95
|
+
const enabled = combination[i];
|
|
96
|
+
const featureConfig = featureToConfig(feature, framework);
|
|
97
|
+
if (featureConfig && featureConfig.key !== 'uiLibrary' && featureConfig.key !== 'routeMode') {
|
|
98
|
+
config[featureConfig.key] = enabled;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// 生成测试用例名称(包含包管理器)
|
|
102
|
+
const suffix = combination.every(v => !v) ? 'minimal' : 'full';
|
|
103
|
+
configs.push(createTestConfig(framework, uiLibrary, `${packageManager}-${suffix}`, config));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// 生成所有组合
|
|
109
|
+
for (const uiLibrary of uiLibraries) {
|
|
110
|
+
// 为每个路由模式生成测试用例
|
|
111
|
+
const routeModesToTest = routeModes.length > 0 ? routeModes : ['manualRoutes']; // 默认
|
|
112
|
+
for (const routeModeFeature of routeModesToTest) {
|
|
113
|
+
// 生成所有布尔 features 的组合(2^n 种)
|
|
114
|
+
const combinations = generateAllCombinations(booleanFeatures);
|
|
115
|
+
// 为每种包管理器生成测试用例
|
|
116
|
+
const packageManagers = ['pnpm', 'npm', 'yarn'];
|
|
117
|
+
for (const packageManager of packageManagers) {
|
|
118
|
+
for (const combination of combinations) {
|
|
119
|
+
const config = {
|
|
120
|
+
framework,
|
|
121
|
+
uiLibrary: uiLibrary,
|
|
122
|
+
routeMode: featureToConfig(routeModeFeature, framework).value,
|
|
123
|
+
packageManager,
|
|
124
|
+
};
|
|
125
|
+
// 应用布尔 features 的组合
|
|
126
|
+
for (let i = 0; i < booleanFeatures.length; i++) {
|
|
127
|
+
const feature = booleanFeatures[i];
|
|
128
|
+
const enabled = combination[i];
|
|
129
|
+
const featureConfig = featureToConfig(feature, framework);
|
|
130
|
+
if (featureConfig && featureConfig.key !== 'uiLibrary' && featureConfig.key !== 'routeMode') {
|
|
131
|
+
config[featureConfig.key] = enabled;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// 生成测试用例名称(包含包管理器)
|
|
135
|
+
const enabledFeatures = booleanFeatures.filter((_, i) => combination[i]);
|
|
136
|
+
const suffix = enabledFeatures.length === 0
|
|
137
|
+
? 'minimal'
|
|
138
|
+
: enabledFeatures.length === booleanFeatures.length
|
|
139
|
+
? 'full'
|
|
140
|
+
: enabledFeatures.join('-');
|
|
141
|
+
configs.push(createTestConfig(framework, uiLibrary, `${packageManager}-${routeModeFeature}-${suffix}`, config));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return configs;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 创建测试配置的辅助函数
|
|
152
|
+
* @param framework 框架类型
|
|
153
|
+
* @param uiLibrary UI 库名称
|
|
154
|
+
* @param suffix 后缀名称
|
|
155
|
+
* @param overrides 配置覆盖项
|
|
156
|
+
* @returns 测试配置对象
|
|
157
|
+
*/
|
|
158
|
+
function createTestConfig(framework, uiLibrary, suffix, overrides) {
|
|
159
|
+
const name = `${framework}-${uiLibrary}-${suffix}`;
|
|
160
|
+
return {
|
|
161
|
+
name,
|
|
174
162
|
config: {
|
|
175
|
-
projectName:
|
|
176
|
-
description: '
|
|
163
|
+
projectName: name,
|
|
164
|
+
description: `${framework === 'vue' ? 'Vue' : 'React'} + ${uiLibrary} ${suffix}`,
|
|
177
165
|
author: 'test',
|
|
178
|
-
|
|
179
|
-
uiLibrary: 'ant-design',
|
|
180
|
-
routeMode: 'manual',
|
|
181
|
-
i18n: false,
|
|
182
|
-
qiankun: false,
|
|
183
|
-
sentry: false,
|
|
184
|
-
eslint: false,
|
|
185
|
-
gitHooks: false,
|
|
186
|
-
packageManager: 'pnpm',
|
|
166
|
+
...overrides,
|
|
187
167
|
},
|
|
188
|
-
}
|
|
189
|
-
|
|
168
|
+
};
|
|
169
|
+
}
|
|
190
170
|
/**
|
|
191
171
|
* 生成测试项目
|
|
172
|
+
* @param minimalOnly 是否只生成全量和最小配置
|
|
192
173
|
*/
|
|
193
|
-
async function generateTestProjects() {
|
|
194
|
-
|
|
174
|
+
async function generateTestProjects(minimalOnly = false) {
|
|
175
|
+
const mode = minimalOnly ? '(仅全量和最小配置)' : '(全部组合)';
|
|
176
|
+
console.log(chalk.blue.bold(`\n🧪 开始生成测试项目${mode}...\n`));
|
|
177
|
+
// 扫描并生成测试配置
|
|
178
|
+
const TEST_CONFIGS = generateTestConfigs(minimalOnly);
|
|
179
|
+
console.log(chalk.cyan(`📋 扫描到 ${TEST_CONFIGS.length} 个测试用例\n`));
|
|
195
180
|
// 清理并创建测试目录
|
|
196
181
|
if (fs.existsSync(TEST_OUTPUT_DIR)) {
|
|
197
182
|
fs.removeSync(TEST_OUTPUT_DIR);
|
|
198
183
|
}
|
|
199
184
|
fs.ensureDirSync(TEST_OUTPUT_DIR);
|
|
185
|
+
// 创建 Vue 和 React 子目录
|
|
186
|
+
const vueOutputDir = path.join(TEST_OUTPUT_DIR, 'vue');
|
|
187
|
+
const reactOutputDir = path.join(TEST_OUTPUT_DIR, 'react');
|
|
188
|
+
fs.ensureDirSync(vueOutputDir);
|
|
189
|
+
fs.ensureDirSync(reactOutputDir);
|
|
200
190
|
for (const { name, config } of TEST_CONFIGS) {
|
|
201
191
|
console.log(chalk.cyan(`📦 生成 ${name}...`));
|
|
192
|
+
// 根据框架决定输出目录
|
|
193
|
+
const frameworkOutputDir = config.framework === 'vue' ? vueOutputDir : reactOutputDir;
|
|
202
194
|
const fullConfig = {
|
|
203
195
|
projectName: config.projectName,
|
|
204
196
|
description: config.description,
|
|
@@ -214,7 +206,7 @@ async function generateTestProjects() {
|
|
|
214
206
|
eslint: config.eslint,
|
|
215
207
|
gitHooks: config.gitHooks,
|
|
216
208
|
packageManager: config.packageManager,
|
|
217
|
-
targetDir: path.join(
|
|
209
|
+
targetDir: path.join(frameworkOutputDir, name),
|
|
218
210
|
};
|
|
219
211
|
try {
|
|
220
212
|
await generateProject(fullConfig);
|
|
@@ -226,20 +218,59 @@ async function generateTestProjects() {
|
|
|
226
218
|
}
|
|
227
219
|
console.log(chalk.green.bold('\n✅ 测试项目生成完成!\n'));
|
|
228
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* 检查 package.json 中是否有 catalog 引用(应该已经全部替换为实际版本号)
|
|
223
|
+
*/
|
|
224
|
+
function checkPackageJsonVersions(projectDir) {
|
|
225
|
+
const packageJsonPath = path.join(projectDir, FILE_CONSTANTS.PACKAGE_JSON);
|
|
226
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
227
|
+
console.log(chalk.red(` ❌ package.json 不存在`));
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
231
|
+
let hasError = false;
|
|
232
|
+
// 检查 dependencies 中是否还有 catalog 引用
|
|
233
|
+
if (packageJson.dependencies) {
|
|
234
|
+
for (const [dep, version] of Object.entries(packageJson.dependencies)) {
|
|
235
|
+
if (typeof version === 'string' && version.startsWith('catalog:')) {
|
|
236
|
+
console.log(chalk.red(` ❌ dependencies.${dep}: "${version}" 应该使用实际版本号`));
|
|
237
|
+
hasError = true;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// 检查 devDependencies 中是否还有 catalog 引用
|
|
242
|
+
if (packageJson.devDependencies) {
|
|
243
|
+
for (const [dep, version] of Object.entries(packageJson.devDependencies)) {
|
|
244
|
+
if (typeof version === 'string' && version.startsWith('catalog:')) {
|
|
245
|
+
console.log(chalk.red(` ❌ devDependencies.${dep}: "${version}" 应该使用实际版本号`));
|
|
246
|
+
hasError = true;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (!hasError) {
|
|
251
|
+
console.log(chalk.green(` ✅ package.json 版本号检查通过(无 catalog 引用)`));
|
|
252
|
+
}
|
|
253
|
+
return !hasError;
|
|
254
|
+
}
|
|
229
255
|
/**
|
|
230
256
|
* 审计 @moluoxixi 依赖
|
|
257
|
+
* @param minimalOnly 是否只生成全量和最小配置
|
|
231
258
|
*/
|
|
232
|
-
async function auditMoluoxixiDeps() {
|
|
259
|
+
async function auditMoluoxixiDeps(minimalOnly = false) {
|
|
233
260
|
console.log(chalk.blue.bold('\n🔍 开始审计 @moluoxixi 依赖...\n'));
|
|
261
|
+
const TEST_CONFIGS = generateTestConfigs(minimalOnly);
|
|
234
262
|
const requiredDeps = [
|
|
235
263
|
'@moluoxixi/vite-config',
|
|
236
264
|
'@moluoxixi/ajax-package',
|
|
237
265
|
];
|
|
238
266
|
let hasError = false;
|
|
239
267
|
for (const { name, config } of TEST_CONFIGS) {
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
|
|
268
|
+
// 根据框架决定输出目录
|
|
269
|
+
const frameworkOutputDir = config.framework === 'vue'
|
|
270
|
+
? path.join(TEST_OUTPUT_DIR, 'vue')
|
|
271
|
+
: path.join(TEST_OUTPUT_DIR, 'react');
|
|
272
|
+
const projectDir = path.join(frameworkOutputDir, name);
|
|
273
|
+
const packageJsonPath = path.join(projectDir, FILE_CONSTANTS.PACKAGE_JSON);
|
|
243
274
|
console.log(chalk.cyan(`📋 检查 ${name}...`));
|
|
244
275
|
// 根据配置决定需要检查的依赖
|
|
245
276
|
const depsToCheck = [...requiredDeps];
|
|
@@ -267,23 +298,6 @@ async function auditMoluoxixiDeps() {
|
|
|
267
298
|
console.log(chalk.red(` ❌ package.json 不存在`));
|
|
268
299
|
hasError = true;
|
|
269
300
|
}
|
|
270
|
-
// 检查 pnpm-workspace.yaml
|
|
271
|
-
if (fs.existsSync(workspacePath)) {
|
|
272
|
-
const workspaceContent = fs.readFileSync(workspacePath, 'utf-8');
|
|
273
|
-
for (const dep of depsToCheck) {
|
|
274
|
-
if (!workspaceContent.includes(dep)) {
|
|
275
|
-
console.log(chalk.red(` ❌ pnpm-workspace.yaml 缺少 ${dep}`));
|
|
276
|
-
hasError = true;
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
console.log(chalk.green(` ✅ pnpm-workspace.yaml 包含 ${dep}`));
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
console.log(chalk.red(` ❌ pnpm-workspace.yaml 不存在`));
|
|
285
|
-
hasError = true;
|
|
286
|
-
}
|
|
287
301
|
// 检查可选特性文件
|
|
288
302
|
if (!config.eslint) {
|
|
289
303
|
const eslintConfig = path.join(projectDir, 'eslint.config.ts');
|
|
@@ -305,6 +319,12 @@ async function auditMoluoxixiDeps() {
|
|
|
305
319
|
console.log(chalk.green(` ✅ .husky/ 目录已正确移除`));
|
|
306
320
|
}
|
|
307
321
|
}
|
|
322
|
+
// 检查 package.json 版本号(确保没有 catalog 引用)
|
|
323
|
+
console.log(chalk.cyan(` 🔍 检查 package.json 版本号...`));
|
|
324
|
+
const packageJsonOk = checkPackageJsonVersions(projectDir);
|
|
325
|
+
if (!packageJsonOk) {
|
|
326
|
+
hasError = true;
|
|
327
|
+
}
|
|
308
328
|
console.log('');
|
|
309
329
|
}
|
|
310
330
|
if (hasError) {
|
|
@@ -320,10 +340,33 @@ async function auditMoluoxixiDeps() {
|
|
|
320
340
|
*/
|
|
321
341
|
async function showFileTrees() {
|
|
322
342
|
console.log(chalk.blue.bold('\n📂 项目文件树...\n'));
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
343
|
+
const vueOutputDir = path.join(TEST_OUTPUT_DIR, 'vue');
|
|
344
|
+
const reactOutputDir = path.join(TEST_OUTPUT_DIR, 'react');
|
|
345
|
+
// 显示 Vue 项目
|
|
346
|
+
if (fs.existsSync(vueOutputDir)) {
|
|
347
|
+
console.log(chalk.cyan.bold('\n📁 Vue 项目:\n'));
|
|
348
|
+
const vueProjects = fs.readdirSync(vueOutputDir).filter((item) => {
|
|
349
|
+
const itemPath = path.join(vueOutputDir, item);
|
|
350
|
+
return fs.statSync(itemPath).isDirectory();
|
|
351
|
+
});
|
|
352
|
+
for (const projectName of vueProjects) {
|
|
353
|
+
const projectDir = path.join(vueOutputDir, projectName);
|
|
354
|
+
console.log(chalk.cyan(`\n${projectName}/`));
|
|
355
|
+
await printFileTree(projectDir, ' ');
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
// 显示 React 项目
|
|
359
|
+
if (fs.existsSync(reactOutputDir)) {
|
|
360
|
+
console.log(chalk.cyan.bold('\n📁 React 项目:\n'));
|
|
361
|
+
const reactProjects = fs.readdirSync(reactOutputDir).filter((item) => {
|
|
362
|
+
const itemPath = path.join(reactOutputDir, item);
|
|
363
|
+
return fs.statSync(itemPath).isDirectory();
|
|
364
|
+
});
|
|
365
|
+
for (const projectName of reactProjects) {
|
|
366
|
+
const projectDir = path.join(reactOutputDir, projectName);
|
|
367
|
+
console.log(chalk.cyan(`\n${projectName}/`));
|
|
368
|
+
await printFileTree(projectDir, ' ');
|
|
369
|
+
}
|
|
327
370
|
}
|
|
328
371
|
}
|
|
329
372
|
/**
|
|
@@ -332,7 +375,7 @@ async function showFileTrees() {
|
|
|
332
375
|
async function printFileTree(dir, indent) {
|
|
333
376
|
const items = fs.readdirSync(dir).sort();
|
|
334
377
|
for (const item of items) {
|
|
335
|
-
if (item ===
|
|
378
|
+
if (item === FILE_CONSTANTS.NODE_MODULES)
|
|
336
379
|
continue;
|
|
337
380
|
const itemPath = path.join(dir, item);
|
|
338
381
|
const stat = fs.statSync(itemPath);
|
|
@@ -349,16 +392,19 @@ async function printFileTree(dir, indent) {
|
|
|
349
392
|
* 主函数
|
|
350
393
|
*/
|
|
351
394
|
async function main() {
|
|
395
|
+
const { minimalOnly } = parseArgs();
|
|
352
396
|
console.log(chalk.blue.bold(`\n${'='.repeat(60)}`));
|
|
353
397
|
console.log(chalk.blue.bold(' Vite CLI Next - 产物审计测试'));
|
|
398
|
+
if (minimalOnly) {
|
|
399
|
+
console.log(chalk.yellow.bold(' 模式: 仅全量和最小配置'));
|
|
400
|
+
}
|
|
354
401
|
console.log(chalk.blue.bold('='.repeat(60)));
|
|
355
402
|
// 1. 生成测试项目
|
|
356
|
-
await generateTestProjects();
|
|
403
|
+
await generateTestProjects(minimalOnly);
|
|
357
404
|
// 2. 审计 @moluoxixi 依赖
|
|
358
|
-
await auditMoluoxixiDeps();
|
|
405
|
+
await auditMoluoxixiDeps(minimalOnly);
|
|
359
406
|
// 3. 显示文件树
|
|
360
407
|
await showFileTrees();
|
|
361
408
|
console.log(chalk.green.bold('\n✅ 全量产物审计完成!\n'));
|
|
362
409
|
}
|
|
363
410
|
main().catch(console.error);
|
|
364
|
-
//# sourceMappingURL=test.js.map
|
package/dist/types/ejs.d.ts
CHANGED
package/dist/types/ejs.js
CHANGED
package/dist/types/features.d.ts
CHANGED
|
@@ -23,4 +23,3 @@ export declare const VUE_FEATURES: readonly ["router", "pinia", "eslint", "i18n"
|
|
|
23
23
|
export declare const REACT_FEATURES: readonly ["router", "zustand", "eslint", "i18n", "sentry", "ant-design"];
|
|
24
24
|
export type VueFeatureId = typeof VUE_FEATURES[number];
|
|
25
25
|
export type ReactFeatureId = typeof REACT_FEATURES[number];
|
|
26
|
-
//# sourceMappingURL=features.d.ts.map
|
package/dist/types/features.js
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
* CLI 类型定义
|
|
3
3
|
* 定义项目配置、模板层级等核心类型
|
|
4
4
|
*/
|
|
5
|
-
export * from './ejs';
|
|
6
|
-
export * from './features';
|
|
7
|
-
export * from './viteConfig';
|
|
5
|
+
export * from './ejs.ts';
|
|
6
|
+
export * from './features.ts';
|
|
8
7
|
/**
|
|
9
8
|
* 框架类型
|
|
10
9
|
*/
|
|
@@ -56,4 +55,3 @@ export interface ProjectConfigType {
|
|
|
56
55
|
/** 目标目录 */
|
|
57
56
|
targetDir: string;
|
|
58
57
|
}
|
|
59
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/types/index.js
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* package.json 类型定义
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* package.json 文件结构接口
|
|
6
|
+
*/
|
|
7
|
+
export interface PackageJson {
|
|
8
|
+
/** 包名称 */
|
|
9
|
+
name?: string;
|
|
10
|
+
/** 版本号 */
|
|
11
|
+
version?: string;
|
|
12
|
+
/** 描述 */
|
|
13
|
+
description?: string;
|
|
14
|
+
/** 作者 */
|
|
15
|
+
author?: string;
|
|
16
|
+
/** 包管理器及版本 */
|
|
17
|
+
packageManager?: string;
|
|
18
|
+
/** 生产依赖 */
|
|
19
|
+
dependencies?: Record<string, string>;
|
|
20
|
+
/** 开发依赖 */
|
|
21
|
+
devDependencies?: Record<string, string>;
|
|
22
|
+
/** 其他字段 */
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|