wyt-cli 1.0.2 → 1.0.3
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/bin/commands/create.js +230 -56
- package/bin/dist/default/index.html +13 -0
- package/bin/dist/default/package.json +28 -0
- package/bin/dist/default/src/App.vue +20 -0
- package/bin/dist/default/src/api/index.js +15 -0
- package/bin/dist/default/src/component/TestComponent.vue +5 -0
- package/bin/dist/default/src/main.js +20 -0
- package/bin/dist/default/src/router/index.js +23 -0
- package/bin/dist/default/src/style.css +20 -0
- package/bin/dist/default/src/views/Home.vue +8 -0
- package/bin/dist/default/src/views/NotFound.vue +13 -0
- package/bin/dist/default/vite.config.js +51 -0
- package/bin/lib/const.js +1 -1
- package/bin/lib/logger.js +37 -0
- package/bin/lib/utils.js +19 -5
- package/bin/main.js +30 -15
- package/bin/templates/default/index.html +13 -0
- package/bin/templates/default/node_modules/.bin/sass +17 -0
- package/bin/templates/default/node_modules/.bin/sass.CMD +12 -0
- package/bin/templates/default/node_modules/.bin/sass.ps1 +41 -0
- package/bin/templates/default/node_modules/.bin/vite +17 -0
- package/bin/templates/default/node_modules/.bin/vite.CMD +12 -0
- package/bin/templates/default/node_modules/.bin/vite.ps1 +41 -0
- package/bin/templates/default/node_modules/.vite/deps/@element-plus_icons-vue.js +592 -0
- package/bin/templates/default/node_modules/.vite/deps/@element-plus_icons-vue.js.map +7 -0
- package/bin/templates/default/node_modules/.vite/deps/_metadata.json +73 -0
- package/bin/templates/default/node_modules/.vite/deps/axios.js +2520 -0
- package/bin/templates/default/node_modules/.vite/deps/axios.js.map +7 -0
- package/bin/templates/default/node_modules/.vite/deps/chunk-AW3DCZT7.js +162 -0
- package/bin/templates/default/node_modules/.vite/deps/chunk-AW3DCZT7.js.map +7 -0
- package/bin/templates/default/node_modules/.vite/deps/chunk-G3PMV62Z.js +35 -0
- package/bin/templates/default/node_modules/.vite/deps/chunk-G3PMV62Z.js.map +7 -0
- package/bin/templates/default/node_modules/.vite/deps/chunk-GQX4HV27.js +5482 -0
- package/bin/templates/default/node_modules/.vite/deps/chunk-GQX4HV27.js.map +7 -0
- package/bin/templates/default/node_modules/.vite/deps/chunk-MAX6BVKX.js +12621 -0
- package/bin/templates/default/node_modules/.vite/deps/chunk-MAX6BVKX.js.map +7 -0
- package/bin/templates/default/node_modules/.vite/deps/chunk-USB5I3PS.js +25 -0
- package/bin/templates/default/node_modules/.vite/deps/chunk-USB5I3PS.js.map +7 -0
- package/bin/templates/default/node_modules/.vite/deps/element-plus.js +65145 -0
- package/bin/templates/default/node_modules/.vite/deps/element-plus.js.map +7 -0
- package/bin/templates/default/node_modules/.vite/deps/element-plus_dist_locale_zh-cn__mjs.js +190 -0
- package/bin/templates/default/node_modules/.vite/deps/element-plus_dist_locale_zh-cn__mjs.js.map +7 -0
- package/bin/templates/default/node_modules/.vite/deps/package.json +3 -0
- package/bin/templates/default/node_modules/.vite/deps/pinia.js +1547 -0
- package/bin/templates/default/node_modules/.vite/deps/pinia.js.map +7 -0
- package/bin/templates/default/node_modules/.vite/deps/print-js.js +898 -0
- package/bin/templates/default/node_modules/.vite/deps/print-js.js.map +7 -0
- package/bin/templates/default/node_modules/.vite/deps/vue-router.js +2782 -0
- package/bin/templates/default/node_modules/.vite/deps/vue-router.js.map +7 -0
- package/bin/templates/default/node_modules/.vite/deps/vue.js +343 -0
- package/bin/templates/default/node_modules/.vite/deps/vue.js.map +7 -0
- package/bin/templates/default/package.json +27 -7
- package/bin/templates/default/src/App.vue +20 -0
- package/bin/templates/default/src/api/index.js +15 -0
- package/bin/templates/default/src/component/TestComponent.vue +5 -0
- package/bin/templates/default/src/main.js +20 -0
- package/bin/templates/default/src/router/index.js +23 -0
- package/bin/templates/default/src/style.css +20 -0
- package/bin/templates/default/src/views/Home.vue +8 -0
- package/bin/templates/default/src/views/NotFound.vue +13 -0
- package/bin/templates/default/vite.config.js +51 -0
- package/package.json +31 -28
- package/bin/templates/default/main.js +0 -1
- package/bin/templates/default/package-lock.json +0 -0
package/bin/commands/create.js
CHANGED
|
@@ -1,96 +1,270 @@
|
|
|
1
1
|
// commands/create.js
|
|
2
2
|
|
|
3
|
-
import path from
|
|
4
|
-
import { require
|
|
3
|
+
import path from 'path';
|
|
4
|
+
// import { require } from '../lib/utils.js';
|
|
5
|
+
import { log_error, log_info, log_success, log_warning } from '../lib/logger.js';
|
|
5
6
|
|
|
6
7
|
// 外部依赖
|
|
7
|
-
import { Command } from
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import inquirer from
|
|
8
|
+
import { Command } from 'commander';
|
|
9
|
+
import { glob } from 'glob';
|
|
10
|
+
import fs from 'fs-extra';
|
|
11
|
+
import ora from 'ora';
|
|
12
|
+
import inquirer from 'inquirer';
|
|
13
|
+
import ejs from 'ejs';
|
|
12
14
|
|
|
15
|
+
const spinner = ora();
|
|
13
16
|
// 命令配置
|
|
14
17
|
export default function () {
|
|
15
|
-
const command = new Command(
|
|
16
|
-
command.description(
|
|
17
|
-
command.argument(
|
|
18
|
-
command.option(
|
|
19
|
-
command.option(
|
|
20
|
-
command.option(
|
|
21
|
-
command.
|
|
18
|
+
const command = new Command('create');
|
|
19
|
+
command.description('创建一个新项目');
|
|
20
|
+
command.argument('[project-name]', '项目名称(仅支持字母、数字和中划线)', '');
|
|
21
|
+
command.option('-t, --template <template-name>', '指定项目模板', 'default');
|
|
22
|
+
command.option('-d, --dir <directory>', '指定创建目录', process.cwd());
|
|
23
|
+
command.option('-l, --list', '显示已有项目列表', true);
|
|
24
|
+
command.option('-f, --force', '强制覆盖已存在目录');
|
|
25
|
+
command.action(async (projectName, options) => {
|
|
26
|
+
// 校验项目根目录是否合法
|
|
27
|
+
if (!checkTargetDir(options.dir)) {
|
|
28
|
+
log_error('请在 HRP3.0 项目根目录下创建项目!');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
spinner.start('正在获取已有项目列表...');
|
|
32
|
+
const glob_projectInfo = await checkProjectInfo(options);
|
|
33
|
+
spinner.stop();
|
|
34
|
+
|
|
35
|
+
// 询问 -> 创建项目
|
|
36
|
+
const inquirerAnswers = await inquirer.prompt([
|
|
37
|
+
{
|
|
38
|
+
type: 'input',
|
|
39
|
+
name: 'projectName',
|
|
40
|
+
message: '请输入项目名称:',
|
|
41
|
+
validate: (input) => {
|
|
42
|
+
// 校验规则
|
|
43
|
+
if (!input) return '项目名称不能为空!';
|
|
44
|
+
if (!/^[a-zA-Z0-9-]{1,50}$/.test(input)) {
|
|
45
|
+
return '名称只能包含字母、数字和中划线,且不超过50字符';
|
|
46
|
+
}
|
|
47
|
+
if (glob_projectInfo.map((item) => item.name).includes(input.toLowerCase())) {
|
|
48
|
+
return `项目名称 "${input}" 已存在,请重新输入`;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
},
|
|
52
|
+
// 当命令行已传入名称时自动跳过
|
|
53
|
+
when: !projectName,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: 'input',
|
|
57
|
+
name: 'devServerPort',
|
|
58
|
+
message: '请输入测试服务器端口号:',
|
|
59
|
+
validate: (input) => {
|
|
60
|
+
// 校验规则
|
|
61
|
+
if (!input) return '测试服务器端口号不能为空!';
|
|
62
|
+
if (!/^\d+$/.test(input)) {
|
|
63
|
+
return '测试服务器端口号必须为纯数字';
|
|
64
|
+
}
|
|
65
|
+
if (glob_projectInfo.map((item) => item.port).includes(input)) {
|
|
66
|
+
return `测试服务器端口号 "${input}" 已存在,请重新输入`;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
// 执行创建项目逻辑
|
|
74
|
+
projectName = inquirerAnswers.projectName || projectName;
|
|
75
|
+
options.devServerPort = inquirerAnswers.devServerPort;
|
|
76
|
+
createAction(projectName, options);
|
|
77
|
+
});
|
|
22
78
|
|
|
23
79
|
return command;
|
|
24
80
|
}
|
|
25
81
|
|
|
26
82
|
// 核心创建逻辑
|
|
27
|
-
function
|
|
83
|
+
function createAction(projectName, options) {
|
|
28
84
|
try {
|
|
29
|
-
|
|
30
|
-
if (!/^[a-zA-Z0-9-]+$/.test(projectName)) {
|
|
31
|
-
console.error("项目名称只能包含字母、数字和中划线!");
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const spinner = ora("正在创建项目...").start();
|
|
35
|
-
const targetDir = path.resolve(options.dir, projectName);
|
|
85
|
+
const targetDir = path.resolve(options.dir, 'apps', projectName);
|
|
36
86
|
// 校验目录存在性
|
|
37
87
|
if (fs.existsSync(targetDir)) {
|
|
38
88
|
if (!options.force) {
|
|
39
|
-
|
|
40
|
-
throw new Error("使用 --force 强制覆盖");
|
|
89
|
+
throw new Error(`项目 ${projectName} 已存在,使用 --force 强制覆盖`);
|
|
41
90
|
}
|
|
42
|
-
spinner.stop();
|
|
43
91
|
inquirer
|
|
44
92
|
.prompt([
|
|
45
93
|
{
|
|
46
|
-
type:
|
|
47
|
-
name:
|
|
48
|
-
message:
|
|
94
|
+
type: 'confirm',
|
|
95
|
+
name: 'confirmOverwrite',
|
|
96
|
+
message: `项目 ${projectName} 已存在,是否覆盖?`,
|
|
49
97
|
default: true,
|
|
50
98
|
},
|
|
51
99
|
])
|
|
52
100
|
.then((answers) => {
|
|
53
101
|
if (answers.confirmOverwrite) {
|
|
54
|
-
spinner.info("强制覆盖已存在目录");
|
|
55
102
|
fs.emptyDirSync(targetDir);
|
|
56
|
-
createProject(projectName,
|
|
57
|
-
|
|
58
|
-
// 关闭进度条
|
|
59
|
-
spinner.succeed(chalk.green(`项目 ${projectName} 强制创建成功!`));
|
|
103
|
+
createProject(projectName, options);
|
|
104
|
+
log_success(`项目 ${projectName} 强制创建成功!`);
|
|
60
105
|
} else {
|
|
61
|
-
|
|
106
|
+
log_info('操作已取消');
|
|
62
107
|
process.exit(1);
|
|
63
108
|
}
|
|
64
109
|
});
|
|
65
110
|
} else {
|
|
66
|
-
createProject(projectName,
|
|
67
|
-
|
|
68
|
-
// 关闭进度条
|
|
69
|
-
spinner.succeed(chalk.green(`项目 ${projectName} 创建成功!`));
|
|
111
|
+
createProject(projectName, options);
|
|
112
|
+
log_success(`项目 ${projectName} 创建成功!`);
|
|
70
113
|
}
|
|
71
114
|
} catch (error) {
|
|
72
|
-
|
|
115
|
+
log_error(error.message);
|
|
73
116
|
process.exit(1);
|
|
74
117
|
}
|
|
75
118
|
}
|
|
76
119
|
|
|
120
|
+
// 检查目标目录是否存在
|
|
121
|
+
function checkTargetDir(currentPath) {
|
|
122
|
+
const monoDirs = ['apps', 'packages'];
|
|
123
|
+
const conflictDirs = monoDirs
|
|
124
|
+
.map((dir) => ({
|
|
125
|
+
name: dir,
|
|
126
|
+
path: path.join(currentPath, dir),
|
|
127
|
+
exists: fs.existsSync(path.join(currentPath, dir)),
|
|
128
|
+
}))
|
|
129
|
+
.filter((item) => item.exists)
|
|
130
|
+
.map((item) => item.name);
|
|
131
|
+
|
|
132
|
+
return conflictDirs.join(',') == monoDirs.join(',');
|
|
133
|
+
}
|
|
134
|
+
|
|
77
135
|
// 创建项目
|
|
78
|
-
function createProject(projectName,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
136
|
+
async function createProject(projectName, options) {
|
|
137
|
+
const files = await glob('./wyt-cli/bin/templates/**/*', {
|
|
138
|
+
cwd: process.cwd(), // 以项目根目录为基准
|
|
139
|
+
absolute: true, // 返回绝对路径
|
|
140
|
+
nodir: true, // 只保留文件
|
|
141
|
+
});
|
|
142
|
+
const renderTasks = files.map(async (filePath) => {
|
|
143
|
+
// 生成输出路径
|
|
144
|
+
const outputPath = filePath.replace('wyt-cli\\bin\\templates\\default', `apps\\${projectName}`);
|
|
145
|
+
|
|
146
|
+
// 递归创建所有不存在的父级目录,确保输出目录存在
|
|
147
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
148
|
+
|
|
149
|
+
// 自动读取文件内容, 渲染模板文件
|
|
150
|
+
const fileContent = await ejs.renderFile(filePath, {
|
|
151
|
+
projectName,
|
|
152
|
+
buildOutDir: `../../dist/${projectName}`,
|
|
153
|
+
devServerPort: Number(options.devServerPort),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// 写入文件
|
|
157
|
+
fs.writeFileSync(outputPath, fileContent);
|
|
158
|
+
|
|
159
|
+
return outputPath;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// 执行所有渲染任务
|
|
163
|
+
Promise.all(renderTasks);
|
|
164
|
+
|
|
165
|
+
// 更新 root -> package.json -> apps 配置
|
|
166
|
+
updateRootPackageJson(projectName, options);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// 检测已有项目信息
|
|
170
|
+
async function checkProjectInfo(options) {
|
|
171
|
+
const files = await glob(['**/package.json'], {
|
|
172
|
+
cwd: path.resolve(options.dir, 'apps'), // 以项目根目录为基准
|
|
173
|
+
absolute: true, // 返回绝对路径
|
|
174
|
+
ignore: [
|
|
175
|
+
// 添加排除规则
|
|
176
|
+
'**/node_modules/**', // 排除 node_modules
|
|
177
|
+
'**/src/**', // 排除测试目录
|
|
178
|
+
'**/.*', // 排除隐藏文件/目录
|
|
179
|
+
],
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
let results = await Promise.all(
|
|
183
|
+
files.map(async (file) => {
|
|
184
|
+
// 识别文件类型
|
|
185
|
+
const isPkg = file.endsWith('package.json');
|
|
186
|
+
// const isVite = file.endsWith('vite.config.js');
|
|
187
|
+
// const isVite_ts = file.endsWith('vite.config.ts');
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
// 读取文件内容
|
|
191
|
+
const content = await fs.promises.readFile(file, 'utf-8');
|
|
192
|
+
|
|
193
|
+
if (isPkg) {
|
|
194
|
+
// 解析 package.json
|
|
195
|
+
const pkg = JSON.parse(content);
|
|
196
|
+
return { port: pkg.devServer && pkg.devServer.port, name: pkg.name };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// if (isVite) {
|
|
200
|
+
// // 动态导入 vite 配置
|
|
201
|
+
// const viteConfig = require(file);
|
|
202
|
+
// const port = viteConfig.default?.server.port;
|
|
203
|
+
// return { type: 'vite', port };
|
|
204
|
+
// }
|
|
205
|
+
|
|
206
|
+
// // 单独 ts 项目 -> 财务系统 fm
|
|
207
|
+
// if (isVite_ts) {
|
|
208
|
+
// return { type: 'vite', port: 6002 };
|
|
209
|
+
// }
|
|
210
|
+
} catch (err) {
|
|
211
|
+
console.error(`文件处理失败: ${file}`, err);
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
})
|
|
215
|
+
);
|
|
216
|
+
// 排序逻辑
|
|
217
|
+
results = results.sort((a, b) => {
|
|
218
|
+
// 处理 undefined 端口为最大值
|
|
219
|
+
const portA = a.port ? parseInt(a.port) : Infinity;
|
|
220
|
+
const portB = b.port ? parseInt(b.port) : Infinity;
|
|
221
|
+
// 优先级 1: 端口号升序
|
|
222
|
+
if (portA !== portB) {
|
|
223
|
+
return portA - portB;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// 优先级 2: 名称字母序
|
|
227
|
+
return a.name.localeCompare(b.name);
|
|
91
228
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
229
|
+
|
|
230
|
+
// 组合项目信息
|
|
231
|
+
const projectList = results.map((item, index) => ({
|
|
232
|
+
序号: index + 1,
|
|
233
|
+
项目名称: item.name,
|
|
234
|
+
'DevServer 端口号': item.port || '未配置',
|
|
235
|
+
}));
|
|
236
|
+
// // 格式化输出
|
|
237
|
+
if (options.list) {
|
|
238
|
+
console.log('\n\n====== 已存在的项目列表,请不要重复 ======');
|
|
239
|
+
console.table(projectList, ['序号', '项目名称', 'DevServer 端口号']);
|
|
240
|
+
}
|
|
241
|
+
return results;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// 更新 root -> package.json -> apps 配置
|
|
245
|
+
async function updateRootPackageJson(projectName, options) {
|
|
246
|
+
const appsConfigPath = path.join(process.cwd(), 'package.json');
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
// 读取配置
|
|
250
|
+
const appsConfig = await fs.readJSON(appsConfigPath);
|
|
251
|
+
|
|
252
|
+
// 初始化 apps 数组
|
|
253
|
+
appsConfig.apps = appsConfig.apps || [];
|
|
254
|
+
// 新增应用配置
|
|
255
|
+
appsConfig.apps.push({
|
|
256
|
+
name: projectName,
|
|
257
|
+
port: options.devServerPort,
|
|
258
|
+
created: new Date().toISOString(),
|
|
259
|
+
});
|
|
260
|
+
// 写入更新
|
|
261
|
+
await fs.writeJSON(appsConfigPath, appsConfig, {
|
|
262
|
+
spaces: 2,
|
|
263
|
+
replacer: null, // 保留完整数据结构
|
|
264
|
+
});
|
|
265
|
+
return true;
|
|
266
|
+
} catch (error) {
|
|
267
|
+
console.error('更新应用配置失败:', error);
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
96
270
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>test</title>
|
|
7
|
+
</head>
|
|
8
|
+
|
|
9
|
+
<body>
|
|
10
|
+
<div id="app"></div>
|
|
11
|
+
<script type="module" src="./src/main.js"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "test",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "个人工作台",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "vite",
|
|
9
|
+
"build": "vite build",
|
|
10
|
+
"preview": "vite preview"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@element-plus/icons-vue": "^2.3.1",
|
|
14
|
+
"@wyt/components": "workspace:^",
|
|
15
|
+
"@wyt/utils": "workspace:^",
|
|
16
|
+
"element-plus": "^2.10.2",
|
|
17
|
+
"pinia": "^2.0.28",
|
|
18
|
+
"sass": "^1.89.2",
|
|
19
|
+
"vue": "^3.5.13",
|
|
20
|
+
"vue-router": "^4.5.0",
|
|
21
|
+
"wujie-polyfill": "^1.1.3",
|
|
22
|
+
"wujie-vue3": "^1.0.24"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@vitejs/plugin-vue": "^5.2.1",
|
|
26
|
+
"vite": "^6.0.5"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="app-container">
|
|
3
|
+
<Home />
|
|
4
|
+
<router-view></router-view>
|
|
5
|
+
</div>
|
|
6
|
+
</template>
|
|
7
|
+
|
|
8
|
+
<script setup scoped>
|
|
9
|
+
import Home from './views/Home.vue';
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<style scoped>
|
|
13
|
+
.app-container {
|
|
14
|
+
width: 100%;
|
|
15
|
+
height: calc(100vh - 70px);
|
|
16
|
+
background-color: #fff;
|
|
17
|
+
overflow: auto;
|
|
18
|
+
scrollbar-width: thin;
|
|
19
|
+
}
|
|
20
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createApp } from 'vue';
|
|
2
|
+
import { createPinia } from 'pinia';
|
|
3
|
+
import App from './App.vue';
|
|
4
|
+
import router from './router';
|
|
5
|
+
import './style.css';
|
|
6
|
+
import ElementPlus from 'element-plus';
|
|
7
|
+
import zhCn from 'element-plus/dist/locale/zh-cn.mjs';
|
|
8
|
+
import 'element-plus/dist/index.css';
|
|
9
|
+
import wytComponents from '@wyt/components';
|
|
10
|
+
import '@wyt/components/dist/themes/index.css';
|
|
11
|
+
import '@wyt/components/dist/index.css';
|
|
12
|
+
import '@wyt/components/dist/assets/iconfont/iconfont.css';
|
|
13
|
+
import '@wyt/form-designer/dist/style.css';
|
|
14
|
+
import { initAndListenTheme } from '@wyt/utils';
|
|
15
|
+
|
|
16
|
+
initAndListenTheme();
|
|
17
|
+
|
|
18
|
+
const app = createApp(App);
|
|
19
|
+
|
|
20
|
+
app.use(createPinia()).use(wytComponents).use(router).use(ElementPlus, { locale: zhCn }).mount('#app');
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createRouter, createWebHashHistory } from 'vue-router';
|
|
2
|
+
const basename = process.env.NODE_ENV === 'production' ? '/mw/' : '';
|
|
3
|
+
|
|
4
|
+
const routes = [
|
|
5
|
+
// {
|
|
6
|
+
// path: '*****',
|
|
7
|
+
// name: '*****',
|
|
8
|
+
// },
|
|
9
|
+
|
|
10
|
+
// 404 路由配置
|
|
11
|
+
{
|
|
12
|
+
path: '/:pathMatch(.*)*',
|
|
13
|
+
name: 'NotFound',
|
|
14
|
+
component: () => import('../views/NotFound.vue'),
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const router = createRouter({
|
|
19
|
+
history: createWebHashHistory(basename),
|
|
20
|
+
routes,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export default router;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
* {
|
|
2
|
+
margin: 0;
|
|
3
|
+
padding: 0;
|
|
4
|
+
box-sizing: border-box;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
ul {
|
|
8
|
+
list-style: none;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* 重置公共样式部分 */
|
|
12
|
+
.drawer-header-box {
|
|
13
|
+
padding: 0 !important;
|
|
14
|
+
margin: 0 !important;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.drawer-body-box {
|
|
18
|
+
padding: 0 !important;
|
|
19
|
+
margin: 0 !important;
|
|
20
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import vue from '@vitejs/plugin-vue';
|
|
3
|
+
const ProxyURL = process.env.VITE_API_BASE_URL;
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
base: './',
|
|
7
|
+
build: {
|
|
8
|
+
outDir: '../../dist/test',
|
|
9
|
+
emptyOutDir: true, // 清空输出目录
|
|
10
|
+
},
|
|
11
|
+
server: {
|
|
12
|
+
port: '6003',
|
|
13
|
+
open: false,
|
|
14
|
+
proxy: {
|
|
15
|
+
// 设置代理
|
|
16
|
+
'/finweb': {
|
|
17
|
+
target: ProxyURL,
|
|
18
|
+
changeOrigin: true,
|
|
19
|
+
rewrite: (path) => path.replace(/^\/finweb/, '/finweb'),
|
|
20
|
+
// 添加 CORS 头
|
|
21
|
+
configure: (proxy) => {
|
|
22
|
+
proxy.on('proxyRes', (proxyRes, req, res) => {
|
|
23
|
+
res.setHeader('Access-Control-Allow-Origin', req.headers.origin || '*');
|
|
24
|
+
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
cors: true,
|
|
30
|
+
},
|
|
31
|
+
resolve: {
|
|
32
|
+
dedupe: ['vue', 'pinia', 'element-plus'],
|
|
33
|
+
alias: {
|
|
34
|
+
'@': '/src',
|
|
35
|
+
'@hooks': '/src/hooks/index.js',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
plugins: [
|
|
39
|
+
vue({
|
|
40
|
+
script: {
|
|
41
|
+
defineModel: true,
|
|
42
|
+
propsDestructure: true,
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
],
|
|
46
|
+
css: {
|
|
47
|
+
preprocessorOptions: {
|
|
48
|
+
scss: {},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
package/bin/lib/const.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LOWEST_NODE_VERSION =
|
|
1
|
+
export const LOWEST_NODE_VERSION = '18.0.0'; // 最低的 node 版本
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
const LOG_TYPES = {
|
|
3
|
+
success: {
|
|
4
|
+
label: '成功',
|
|
5
|
+
bgColor: chalk.bgGreen,
|
|
6
|
+
textColor: chalk.green,
|
|
7
|
+
},
|
|
8
|
+
warning: {
|
|
9
|
+
label: '警告',
|
|
10
|
+
bgColor: chalk.bgYellow,
|
|
11
|
+
textColor: chalk.yellow,
|
|
12
|
+
},
|
|
13
|
+
error: {
|
|
14
|
+
label: '错误',
|
|
15
|
+
bgColor: chalk.bgRed,
|
|
16
|
+
textColor: chalk.red,
|
|
17
|
+
},
|
|
18
|
+
info: {
|
|
19
|
+
label: '信息',
|
|
20
|
+
bgColor: chalk.bgBlue,
|
|
21
|
+
textColor: chalk.blue,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export function log(type = 'info', message, customLabel) {
|
|
25
|
+
const config = LOG_TYPES[type] || LOG_TYPES.info;
|
|
26
|
+
const label = customLabel || config.label;
|
|
27
|
+
const badge = config.bgColor(label);
|
|
28
|
+
const text = config.textColor(message);
|
|
29
|
+
console.log(badge, text);
|
|
30
|
+
}
|
|
31
|
+
export const log_success = (msg, label) => log('success', msg, label);
|
|
32
|
+
export const log_warning = (msg, label) => log('warning', msg, label);
|
|
33
|
+
export const log_error = (msg, label) => log('error', msg, label);
|
|
34
|
+
export const log_info = (msg, label) => log('info', msg, label); // 保持向后兼容
|
|
35
|
+
export function printError(err, label) {
|
|
36
|
+
log_error(err instanceof Error ? err.message : err, label);
|
|
37
|
+
}
|
package/bin/lib/utils.js
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
// bin/lib/index.js
|
|
2
|
-
import { createRequire } from
|
|
3
|
-
import { fileURLToPath } from
|
|
4
|
-
import path from
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import path from 'path';
|
|
5
5
|
|
|
6
6
|
// 转换 URL 为系统路径
|
|
7
7
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
8
|
const __dirname = path.dirname(__filename);
|
|
9
9
|
|
|
10
10
|
// 计算项目根目录(假设该文件在 bin/lib/ 下)
|
|
11
|
-
export const projectRoot = path.resolve(__dirname,
|
|
11
|
+
export const projectRoot = path.resolve(__dirname, '../../');
|
|
12
12
|
|
|
13
13
|
// ES6 自定义 require 函数,用于读取 .json 文件信息
|
|
14
14
|
// import.meta.url 的路径基准点是 当前文件所在目录(即 bin/lib/index.js)
|
|
15
|
-
export const require = createRequire(projectRoot +
|
|
15
|
+
export const require = createRequire(projectRoot + '/');
|
|
16
|
+
|
|
17
|
+
// 初始化 TS 编译器
|
|
18
|
+
// require('ts-node').register({
|
|
19
|
+
// transpileOnly: true, // 禁用类型检查(提升性能)
|
|
20
|
+
// files: ['**/*.config.ts'], // 只编译配置文件
|
|
21
|
+
// compilerOptions: {
|
|
22
|
+
// moduleResolution: 'NodeNext',
|
|
23
|
+
// module: 'NodeNext',
|
|
24
|
+
// },
|
|
25
|
+
// });
|
|
26
|
+
// // 支持 .ts 扩展名注册 (针对旧版 Node)
|
|
27
|
+
// require.extensions['ts'] = function (module, filePath) {
|
|
28
|
+
// module._compile(require('fs').readFileSync(filePath, 'utf8'), filePath);
|
|
29
|
+
// };
|