@moluoxixi/create-app 2.0.4 → 2.0.403
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 +1 -2
- package/dist/types/features.js +1 -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/main.tsx.ejs +51 -6
- 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/qiankun/package.json +6 -0
- package/templates/react/features/qiankun/src/qiankun/index.ts +80 -0
- 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/main.ts.ejs +9 -25
- 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/src/router/index.ts.ejs +10 -13
- 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
|
@@ -1,96 +1,164 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { FILE_CONSTANTS } from "../constants/index.js";
|
|
4
|
+
import { validatePath } from "./file.js";
|
|
5
|
+
import { deepMerge } from "./deepMerge.js";
|
|
6
|
+
import { sortDependencies } from "./sortDependencies.js";
|
|
6
7
|
/**
|
|
7
8
|
* 渲染模板到目标目录
|
|
8
9
|
* 支持物理路径合并和配置文件深度合并
|
|
10
|
+
* @param src 源路径
|
|
11
|
+
* @param dest 目标路径
|
|
12
|
+
* @throws {Error} 如果路径不安全、文件操作失败
|
|
9
13
|
*/
|
|
10
14
|
export function renderTemplate(src, dest) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
// 验证路径安全性
|
|
16
|
+
validatePath(src);
|
|
17
|
+
validatePath(dest);
|
|
18
|
+
try {
|
|
19
|
+
const stats = fs.statSync(src);
|
|
20
|
+
// 处理目录
|
|
21
|
+
if (stats.isDirectory()) {
|
|
22
|
+
// 跳过 node_modules 目录
|
|
23
|
+
if (path.basename(src) === FILE_CONSTANTS.NODE_MODULES) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
27
|
+
for (const file of fs.readdirSync(src)) {
|
|
28
|
+
// 验证文件名安全性
|
|
29
|
+
if (file.includes('..') || file.includes('~')) {
|
|
30
|
+
throw new Error(`不安全的文件名: ${file}`);
|
|
31
|
+
}
|
|
32
|
+
renderTemplate(path.resolve(src, file), path.resolve(dest, file));
|
|
33
|
+
}
|
|
15
34
|
return;
|
|
16
35
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
36
|
+
// 处理文件
|
|
37
|
+
const filename = path.basename(src);
|
|
38
|
+
// 跳过 .ejs 文件(由生成器单独处理)
|
|
39
|
+
if (filename.endsWith(FILE_CONSTANTS.EJS_EXTENSION)) {
|
|
40
|
+
return;
|
|
20
41
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
42
|
+
// 处理 package.json - 深度合并
|
|
43
|
+
if (filename === FILE_CONSTANTS.PACKAGE_JSON) {
|
|
44
|
+
renderPackageJson(src, dest);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// 跳过 pnpm-workspace.yaml(不再使用)
|
|
48
|
+
if (filename === FILE_CONSTANTS.PNPM_WORKSPACE_YAML) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// 处理特殊文件名转换(如 _gitignore -> .gitignore)
|
|
52
|
+
const targetFilename = renameFile(filename);
|
|
53
|
+
const targetPath = path.resolve(path.dirname(dest), targetFilename);
|
|
54
|
+
// 普通文件直接复制(后面的会覆盖前面的)
|
|
55
|
+
fs.copyFileSync(src, targetPath);
|
|
27
56
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
57
|
+
catch (error) {
|
|
58
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
59
|
+
throw new Error(`渲染模板失败: ${src} -> ${dest}\n错误: ${errorMessage}`, {
|
|
60
|
+
cause: error,
|
|
61
|
+
});
|
|
31
62
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 对 package.json 的依赖进行排序
|
|
66
|
+
* @param packageJson package.json 对象(会被修改)
|
|
67
|
+
*/
|
|
68
|
+
function sortPackageJsonDependencies(packageJson) {
|
|
69
|
+
if (packageJson.dependencies) {
|
|
70
|
+
packageJson.dependencies = sortDependencies(packageJson.dependencies);
|
|
36
71
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
renderPnpmWorkspace(src, dest);
|
|
40
|
-
return;
|
|
72
|
+
if (packageJson.devDependencies) {
|
|
73
|
+
packageJson.devDependencies = sortDependencies(packageJson.devDependencies);
|
|
41
74
|
}
|
|
42
|
-
// 处理特殊文件名转换(如 _gitignore -> .gitignore)
|
|
43
|
-
const targetFilename = renameFile(filename);
|
|
44
|
-
const targetPath = path.resolve(path.dirname(dest), targetFilename);
|
|
45
|
-
// 普通文件直接复制(后面的会覆盖前面的)
|
|
46
|
-
fs.copyFileSync(src, targetPath);
|
|
47
75
|
}
|
|
48
76
|
/**
|
|
49
77
|
* 渲染 package.json - 深度合并
|
|
78
|
+
* @param src 源文件路径
|
|
79
|
+
* @param dest 目标文件路径
|
|
80
|
+
* @throws {Error} 如果文件读取失败、JSON 解析失败或写入失败
|
|
50
81
|
*/
|
|
51
82
|
function renderPackageJson(src, dest) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
merged
|
|
83
|
+
try {
|
|
84
|
+
const srcContent = fs.readFileSync(src, 'utf-8');
|
|
85
|
+
const newPackage = JSON.parse(srcContent);
|
|
86
|
+
if (fs.existsSync(dest)) {
|
|
87
|
+
const destContent = fs.readFileSync(dest, 'utf-8');
|
|
88
|
+
const existingPackage = JSON.parse(destContent);
|
|
89
|
+
const merged = deepMerge(existingPackage, newPackage);
|
|
90
|
+
sortPackageJsonDependencies(merged);
|
|
91
|
+
fs.writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\n`);
|
|
59
92
|
}
|
|
60
|
-
|
|
61
|
-
|
|
93
|
+
else {
|
|
94
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
95
|
+
fs.writeFileSync(dest, `${JSON.stringify(newPackage, null, 2)}\n`);
|
|
62
96
|
}
|
|
63
|
-
fs.writeFileSync(dest, `${JSON.stringify(merged, null, 2)}\n`);
|
|
64
97
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
98
|
+
catch (error) {
|
|
99
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
100
|
+
if (error instanceof SyntaxError) {
|
|
101
|
+
throw new TypeError(`package.json 解析失败: ${src}\n错误: ${errorMessage}`, { cause: error });
|
|
102
|
+
}
|
|
103
|
+
throw new Error(`处理 package.json 失败: ${src} -> ${dest}\n错误: ${errorMessage}`, { cause: error });
|
|
68
104
|
}
|
|
69
105
|
}
|
|
70
106
|
/**
|
|
71
|
-
*
|
|
107
|
+
* 获取包管理器的默认版本号
|
|
108
|
+
* @param packageManager 包管理器类型
|
|
109
|
+
* @returns 包管理器版本字符串
|
|
72
110
|
*/
|
|
73
|
-
function
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
111
|
+
function getPackageManagerVersion(packageManager) {
|
|
112
|
+
const versions = {
|
|
113
|
+
pnpm: '10.8.0',
|
|
114
|
+
npm: '10.9.0',
|
|
115
|
+
yarn: '4.1.0',
|
|
116
|
+
};
|
|
117
|
+
return versions[packageManager] || versions.pnpm;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 更新 package.json 的元数据字段(name, description, author, packageManager)
|
|
121
|
+
* @param packageJsonPath package.json 文件路径
|
|
122
|
+
* @param projectName 项目名称
|
|
123
|
+
* @param description 项目描述
|
|
124
|
+
* @param author 作者
|
|
125
|
+
* @param packageManager 包管理器类型
|
|
126
|
+
* @throws {Error} 如果文件读取失败、JSON 解析失败或写入失败
|
|
127
|
+
*/
|
|
128
|
+
export function updatePackageJsonMetadata(packageJsonPath, projectName, description, author, packageManager) {
|
|
129
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const content = fs.readFileSync(packageJsonPath, 'utf-8');
|
|
134
|
+
const packageJson = JSON.parse(content);
|
|
135
|
+
// 更新元数据字段
|
|
136
|
+
packageJson.name = projectName;
|
|
137
|
+
if (description) {
|
|
138
|
+
packageJson.description = description;
|
|
83
139
|
}
|
|
84
|
-
|
|
140
|
+
if (author) {
|
|
141
|
+
packageJson.author = author;
|
|
142
|
+
}
|
|
143
|
+
// 更新 packageManager 字段
|
|
144
|
+
packageJson.packageManager = `${packageManager}@${getPackageManagerVersion(packageManager)}`;
|
|
145
|
+
// 排序依赖
|
|
146
|
+
sortPackageJsonDependencies(packageJson);
|
|
147
|
+
fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`);
|
|
85
148
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
149
|
+
catch (error) {
|
|
150
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
151
|
+
if (error instanceof SyntaxError) {
|
|
152
|
+
throw new TypeError(`package.json 解析失败: ${packageJsonPath}\n错误: ${errorMessage}`, { cause: error });
|
|
153
|
+
}
|
|
154
|
+
throw new Error(`更新 package.json 元数据失败: ${packageJsonPath}\n错误: ${errorMessage}`, { cause: error });
|
|
89
155
|
}
|
|
90
156
|
}
|
|
91
157
|
/**
|
|
92
158
|
* 重命名特殊文件
|
|
93
159
|
* 某些文件不能以 . 开头存在于模板中,需要特殊处理
|
|
160
|
+
* @param name 原始文件名
|
|
161
|
+
* @returns 转换后的文件名
|
|
94
162
|
*/
|
|
95
163
|
function renameFile(name) {
|
|
96
164
|
// _开头的文件转换为.开头
|
|
@@ -99,4 +167,3 @@ function renameFile(name) {
|
|
|
99
167
|
}
|
|
100
168
|
return name;
|
|
101
169
|
}
|
|
102
|
-
//# sourceMappingURL=renderTemplate.js.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 对依赖对象进行排序
|
|
3
|
-
*
|
|
3
|
+
* 按字母顺序排列,@ 开头的包放在前面
|
|
4
|
+
* @param dependencies 依赖对象
|
|
5
|
+
* @returns 排序后的依赖对象
|
|
4
6
|
*/
|
|
5
7
|
export function sortDependencies(dependencies) {
|
|
6
8
|
const sorted = {};
|
|
@@ -19,4 +21,3 @@ export function sortDependencies(dependencies) {
|
|
|
19
21
|
}
|
|
20
22
|
return sorted;
|
|
21
23
|
}
|
|
22
|
-
//# sourceMappingURL=sortDependencies.js.map
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Vite 配置渲染工具
|
|
3
|
-
*
|
|
4
|
-
* 从各 feature 的 vite.config.data.ts 中读取配置
|
|
3
|
+
* 简化版:直接返回配置数据给 EJS 模板处理
|
|
5
4
|
*/
|
|
6
|
-
import type { ProjectConfigType
|
|
5
|
+
import type { ProjectConfigType } from '../types/index.ts';
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
7
|
+
* 生成 vite.config.ts 的 EJS 模板数据
|
|
8
|
+
* @param config 项目配置对象
|
|
9
|
+
* @returns EJS 模板数据对象,包含框架类型、Sentry 配置、UI 库和路由模式
|
|
9
10
|
*/
|
|
10
|
-
export declare function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* 生成 vite.config.ts 内容
|
|
17
|
-
*/
|
|
18
|
-
export declare function renderViteConfig(config: ProjectConfigType): string;
|
|
19
|
-
//# sourceMappingURL=viteConfigRender.d.ts.map
|
|
11
|
+
export declare function getViteConfigEjsData(config: ProjectConfigType): {
|
|
12
|
+
framework: string;
|
|
13
|
+
sentry?: boolean;
|
|
14
|
+
uiLibrary?: string;
|
|
15
|
+
routeMode?: string;
|
|
16
|
+
};
|
|
@@ -1,180 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Vite 配置渲染工具
|
|
3
|
-
*
|
|
4
|
-
* 从各 feature 的 vite.config.data.ts 中读取配置
|
|
3
|
+
* 简化版:直接返回配置数据给 EJS 模板处理
|
|
5
4
|
*/
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
import { createJiti } from 'jiti';
|
|
9
|
-
import { getTemplatesDir } from './file.js';
|
|
10
|
-
/** Jiti 实例,用于动态加载 TypeScript 配置文件 */
|
|
11
|
-
const jiti = createJiti(import.meta.url);
|
|
12
5
|
/**
|
|
13
|
-
*
|
|
6
|
+
* 生成 vite.config.ts 的 EJS 模板数据
|
|
7
|
+
* @param config 项目配置对象
|
|
8
|
+
* @returns EJS 模板数据对象,包含框架类型、Sentry 配置、UI 库和路由模式
|
|
14
9
|
*/
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
const module = jiti(dataPath);
|
|
23
|
-
return module.default;
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
console.error(`Failed to load ${dataPath}:`, error);
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 收集所有启用的 feature 的 vite.config.data
|
|
32
|
-
*/
|
|
33
|
-
export function collectViteConfigData(config) {
|
|
34
|
-
const framework = config.framework;
|
|
35
|
-
const dataList = [];
|
|
36
|
-
// 根据配置收集各 feature 的配置数据
|
|
37
|
-
const enabledFeatures = [];
|
|
38
|
-
if (config.sentry) {
|
|
39
|
-
enabledFeatures.push('sentry');
|
|
40
|
-
}
|
|
41
|
-
if (config.routeMode === 'file-system') {
|
|
42
|
-
enabledFeatures.push('pageRoutes');
|
|
43
|
-
}
|
|
44
|
-
if (framework === 'vue' && config.uiLibrary === 'element-plus') {
|
|
45
|
-
enabledFeatures.push('element-plus');
|
|
46
|
-
}
|
|
47
|
-
for (const feature of enabledFeatures) {
|
|
48
|
-
const data = readViteConfigData(framework, feature);
|
|
49
|
-
if (data) {
|
|
50
|
-
dataList.push(data);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return dataList;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* 合并 ViteConfigData 数组
|
|
57
|
-
*/
|
|
58
|
-
export function mergeViteConfigData(dataList) {
|
|
59
|
-
const merged = {
|
|
60
|
-
imports: [],
|
|
61
|
-
options: {},
|
|
62
|
-
plugins: [],
|
|
10
|
+
export function getViteConfigEjsData(config) {
|
|
11
|
+
return {
|
|
12
|
+
framework: config.framework,
|
|
13
|
+
sentry: config.sentry,
|
|
14
|
+
uiLibrary: config.uiLibrary,
|
|
15
|
+
routeMode: config.routeMode,
|
|
63
16
|
};
|
|
64
|
-
for (const data of dataList) {
|
|
65
|
-
if (data.imports) {
|
|
66
|
-
merged.imports.push(...data.imports);
|
|
67
|
-
}
|
|
68
|
-
if (data.options) {
|
|
69
|
-
Object.assign(merged.options, data.options);
|
|
70
|
-
}
|
|
71
|
-
if (data.plugins) {
|
|
72
|
-
merged.plugins.push(...data.plugins);
|
|
73
|
-
}
|
|
74
|
-
if (data.css) {
|
|
75
|
-
merged.css = data.css;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return merged;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* 生成 vite.config.ts 内容
|
|
82
|
-
*/
|
|
83
|
-
export function renderViteConfig(config) {
|
|
84
|
-
const dataList = collectViteConfigData(config);
|
|
85
|
-
const merged = mergeViteConfigData(dataList);
|
|
86
|
-
const lines = [];
|
|
87
|
-
lines.push('/**');
|
|
88
|
-
lines.push(' * Vite 配置文件');
|
|
89
|
-
lines.push(' * 基于 @moluoxixi/vite-config 的配置');
|
|
90
|
-
lines.push(' */');
|
|
91
|
-
lines.push('');
|
|
92
|
-
lines.push('import path from \'node:path\'');
|
|
93
|
-
lines.push('import process from \'node:process\'');
|
|
94
|
-
lines.push('import cssModuleGlobalRootPlugin from \'@moluoxixi/css-module-global-root-plugin\'');
|
|
95
|
-
lines.push('import { ViteConfig, wrapperEnv } from \'@moluoxixi/vite-config\'');
|
|
96
|
-
// 添加 feature 导入
|
|
97
|
-
if (merged.imports && merged.imports.length > 0) {
|
|
98
|
-
for (const imp of merged.imports) {
|
|
99
|
-
lines.push(imp);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
lines.push('import { loadEnv } from \'vite\'');
|
|
103
|
-
lines.push('');
|
|
104
|
-
lines.push('export default ViteConfig(');
|
|
105
|
-
lines.push(' ({ mode }) => {');
|
|
106
|
-
lines.push(' const env = loadEnv(mode!, process.cwd())');
|
|
107
|
-
lines.push(' const viteEnv = wrapperEnv(env)');
|
|
108
|
-
lines.push(' const rootPath = path.resolve()');
|
|
109
|
-
lines.push(' const appCode = viteEnv.VITE_APP_CODE');
|
|
110
|
-
lines.push(' const appTitle = viteEnv.VITE_APP_TITLE');
|
|
111
|
-
lines.push(' const port = viteEnv.VITE_APP_PORT');
|
|
112
|
-
lines.push(' return {');
|
|
113
|
-
lines.push(' rootPath,');
|
|
114
|
-
lines.push(' appTitle,');
|
|
115
|
-
lines.push(' appCode,');
|
|
116
|
-
lines.push(' port,');
|
|
117
|
-
// 框架配置
|
|
118
|
-
if (config.framework === 'vue') {
|
|
119
|
-
lines.push(' vue: true,');
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
lines.push(' react: true,');
|
|
123
|
-
}
|
|
124
|
-
lines.push(' autoComponent: true,');
|
|
125
|
-
// 添加 feature options
|
|
126
|
-
if (merged.options) {
|
|
127
|
-
for (const [key, value] of Object.entries(merged.options)) {
|
|
128
|
-
if (typeof value === 'boolean') {
|
|
129
|
-
lines.push(` ${key}: ${value},`);
|
|
130
|
-
}
|
|
131
|
-
else if (typeof value === 'string') {
|
|
132
|
-
lines.push(` ${key}: '${value}',`);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
lines.push(` ${key}: ${JSON.stringify(value)},`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
lines.push(' viteConfig: {');
|
|
140
|
-
lines.push(' plugins: [');
|
|
141
|
-
// 添加 feature plugins
|
|
142
|
-
if (merged.plugins && merged.plugins.length > 0) {
|
|
143
|
-
for (const plugin of merged.plugins) {
|
|
144
|
-
lines.push(` ${plugin},`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
lines.push(' ],');
|
|
148
|
-
lines.push(' server: {');
|
|
149
|
-
lines.push(' proxy: {');
|
|
150
|
-
lines.push(' \'/api\': {');
|
|
151
|
-
lines.push(' changeOrigin: true,');
|
|
152
|
-
lines.push(' target: \'http://localhost:3000\',');
|
|
153
|
-
lines.push(' },');
|
|
154
|
-
lines.push(' },');
|
|
155
|
-
lines.push(' },');
|
|
156
|
-
lines.push(' css: {');
|
|
157
|
-
lines.push(' postcss: {');
|
|
158
|
-
lines.push(' plugins: [');
|
|
159
|
-
lines.push(' cssModuleGlobalRootPlugin,');
|
|
160
|
-
lines.push(' ],');
|
|
161
|
-
lines.push(' },');
|
|
162
|
-
lines.push(' preprocessorOptions: {');
|
|
163
|
-
lines.push(' scss: {');
|
|
164
|
-
lines.push(' silenceDeprecations: [\'legacy-js-api\'],');
|
|
165
|
-
lines.push(' api: \'modern-compiler\',');
|
|
166
|
-
// 添加 CSS additionalData
|
|
167
|
-
if (merged.css?.additionalData) {
|
|
168
|
-
lines.push(` ${merged.css.additionalData}`);
|
|
169
|
-
}
|
|
170
|
-
lines.push(' },');
|
|
171
|
-
lines.push(' },');
|
|
172
|
-
lines.push(' },');
|
|
173
|
-
lines.push(' },');
|
|
174
|
-
lines.push(' }');
|
|
175
|
-
lines.push(' },');
|
|
176
|
-
lines.push(')');
|
|
177
|
-
lines.push('');
|
|
178
|
-
return lines.join('\n');
|
|
179
17
|
}
|
|
180
|
-
//# sourceMappingURL=viteConfigRender.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moluoxixi/create-app",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.403",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Create Vue/React projects with atomic layered architecture",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"yaml": "^2.6.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
+
"vite": "^6.2.4",
|
|
52
53
|
"@commitlint/cli": "^19.8.0",
|
|
53
54
|
"@commitlint/config-conventional": "^19.8.0",
|
|
54
55
|
"@moluoxixi/eslint-config": "latest",
|
|
@@ -56,6 +57,7 @@
|
|
|
56
57
|
"@types/fs-extra": "^11.0.4",
|
|
57
58
|
"@types/inquirer": "^9.0.7",
|
|
58
59
|
"@types/lodash-es": "^4.17.12",
|
|
60
|
+
"@vue-macros/volar": "^3.0.0-beta.15",
|
|
59
61
|
"@types/node": "^22.14.0",
|
|
60
62
|
"commitizen": "^4.3.1",
|
|
61
63
|
"cz-customizable": "^7.4.0",
|
|
@@ -70,7 +72,7 @@
|
|
|
70
72
|
},
|
|
71
73
|
"scripts": {
|
|
72
74
|
"dev": "tsx src/index.ts",
|
|
73
|
-
"build": "tsc",
|
|
75
|
+
"build": "tsc --build tsconfig.build.json",
|
|
74
76
|
"test": "tsx src/test.ts --min",
|
|
75
77
|
"test:all": "tsx src/test.ts",
|
|
76
78
|
"type-check": "tsc --noEmit",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# 环境变量配置
|
|
2
|
-
# 所有环境通用
|
|
3
|
-
|
|
4
|
-
VITE_APP_CODE=app
|
|
5
|
-
VITE_APP_TITLE=My App
|
|
6
|
-
VITE_APP_PORT=3000
|
|
7
|
-
VITE_APP_VERSION=0.0.0
|
|
1
|
+
# 环境变量配置
|
|
2
|
+
# 所有环境通用
|
|
3
|
+
|
|
4
|
+
VITE_APP_CODE=app
|
|
5
|
+
VITE_APP_TITLE=My App
|
|
6
|
+
VITE_APP_PORT=3000
|
|
7
|
+
VITE_APP_VERSION=0.0.0
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# 开发环境变量配置
|
|
2
|
-
|
|
3
|
-
VITE_APP_ENV=development
|
|
4
|
-
VITE_API_BASE_URL=http://localhost:3000
|
|
5
|
-
VITE_SENTRY=false
|
|
1
|
+
# 开发环境变量配置
|
|
2
|
+
|
|
3
|
+
VITE_APP_ENV=development
|
|
4
|
+
VITE_API_BASE_URL=http://localhost:3000
|
|
5
|
+
VITE_SENTRY=false
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# 生产环境变量配置
|
|
2
|
-
|
|
3
|
-
VITE_APP_ENV=production
|
|
4
|
-
VITE_API_BASE_URL=https://api.example.com
|
|
5
|
-
VITE_SENTRY=true
|
|
1
|
+
# 生产环境变量配置
|
|
2
|
+
|
|
3
|
+
VITE_APP_ENV=production
|
|
4
|
+
VITE_API_BASE_URL=https://api.example.com
|
|
5
|
+
VITE_SENTRY=true
|
|
@@ -21,36 +21,32 @@
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@moluoxixi/ajax-package": "
|
|
25
|
-
"@moluoxixi/class-names": "
|
|
26
|
-
"crypto-js": "
|
|
27
|
-
"dayjs": "
|
|
28
|
-
"lodash-es": "
|
|
29
|
-
"radash": "
|
|
30
|
-
"uuid": "
|
|
24
|
+
"@moluoxixi/ajax-package": "latest",
|
|
25
|
+
"@moluoxixi/class-names": "latest",
|
|
26
|
+
"crypto-js": "^4.2.0",
|
|
27
|
+
"dayjs": "^1.11.13",
|
|
28
|
+
"lodash-es": "^4.17.21",
|
|
29
|
+
"radash": "^12.1.0",
|
|
30
|
+
"uuid": "^11.1.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"@types/
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"tsx": "catalog:dev",
|
|
50
|
-
"typescript": "catalog:dev",
|
|
51
|
-
"vite": "catalog:dev"
|
|
33
|
+
"@types/crypto-js": "^4.2.2",
|
|
34
|
+
"@types/lodash-es": "^4.17.12",
|
|
35
|
+
"@types/node": "^22.14.0",
|
|
36
|
+
"@types/uuid": "^10.0.0",
|
|
37
|
+
"autoprefixer": "^10.4.20",
|
|
38
|
+
"compressing": "^1.10.1",
|
|
39
|
+
"dotenv": "^16.5.0",
|
|
40
|
+
"jiti": "^2.4.2",
|
|
41
|
+
"postcss": "^8.5.3",
|
|
42
|
+
"sass": "^1.87.0",
|
|
43
|
+
"sass-embedded": "^1.87.0",
|
|
44
|
+
"sass-loader": "^16.0.5",
|
|
45
|
+
"tailwindcss": "^4.0.0",
|
|
46
|
+
"tsx": "^4.20.5",
|
|
47
|
+
"typescript": "~5.8.0",
|
|
48
|
+
"vite": "^6.2.4"
|
|
52
49
|
},
|
|
53
50
|
"author": "",
|
|
54
51
|
"license": "MIT"
|
|
55
52
|
}
|
|
56
|
-
|