@4399ywkf/cli 0.0.14 → 0.0.18
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/dist/cli.js +378 -219
- package/dist/templates.js +15 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -14,19 +14,78 @@ require('https');
|
|
|
14
14
|
|
|
15
15
|
var cli = {};
|
|
16
16
|
|
|
17
|
+
/** 暴露模版代码 */
|
|
18
|
+
|
|
19
|
+
var templates$1 = {
|
|
20
|
+
microFrontend: {
|
|
21
|
+
webpack: {
|
|
22
|
+
main: [
|
|
23
|
+
{
|
|
24
|
+
value: "https://ywgit.gz4399.com/ywkf/webpack-mainApplicate_demo.git",
|
|
25
|
+
name: "webpack-mainApplicate_demo",
|
|
26
|
+
description: "基于 Webpack 的微前端主应用模板",
|
|
27
|
+
features: ["qiankun", "react", "antd", "路由管理"],
|
|
28
|
+
recommended: true,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
sub: [
|
|
32
|
+
{
|
|
33
|
+
value: "https://ywgit.gz4399.com/ywkf/webpack-subApplicate_demo.git",
|
|
34
|
+
name: "webpack-subApplicate_demo",
|
|
35
|
+
description: "标准的微前端子应用模板",
|
|
36
|
+
features: ["react", "antd", "独立运行"],
|
|
37
|
+
recommended: true,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
vite: {
|
|
42
|
+
main: [
|
|
43
|
+
{
|
|
44
|
+
value: "https://ywgit.gz4399.com/ywkf/vite-mainApplicate_demo.git",
|
|
45
|
+
name: "vite-mainApplicate_demo",
|
|
46
|
+
description: "基于 Vite 的微前端主应用模板",
|
|
47
|
+
features: ["qiankun", "react", "antd", "路由管理"],
|
|
48
|
+
recommended: true,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
sub: [
|
|
52
|
+
{
|
|
53
|
+
value: "https://ywgit.gz4399.com/ywkf/vite-subApplicate_demo.git",
|
|
54
|
+
name: "vite-subApplicate_demo",
|
|
55
|
+
description: "标准的微前端子应用模板",
|
|
56
|
+
features: ["react", "antd", "独立运行"],
|
|
57
|
+
recommended: true,
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
standalone: {
|
|
63
|
+
nextjs: [
|
|
64
|
+
{
|
|
65
|
+
value: "https://ywgit.gz4399.com/ywkf/next-dome.git",
|
|
66
|
+
name: "next-demo",
|
|
67
|
+
description: "基于 Next.js 的全栈应用模板",
|
|
68
|
+
features: ["react", "antd", "next", "路由管理"],
|
|
69
|
+
recommended: true,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
17
75
|
const program = require$$0;
|
|
18
76
|
const inquirer = require$$1;
|
|
19
77
|
const path = require$$2;
|
|
20
78
|
const ora = require$$3;
|
|
21
79
|
const fs = require$$4;
|
|
22
80
|
const { exec } = require$$5;
|
|
81
|
+
const templates = templates$1;
|
|
23
82
|
|
|
24
83
|
// 美化输出相关
|
|
25
84
|
const chalk = require$$7;
|
|
26
85
|
const boxen = require$$8;
|
|
27
86
|
const figlet = require$$9;
|
|
28
87
|
const pkgInfo = {
|
|
29
|
-
version: "0.0.
|
|
88
|
+
version: "0.0.18",
|
|
30
89
|
};
|
|
31
90
|
|
|
32
91
|
// 美化输出函数
|
|
@@ -60,31 +119,44 @@ function printWarning(message) {
|
|
|
60
119
|
}
|
|
61
120
|
|
|
62
121
|
function printFinalInstructions(projectName) {
|
|
63
|
-
|
|
64
|
-
chalk.green("🎉 项目创建成功!"),
|
|
65
|
-
"",
|
|
66
|
-
chalk.cyan("接下来的步骤:"),
|
|
67
|
-
chalk.gray(" 1. 进入项目目录"),
|
|
68
|
-
chalk.white(` cd ${projectName}`),
|
|
69
|
-
chalk.gray(" 2. 切换Node版本"),
|
|
70
|
-
chalk.white(" nvm use"),
|
|
71
|
-
chalk.gray(" 3. 安装依赖"),
|
|
72
|
-
chalk.white(" pnpm i"),
|
|
73
|
-
chalk.gray(" 4. 启动项目"),
|
|
74
|
-
chalk.white(" pnpm start"),
|
|
75
|
-
"",
|
|
76
|
-
chalk.magenta("🚀 开始你的开发之旅吧!"),
|
|
77
|
-
].join("\n");
|
|
78
|
-
|
|
122
|
+
console.log();
|
|
79
123
|
console.log(
|
|
80
|
-
boxen(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
124
|
+
boxen(
|
|
125
|
+
[
|
|
126
|
+
chalk.green.bold("🎉 项目创建成功!"),
|
|
127
|
+
"",
|
|
128
|
+
chalk.yellow("📂 项目路径:") + chalk.cyan(projectName),
|
|
129
|
+
"",
|
|
130
|
+
chalk.yellow("🚀 下一步:"),
|
|
131
|
+
chalk.white(` cd ${projectName}`),
|
|
132
|
+
chalk.white(" npm install # 或 pnpm install"),
|
|
133
|
+
chalk.white(" npm run dev # 启动开发服务器"),
|
|
134
|
+
"",
|
|
135
|
+
chalk.gray("💡 提示:"),
|
|
136
|
+
chalk.gray(" - 查看 README.md 了解更多信息"),
|
|
137
|
+
chalk.gray(" - 检查 package.json 中的可用脚本"),
|
|
138
|
+
chalk.gray(" - 访问内部文档了解最佳实践"),
|
|
139
|
+
].join("\n"),
|
|
140
|
+
{
|
|
141
|
+
padding: 1,
|
|
142
|
+
margin: 1,
|
|
143
|
+
borderStyle: "round",
|
|
144
|
+
borderColor: "green",
|
|
145
|
+
}
|
|
146
|
+
)
|
|
87
147
|
);
|
|
148
|
+
|
|
149
|
+
// 根据项目类型提供特定建议
|
|
150
|
+
if (architectureType === "microFrontend") {
|
|
151
|
+
console.log(chalk.blue("🔗 微前端相关:"));
|
|
152
|
+
if (appDirection === "main") {
|
|
153
|
+
console.log(chalk.gray(" - 配置子应用注册信息"));
|
|
154
|
+
console.log(chalk.gray(" - 设置路由规则"));
|
|
155
|
+
} else {
|
|
156
|
+
console.log(chalk.gray(" - 确认子应用配置正确"));
|
|
157
|
+
console.log(chalk.gray(" - 测试独立运行"));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
88
160
|
}
|
|
89
161
|
|
|
90
162
|
function cloneRepository(repoUrl, destination) {
|
|
@@ -256,33 +328,19 @@ async function configureWebpackSubApp(projectPath, projectName) {
|
|
|
256
328
|
}
|
|
257
329
|
}
|
|
258
330
|
|
|
331
|
+
// 支持无参数创建(在当前目录)
|
|
259
332
|
program
|
|
260
|
-
.command("create [
|
|
261
|
-
.description("
|
|
262
|
-
.option("-t, --template <template>", "
|
|
333
|
+
.command("create [project-name]") // 使project-name可选
|
|
334
|
+
.description("创建新项目")
|
|
335
|
+
.option("-t, --template <template>", "指定模版")
|
|
263
336
|
.action(async (projectName, options) => {
|
|
264
|
-
//
|
|
265
|
-
printBanner();
|
|
266
|
-
|
|
267
|
-
const getRepoLoading = ora({
|
|
268
|
-
text: "正在获取模版列表...",
|
|
269
|
-
spinner: "dots",
|
|
270
|
-
});
|
|
271
|
-
getRepoLoading.start();
|
|
272
|
-
|
|
273
|
-
// 模拟异步获取模版数据
|
|
274
|
-
const templates = templates;
|
|
275
|
-
|
|
276
|
-
getRepoLoading.succeed();
|
|
277
|
-
printSuccess("模版列表获取成功!");
|
|
278
|
-
console.log(); // 空行
|
|
279
|
-
|
|
280
|
-
// 1. 如果用户没有传入名称就交互式输入
|
|
337
|
+
// 如果没有提供项目名,询问用户
|
|
281
338
|
if (!projectName) {
|
|
282
339
|
const { name } = await inquirer.prompt({
|
|
283
340
|
type: "input",
|
|
284
341
|
name: "name",
|
|
285
342
|
message: chalk.cyan("📝 请输入项目名称:"),
|
|
343
|
+
default: "my-project",
|
|
286
344
|
validate: (input) => {
|
|
287
345
|
if (!input.trim()) {
|
|
288
346
|
return "项目名称不能为空!";
|
|
@@ -294,218 +352,319 @@ program
|
|
|
294
352
|
}
|
|
295
353
|
printInfo(`项目名称:${chalk.bold(projectName)}`);
|
|
296
354
|
|
|
297
|
-
//
|
|
298
|
-
const {
|
|
299
|
-
type: "
|
|
300
|
-
name: "
|
|
301
|
-
message: chalk.cyan("
|
|
302
|
-
|
|
303
|
-
{
|
|
304
|
-
name: `${chalk.blue("🧩 微前端架构")} - 支持主应用和子应用`,
|
|
305
|
-
value: "microFrontend",
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
name: `${chalk.green("📱 独立应用")} - 单体应用架构`,
|
|
309
|
-
value: "standalone",
|
|
310
|
-
},
|
|
311
|
-
],
|
|
355
|
+
// 添加预设选择(移到这里)
|
|
356
|
+
const { usePreset } = await inquirer.prompt({
|
|
357
|
+
type: "confirm",
|
|
358
|
+
name: "usePreset",
|
|
359
|
+
message: chalk.cyan("🎯 是否使用推荐预设?"),
|
|
360
|
+
default: true,
|
|
312
361
|
});
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
let projectTemplate;
|
|
320
|
-
let toolType, appDirection;
|
|
321
|
-
|
|
322
|
-
if (architectureType === "microFrontend") {
|
|
323
|
-
// 微前端架构流程
|
|
324
|
-
// 3. 选择工具类型
|
|
325
|
-
const toolTypeResult = await inquirer.prompt({
|
|
362
|
+
|
|
363
|
+
let architectureType, toolType, appDirection;
|
|
364
|
+
|
|
365
|
+
if (usePreset) {
|
|
366
|
+
// 预设选择逻辑
|
|
367
|
+
const { preset } = await inquirer.prompt({
|
|
326
368
|
type: "list",
|
|
327
|
-
name: "
|
|
328
|
-
message: chalk.cyan("
|
|
369
|
+
name: "preset",
|
|
370
|
+
message: chalk.cyan("📋 请选择预设:"),
|
|
329
371
|
choices: [
|
|
330
372
|
{
|
|
331
|
-
name: `${chalk.blue("
|
|
332
|
-
value:
|
|
373
|
+
name: `${chalk.blue("🏠 Webpack 主应用")} - 企业级微前端主应用`,
|
|
374
|
+
value: {
|
|
375
|
+
architecture: "microFrontend",
|
|
376
|
+
tool: "webpack",
|
|
377
|
+
direction: "main",
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
name: `${chalk.green("🧩 Webpack 子应用")} - 业务子应用`,
|
|
382
|
+
value: {
|
|
383
|
+
architecture: "microFrontend",
|
|
384
|
+
tool: "webpack",
|
|
385
|
+
direction: "sub",
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
name: `${chalk.purple("⚡ Vite 主应用")} - 高性能微前端主应用`,
|
|
390
|
+
value: {
|
|
391
|
+
architecture: "microFrontend",
|
|
392
|
+
tool: "vite",
|
|
393
|
+
direction: "main",
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
name: `${chalk.yellow("📱 Next.js 应用")} - 全栈应用`,
|
|
398
|
+
value: { architecture: "standalone", framework: "nextjs" },
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
name: `${chalk.gray("⚙️ 自定义配置")} - 手动选择所有选项`,
|
|
402
|
+
value: null,
|
|
333
403
|
},
|
|
334
|
-
{ name: `${chalk.green("⚡ Vite")} - 快速的构建工具`, value: "vite" },
|
|
335
404
|
],
|
|
336
405
|
});
|
|
337
|
-
toolType = toolTypeResult.toolType;
|
|
338
|
-
printInfo(`工具类型:${chalk.bold(toolType)}`);
|
|
339
406
|
|
|
340
|
-
|
|
341
|
-
|
|
407
|
+
if (preset) {
|
|
408
|
+
architectureType = preset.architecture;
|
|
409
|
+
toolType = preset.tool;
|
|
410
|
+
appDirection = preset.direction;
|
|
411
|
+
printSuccess(`使用预设:${chalk.bold("快速配置")}`);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// 如果没有使用预设,或者选择了自定义配置,继续原有的选择流程
|
|
416
|
+
if (!usePreset || !preset) {
|
|
417
|
+
// 2. 选择架构类型
|
|
418
|
+
const { architectureType: selectedArchitecture } = await inquirer.prompt({
|
|
342
419
|
type: "list",
|
|
343
|
-
name: "
|
|
344
|
-
message: chalk.cyan("
|
|
420
|
+
name: "architectureType",
|
|
421
|
+
message: chalk.cyan("🏗️ 请选择架构类型:"),
|
|
345
422
|
choices: [
|
|
346
423
|
{
|
|
347
|
-
name: `${chalk.
|
|
348
|
-
value: "
|
|
424
|
+
name: `${chalk.blue("🧩 微前端架构")} - 支持主应用和子应用`,
|
|
425
|
+
value: "microFrontend",
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
name: `${chalk.green("📱 独立应用")} - 单体应用架构`,
|
|
429
|
+
value: "standalone",
|
|
349
430
|
},
|
|
350
|
-
{ name: `${chalk.yellow("🧩 子应用")} - 微前端子应用`, value: "sub" },
|
|
351
431
|
],
|
|
352
432
|
});
|
|
353
|
-
|
|
433
|
+
architectureType = selectedArchitecture;
|
|
354
434
|
printInfo(
|
|
355
|
-
|
|
435
|
+
`架构类型:${chalk.bold(
|
|
436
|
+
architectureType === "microFrontend" ? "微前端架构" : "独立应用"
|
|
437
|
+
)}`
|
|
356
438
|
);
|
|
357
439
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
440
|
+
let projectTemplate;
|
|
441
|
+
|
|
442
|
+
if (architectureType === "microFrontend") {
|
|
443
|
+
// 微前端架构流程
|
|
444
|
+
// 3. 选择工具类型
|
|
445
|
+
const toolTypeResult = await inquirer.prompt({
|
|
446
|
+
type: "list",
|
|
447
|
+
name: "toolType",
|
|
448
|
+
message: chalk.cyan("🔧 请选择工具类型:"),
|
|
449
|
+
choices: [
|
|
450
|
+
{
|
|
451
|
+
name: `${chalk.blue("📦 Webpack")} - 成熟稳定的打包工具`,
|
|
452
|
+
value: "webpack",
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
name: `${chalk.green("⚡ Vite")} - 快速的构建工具`,
|
|
456
|
+
value: "vite",
|
|
457
|
+
},
|
|
458
|
+
],
|
|
459
|
+
});
|
|
460
|
+
toolType = toolTypeResult.toolType;
|
|
461
|
+
printInfo(`工具类型:${chalk.bold(toolType)}`);
|
|
462
|
+
|
|
463
|
+
// 4. 选择应用方向
|
|
464
|
+
const appDirectionResult = await inquirer.prompt({
|
|
465
|
+
type: "list",
|
|
466
|
+
name: "appDirection",
|
|
467
|
+
message: chalk.cyan("🎯 请选择应用方向:"),
|
|
468
|
+
choices: [
|
|
469
|
+
{
|
|
470
|
+
name: `${chalk.magenta("🏠 主应用")} - 微前端主应用`,
|
|
471
|
+
value: "main",
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
name: `${chalk.yellow("🧩 子应用")} - 微前端子应用`,
|
|
475
|
+
value: "sub",
|
|
476
|
+
},
|
|
477
|
+
],
|
|
478
|
+
});
|
|
479
|
+
appDirection = appDirectionResult.appDirection;
|
|
480
|
+
printInfo(
|
|
481
|
+
`应用方向:${chalk.bold(
|
|
482
|
+
appDirection === "main" ? "主应用" : "子应用"
|
|
483
|
+
)}`
|
|
484
|
+
);
|
|
370
485
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
templates.microFrontend[toolType][
|
|
486
|
+
// 5. 选择模版
|
|
487
|
+
if (options.template) {
|
|
488
|
+
const foundTemplate = templates.microFrontend[toolType][
|
|
489
|
+
appDirection
|
|
490
|
+
].find((template) => template.name === options.template);
|
|
491
|
+
if (foundTemplate) {
|
|
492
|
+
projectTemplate = foundTemplate.value;
|
|
493
|
+
printSuccess(`使用指定模版:${chalk.bold(options.template)}`);
|
|
494
|
+
} else {
|
|
495
|
+
printWarning(`未找到指定模版 "${options.template}",请重新选择`);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
374
498
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
//
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
499
|
+
if (!projectTemplate) {
|
|
500
|
+
const availableTemplates =
|
|
501
|
+
templates.microFrontend[toolType][appDirection];
|
|
502
|
+
|
|
503
|
+
// 如果只有一个模版,直接使用它
|
|
504
|
+
if (availableTemplates.length === 1) {
|
|
505
|
+
projectTemplate = availableTemplates[0].value;
|
|
506
|
+
} else {
|
|
507
|
+
// 多个模版时让用户选择
|
|
508
|
+
const { template } = await inquirer.prompt({
|
|
509
|
+
type: "list",
|
|
510
|
+
name: "template",
|
|
511
|
+
message: chalk.cyan("📋 请选择模版:"),
|
|
512
|
+
choices: availableTemplates.map((t) => ({
|
|
513
|
+
name: [
|
|
514
|
+
`${t.recommended ? chalk.green("⭐") : " "} ${chalk.white(
|
|
515
|
+
t.name
|
|
516
|
+
)}`,
|
|
517
|
+
` ${chalk.gray(t.description)}`,
|
|
518
|
+
` ${chalk.blue(`特性: ${t.features.join(", ")}`)}`,
|
|
519
|
+
].join("\n"),
|
|
520
|
+
value: t.value,
|
|
521
|
+
short: t.name,
|
|
522
|
+
})),
|
|
523
|
+
pageSize: 10,
|
|
524
|
+
});
|
|
525
|
+
projectTemplate = template;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
} else {
|
|
529
|
+
// 独立应用架构流程
|
|
530
|
+
// 3. 选择框架类型
|
|
531
|
+
const { frameworkType } = await inquirer.prompt({
|
|
532
|
+
type: "list",
|
|
533
|
+
name: "frameworkType",
|
|
534
|
+
message: chalk.cyan("⚛️ 请选择框架类型:"),
|
|
535
|
+
default: "nextjs",
|
|
536
|
+
choices: [
|
|
537
|
+
{
|
|
538
|
+
name: `${chalk.black("▲")} ${chalk.white(
|
|
539
|
+
"Next.js"
|
|
540
|
+
)} - React 全栈框架`,
|
|
541
|
+
value: "nextjs",
|
|
542
|
+
},
|
|
543
|
+
// 可以在这里添加更多独立应用框架
|
|
544
|
+
],
|
|
545
|
+
});
|
|
546
|
+
printInfo(`框架类型:${chalk.bold(frameworkType)}`);
|
|
547
|
+
|
|
548
|
+
// 4. 选择模版
|
|
549
|
+
if (options.template) {
|
|
550
|
+
const foundTemplate = templates.standalone[frameworkType].find(
|
|
551
|
+
(template) => template.name === options.template
|
|
552
|
+
);
|
|
553
|
+
if (foundTemplate) {
|
|
554
|
+
projectTemplate = foundTemplate.value;
|
|
555
|
+
printSuccess(`使用指定模版:${chalk.bold(options.template)}`);
|
|
556
|
+
} else {
|
|
557
|
+
printWarning(`未找到指定模版 "${options.template}",请重新选择`);
|
|
558
|
+
}
|
|
390
559
|
}
|
|
391
|
-
}
|
|
392
|
-
} else {
|
|
393
|
-
// 独立应用架构流程
|
|
394
|
-
// 3. 选择框架类型
|
|
395
|
-
const { frameworkType } = await inquirer.prompt({
|
|
396
|
-
type: "list",
|
|
397
|
-
name: "frameworkType",
|
|
398
|
-
message: chalk.cyan("⚛️ 请选择框架类型:"),
|
|
399
|
-
default: "nextjs",
|
|
400
|
-
choices: [
|
|
401
|
-
{
|
|
402
|
-
name: `${chalk.black("▲")} ${chalk.white(
|
|
403
|
-
"Next.js"
|
|
404
|
-
)} - React 全栈框架`,
|
|
405
|
-
value: "nextjs",
|
|
406
|
-
},
|
|
407
|
-
// 可以在这里添加更多独立应用框架
|
|
408
|
-
],
|
|
409
|
-
});
|
|
410
|
-
printInfo(`框架类型:${chalk.bold(frameworkType)}`);
|
|
411
560
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
561
|
+
if (!projectTemplate) {
|
|
562
|
+
const availableTemplates = templates.standalone[frameworkType];
|
|
563
|
+
|
|
564
|
+
// 如果只有一个模版,直接使用它
|
|
565
|
+
if (availableTemplates.length === 1) {
|
|
566
|
+
projectTemplate = availableTemplates[0].value;
|
|
567
|
+
printInfo(`使用模版:${chalk.bold(availableTemplates[0].name)}`);
|
|
568
|
+
} else {
|
|
569
|
+
// 多个模版时让用户选择
|
|
570
|
+
const { template } = await inquirer.prompt({
|
|
571
|
+
type: "list",
|
|
572
|
+
name: "template",
|
|
573
|
+
message: chalk.cyan("📋 请选择模版:"),
|
|
574
|
+
choices: availableTemplates.map((t) => ({
|
|
575
|
+
name: `${chalk.white(t.name)}`,
|
|
576
|
+
value: t.value,
|
|
577
|
+
})),
|
|
578
|
+
});
|
|
579
|
+
projectTemplate = template;
|
|
580
|
+
}
|
|
422
581
|
}
|
|
423
582
|
}
|
|
424
583
|
|
|
425
|
-
|
|
426
|
-
const availableTemplates = templates.standalone[frameworkType];
|
|
584
|
+
console.log(); // 空行
|
|
427
585
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
586
|
+
// 获取目标文件夹路径
|
|
587
|
+
const dest = path.join(process.cwd(), projectName);
|
|
588
|
+
// 判断文件夹是否存在,存在就交互询问用户是否覆盖
|
|
589
|
+
if (fs.existsSync(dest)) {
|
|
590
|
+
printWarning(`目录 "${projectName}" 已存在!`);
|
|
591
|
+
const { force } = await inquirer.prompt({
|
|
592
|
+
type: "confirm",
|
|
593
|
+
name: "force",
|
|
594
|
+
message: chalk.yellow("⚠️ 是否覆盖现有目录?"),
|
|
595
|
+
default: false,
|
|
596
|
+
});
|
|
597
|
+
if (force) {
|
|
598
|
+
fs.removeSync(dest);
|
|
599
|
+
printSuccess("已删除现有目录");
|
|
432
600
|
} else {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
type: "list",
|
|
436
|
-
name: "template",
|
|
437
|
-
message: chalk.cyan("📋 请选择模版:"),
|
|
438
|
-
choices: availableTemplates.map((t) => ({
|
|
439
|
-
name: `${chalk.white(t.name)}`,
|
|
440
|
-
value: t.value,
|
|
441
|
-
})),
|
|
442
|
-
});
|
|
443
|
-
projectTemplate = template;
|
|
601
|
+
printInfo("操作已取消");
|
|
602
|
+
process.exit(1);
|
|
444
603
|
}
|
|
445
604
|
}
|
|
446
|
-
}
|
|
447
605
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
// 判断文件夹是否存在,存在就交互询问用户是否覆盖
|
|
453
|
-
if (fs.existsSync(dest)) {
|
|
454
|
-
printWarning(`目录 "${projectName}" 已存在!`);
|
|
455
|
-
const { force } = await inquirer.prompt({
|
|
456
|
-
type: "confirm",
|
|
457
|
-
name: "force",
|
|
458
|
-
message: chalk.yellow("⚠️ 是否覆盖现有目录?"),
|
|
459
|
-
default: false,
|
|
606
|
+
// 开始loading
|
|
607
|
+
const loading = ora({
|
|
608
|
+
text: "正在下载模版...",
|
|
609
|
+
spinner: "bouncingBar",
|
|
460
610
|
});
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
611
|
+
loading.start();
|
|
612
|
+
|
|
613
|
+
// 6. 开始下载模版
|
|
614
|
+
try {
|
|
615
|
+
const result = await cloneRepository(projectTemplate, dest);
|
|
616
|
+
loading.succeed();
|
|
617
|
+
printSuccess("模版下载成功!");
|
|
618
|
+
|
|
619
|
+
// 删除.git文件夹
|
|
620
|
+
const gitDir = path.join(dest, ".git");
|
|
621
|
+
if (fs.existsSync(gitDir)) {
|
|
622
|
+
fs.removeSync(gitDir);
|
|
623
|
+
printSuccess("已清理 .git 文件夹");
|
|
624
|
+
}
|
|
469
625
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
const result = await cloneRepository(projectTemplate, dest);
|
|
480
|
-
loading.succeed();
|
|
481
|
-
printSuccess("模版下载成功!");
|
|
482
|
-
|
|
483
|
-
// 删除.git文件夹
|
|
484
|
-
const gitDir = path.join(dest, ".git");
|
|
485
|
-
if (fs.existsSync(gitDir)) {
|
|
486
|
-
fs.removeSync(gitDir);
|
|
487
|
-
printSuccess("已清理 .git 文件夹");
|
|
488
|
-
}
|
|
626
|
+
// 新添加:如果是 webpack 子应用,进行环境配置
|
|
627
|
+
if (
|
|
628
|
+
architectureType === "microFrontend" &&
|
|
629
|
+
toolType === "webpack" &&
|
|
630
|
+
appDirection === "sub"
|
|
631
|
+
) {
|
|
632
|
+
console.log(); // 空行
|
|
633
|
+
await configureWebpackSubApp(dest, projectName);
|
|
634
|
+
}
|
|
489
635
|
|
|
490
|
-
// 新添加:如果是 webpack 子应用,进行环境配置
|
|
491
|
-
if (
|
|
492
|
-
architectureType === "microFrontend" &&
|
|
493
|
-
toolType === "webpack" &&
|
|
494
|
-
appDirection === "sub"
|
|
495
|
-
) {
|
|
496
636
|
console.log(); // 空行
|
|
497
|
-
|
|
637
|
+
printFinalInstructions(projectName);
|
|
638
|
+
} catch (error) {
|
|
639
|
+
loading.fail();
|
|
640
|
+
printError("模版下载失败:" + error);
|
|
641
|
+
process.exit(1);
|
|
498
642
|
}
|
|
499
|
-
|
|
500
|
-
console.log(); // 空行
|
|
501
|
-
printFinalInstructions(projectName);
|
|
502
|
-
} catch (error) {
|
|
503
|
-
loading.fail();
|
|
504
|
-
printError("模版下载失败:" + error);
|
|
505
|
-
process.exit(1);
|
|
506
643
|
}
|
|
507
644
|
});
|
|
508
645
|
|
|
646
|
+
// 在环境配置前添加说明
|
|
647
|
+
console.log();
|
|
648
|
+
console.log(
|
|
649
|
+
boxen(
|
|
650
|
+
[
|
|
651
|
+
chalk.blue.bold("🔧 环境配置"),
|
|
652
|
+
"",
|
|
653
|
+
chalk.gray("接下来将配置应用的基本信息:"),
|
|
654
|
+
chalk.gray("• 应用名称 - 用于标识和显示"),
|
|
655
|
+
chalk.gray("• 构建配置 - 输出路径和公共路径"),
|
|
656
|
+
chalk.gray("• 监控配置 - Sentry 错误监控(可选)"),
|
|
657
|
+
"",
|
|
658
|
+
chalk.yellow("💡 提示:所有配置后续都可以在代码中修改"),
|
|
659
|
+
].join("\n"),
|
|
660
|
+
{
|
|
661
|
+
padding: 1,
|
|
662
|
+
borderStyle: "round",
|
|
663
|
+
borderColor: "blue",
|
|
664
|
+
}
|
|
665
|
+
)
|
|
666
|
+
);
|
|
667
|
+
|
|
509
668
|
// 定义当前版本
|
|
510
669
|
program.version(`v${pkgInfo.version}`);
|
|
511
670
|
program.on("--help", () => {
|
package/dist/templates.js
CHANGED
|
@@ -13,12 +13,18 @@ var templates = {
|
|
|
13
13
|
{
|
|
14
14
|
value: "https://ywgit.gz4399.com/ywkf/webpack-mainApplicate_demo.git",
|
|
15
15
|
name: "webpack-mainApplicate_demo",
|
|
16
|
+
description: "基于 Webpack 的微前端主应用模板",
|
|
17
|
+
features: ["qiankun", "react", "antd", "路由管理"],
|
|
18
|
+
recommended: true,
|
|
16
19
|
},
|
|
17
20
|
],
|
|
18
21
|
sub: [
|
|
19
22
|
{
|
|
20
23
|
value: "https://ywgit.gz4399.com/ywkf/webpack-subApplicate_demo.git",
|
|
21
24
|
name: "webpack-subApplicate_demo",
|
|
25
|
+
description: "标准的微前端子应用模板",
|
|
26
|
+
features: ["react", "antd", "独立运行"],
|
|
27
|
+
recommended: true,
|
|
22
28
|
},
|
|
23
29
|
],
|
|
24
30
|
},
|
|
@@ -27,12 +33,18 @@ var templates = {
|
|
|
27
33
|
{
|
|
28
34
|
value: "https://ywgit.gz4399.com/ywkf/vite-mainApplicate_demo.git",
|
|
29
35
|
name: "vite-mainApplicate_demo",
|
|
36
|
+
description: "基于 Vite 的微前端主应用模板",
|
|
37
|
+
features: ["qiankun", "react", "antd", "路由管理"],
|
|
38
|
+
recommended: true,
|
|
30
39
|
},
|
|
31
40
|
],
|
|
32
41
|
sub: [
|
|
33
42
|
{
|
|
34
43
|
value: "https://ywgit.gz4399.com/ywkf/vite-subApplicate_demo.git",
|
|
35
44
|
name: "vite-subApplicate_demo",
|
|
45
|
+
description: "标准的微前端子应用模板",
|
|
46
|
+
features: ["react", "antd", "独立运行"],
|
|
47
|
+
recommended: true,
|
|
36
48
|
},
|
|
37
49
|
],
|
|
38
50
|
},
|
|
@@ -42,6 +54,9 @@ var templates = {
|
|
|
42
54
|
{
|
|
43
55
|
value: "https://ywgit.gz4399.com/ywkf/next-dome.git",
|
|
44
56
|
name: "next-demo",
|
|
57
|
+
description: "基于 Next.js 的全栈应用模板",
|
|
58
|
+
features: ["react", "antd", "next", "路由管理"],
|
|
59
|
+
recommended: true,
|
|
45
60
|
},
|
|
46
61
|
],
|
|
47
62
|
},
|