@4399ywkf/cli 0.0.18 → 0.0.20
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 +186 -252
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -85,7 +85,7 @@ const chalk = require$$7;
|
|
|
85
85
|
const boxen = require$$8;
|
|
86
86
|
const figlet = require$$9;
|
|
87
87
|
const pkgInfo = {
|
|
88
|
-
version: "0.0.
|
|
88
|
+
version: "0.0.20",
|
|
89
89
|
};
|
|
90
90
|
|
|
91
91
|
// 美化输出函数
|
|
@@ -118,7 +118,7 @@ function printWarning(message) {
|
|
|
118
118
|
console.log(chalk.yellow("⚠️ " + message));
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
function printFinalInstructions(projectName) {
|
|
121
|
+
function printFinalInstructions(projectName, architectureType, appDirection) {
|
|
122
122
|
console.log();
|
|
123
123
|
console.log(
|
|
124
124
|
boxen(
|
|
@@ -352,294 +352,228 @@ program
|
|
|
352
352
|
}
|
|
353
353
|
printInfo(`项目名称:${chalk.bold(projectName)}`);
|
|
354
354
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
355
|
+
const { architectureType } = await inquirer.prompt({
|
|
356
|
+
type: "list",
|
|
357
|
+
name: "architectureType",
|
|
358
|
+
message: chalk.cyan("🏗️ 请选择架构类型:"),
|
|
359
|
+
choices: [
|
|
360
|
+
{
|
|
361
|
+
name: `${chalk.blue("🧩 微前端架构")} - 支持主应用和子应用`,
|
|
362
|
+
value: "microFrontend",
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
name: `${chalk.green("📱 独立应用")} - 单体应用架构`,
|
|
366
|
+
value: "standalone",
|
|
367
|
+
},
|
|
368
|
+
],
|
|
361
369
|
});
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
370
|
+
printInfo(
|
|
371
|
+
`架构类型:${chalk.bold(
|
|
372
|
+
architectureType === "microFrontend" ? "微前端架构" : "独立应用"
|
|
373
|
+
)}`
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
let projectTemplate, toolType, appDirection;
|
|
377
|
+
|
|
378
|
+
if (architectureType === "microFrontend") {
|
|
379
|
+
// 微前端架构流程
|
|
380
|
+
// 3. 选择工具类型
|
|
381
|
+
const { toolType: toolTypeResult } = await inquirer.prompt({
|
|
368
382
|
type: "list",
|
|
369
|
-
name: "
|
|
370
|
-
message: chalk.cyan("
|
|
383
|
+
name: "toolType",
|
|
384
|
+
message: chalk.cyan("🔧 请选择工具类型:"),
|
|
371
385
|
choices: [
|
|
372
386
|
{
|
|
373
|
-
name: `${chalk.blue("
|
|
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" },
|
|
387
|
+
name: `${chalk.blue("📦 Webpack")} - 成熟稳定的打包工具`,
|
|
388
|
+
value: "webpack",
|
|
399
389
|
},
|
|
400
390
|
{
|
|
401
|
-
name: `${chalk.
|
|
402
|
-
value:
|
|
391
|
+
name: `${chalk.green("⚡ Vite")} - 快速的构建工具`,
|
|
392
|
+
value: "vite",
|
|
403
393
|
},
|
|
404
394
|
],
|
|
405
395
|
});
|
|
396
|
+
toolType = toolTypeResult;
|
|
397
|
+
printInfo(`工具类型:${chalk.bold(toolType)}`);
|
|
406
398
|
|
|
407
|
-
|
|
408
|
-
|
|
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({
|
|
399
|
+
// 4. 选择应用方向
|
|
400
|
+
const { appDirection: appDirectionResult } = await inquirer.prompt({
|
|
419
401
|
type: "list",
|
|
420
|
-
name: "
|
|
421
|
-
message: chalk.cyan("
|
|
402
|
+
name: "appDirection",
|
|
403
|
+
message: chalk.cyan("🎯 请选择应用方向:"),
|
|
422
404
|
choices: [
|
|
423
405
|
{
|
|
424
|
-
name: `${chalk.
|
|
425
|
-
value: "
|
|
406
|
+
name: `${chalk.magenta("🏠 主应用")} - 微前端主应用`,
|
|
407
|
+
value: "main",
|
|
426
408
|
},
|
|
427
409
|
{
|
|
428
|
-
name: `${chalk.
|
|
429
|
-
value: "
|
|
410
|
+
name: `${chalk.yellow("🧩 子应用")} - 微前端子应用`,
|
|
411
|
+
value: "sub",
|
|
430
412
|
},
|
|
431
413
|
],
|
|
432
414
|
});
|
|
433
|
-
|
|
415
|
+
appDirection = appDirectionResult;
|
|
416
|
+
|
|
434
417
|
printInfo(
|
|
435
|
-
|
|
436
|
-
architectureType === "microFrontend" ? "微前端架构" : "独立应用"
|
|
437
|
-
)}`
|
|
418
|
+
`应用方向:${chalk.bold(appDirection === "main" ? "主应用" : "子应用")}`
|
|
438
419
|
);
|
|
439
420
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
-
);
|
|
485
|
-
|
|
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
|
-
}
|
|
421
|
+
// 5. 选择模版
|
|
422
|
+
if (options.template) {
|
|
423
|
+
const foundTemplate = templates.microFrontend[toolType][
|
|
424
|
+
appDirection
|
|
425
|
+
].find((template) => template.name === options.template);
|
|
426
|
+
if (foundTemplate) {
|
|
427
|
+
projectTemplate = foundTemplate.value;
|
|
428
|
+
printSuccess(`使用指定模版:${chalk.bold(options.template)}`);
|
|
429
|
+
} else {
|
|
430
|
+
printWarning(`未找到指定模版 "${options.template}",请重新选择`);
|
|
497
431
|
}
|
|
432
|
+
}
|
|
498
433
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
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
|
-
}
|
|
434
|
+
if (!projectTemplate) {
|
|
435
|
+
const availableTemplates =
|
|
436
|
+
templates.microFrontend[toolType][appDirection];
|
|
437
|
+
|
|
438
|
+
// 如果只有一个模版,直接使用它
|
|
439
|
+
if (availableTemplates.length === 1) {
|
|
440
|
+
projectTemplate = availableTemplates[0].value;
|
|
441
|
+
} else {
|
|
442
|
+
// 多个模版时让用户选择
|
|
443
|
+
const { template } = await inquirer.prompt({
|
|
444
|
+
type: "list",
|
|
445
|
+
name: "template",
|
|
446
|
+
message: chalk.cyan("📋 请选择模版:"),
|
|
447
|
+
choices: availableTemplates.map((t) => ({
|
|
448
|
+
name: [
|
|
449
|
+
`${t.recommended ? chalk.green("⭐") : " "} ${chalk.white(
|
|
450
|
+
t.name
|
|
451
|
+
)}`,
|
|
452
|
+
` ${chalk.gray(t.description)}`,
|
|
453
|
+
` ${chalk.blue(`特性: ${t.features.join(", ")}`)}`,
|
|
454
|
+
].join("\n"),
|
|
455
|
+
value: t.value,
|
|
456
|
+
short: t.name,
|
|
457
|
+
})),
|
|
458
|
+
pageSize: 10,
|
|
459
|
+
});
|
|
460
|
+
projectTemplate = template;
|
|
559
461
|
}
|
|
462
|
+
}
|
|
463
|
+
} else {
|
|
464
|
+
// 独立应用架构流程
|
|
465
|
+
// 3. 选择框架类型
|
|
466
|
+
const { frameworkType } = await inquirer.prompt({
|
|
467
|
+
type: "list",
|
|
468
|
+
name: "frameworkType",
|
|
469
|
+
message: chalk.cyan("⚛️ 请选择框架类型:"),
|
|
470
|
+
default: "nextjs",
|
|
471
|
+
choices: [
|
|
472
|
+
{
|
|
473
|
+
name: `${chalk.black("▲")} ${chalk.white(
|
|
474
|
+
"Next.js"
|
|
475
|
+
)} - React 全栈框架`,
|
|
476
|
+
value: "nextjs",
|
|
477
|
+
},
|
|
478
|
+
// 可以在这里添加更多独立应用框架
|
|
479
|
+
],
|
|
480
|
+
});
|
|
481
|
+
printInfo(`框架类型:${chalk.bold(frameworkType)}`);
|
|
560
482
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
|
|
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
|
-
}
|
|
483
|
+
// 4. 选择模版
|
|
484
|
+
if (options.template) {
|
|
485
|
+
const foundTemplate = templates.standalone[frameworkType].find(
|
|
486
|
+
(template) => template.name === options.template
|
|
487
|
+
);
|
|
488
|
+
if (foundTemplate) {
|
|
489
|
+
projectTemplate = foundTemplate.value;
|
|
490
|
+
printSuccess(`使用指定模版:${chalk.bold(options.template)}`);
|
|
491
|
+
} else {
|
|
492
|
+
printWarning(`未找到指定模版 "${options.template}",请重新选择`);
|
|
581
493
|
}
|
|
582
494
|
}
|
|
583
495
|
|
|
584
|
-
|
|
496
|
+
if (!projectTemplate) {
|
|
497
|
+
const availableTemplates = templates.standalone[frameworkType];
|
|
585
498
|
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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("已删除现有目录");
|
|
499
|
+
// 如果只有一个模版,直接使用它
|
|
500
|
+
if (availableTemplates.length === 1) {
|
|
501
|
+
projectTemplate = availableTemplates[0].value;
|
|
502
|
+
printInfo(`使用模版:${chalk.bold(availableTemplates[0].name)}`);
|
|
600
503
|
} else {
|
|
601
|
-
|
|
602
|
-
|
|
504
|
+
// 多个模版时让用户选择
|
|
505
|
+
const { template } = await inquirer.prompt({
|
|
506
|
+
type: "list",
|
|
507
|
+
name: "template",
|
|
508
|
+
message: chalk.cyan("📋 请选择模版:"),
|
|
509
|
+
choices: availableTemplates.map((t) => ({
|
|
510
|
+
name: `${chalk.white(t.name)}`,
|
|
511
|
+
value: t.value,
|
|
512
|
+
})),
|
|
513
|
+
});
|
|
514
|
+
projectTemplate = template;
|
|
603
515
|
}
|
|
604
516
|
}
|
|
517
|
+
}
|
|
605
518
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
519
|
+
console.log(); // 空行
|
|
520
|
+
|
|
521
|
+
// 获取目标文件夹路径
|
|
522
|
+
const dest = path.join(process.cwd(), projectName);
|
|
523
|
+
// 判断文件夹是否存在,存在就交互询问用户是否覆盖
|
|
524
|
+
if (fs.existsSync(dest)) {
|
|
525
|
+
printWarning(`目录 "${projectName}" 已存在!`);
|
|
526
|
+
const { force } = await inquirer.prompt({
|
|
527
|
+
type: "confirm",
|
|
528
|
+
name: "force",
|
|
529
|
+
message: chalk.yellow("⚠️ 是否覆盖现有目录?"),
|
|
530
|
+
default: false,
|
|
610
531
|
});
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
// 删除.git文件夹
|
|
620
|
-
const gitDir = path.join(dest, ".git");
|
|
621
|
-
if (fs.existsSync(gitDir)) {
|
|
622
|
-
fs.removeSync(gitDir);
|
|
623
|
-
printSuccess("已清理 .git 文件夹");
|
|
624
|
-
}
|
|
532
|
+
if (force) {
|
|
533
|
+
fs.removeSync(dest);
|
|
534
|
+
printSuccess("已删除现有目录");
|
|
535
|
+
} else {
|
|
536
|
+
printInfo("操作已取消");
|
|
537
|
+
process.exit(1);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
625
540
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
541
|
+
// 开始loading
|
|
542
|
+
const loading = ora({
|
|
543
|
+
text: "正在下载模版...",
|
|
544
|
+
spinner: "bouncingBar",
|
|
545
|
+
});
|
|
546
|
+
loading.start();
|
|
547
|
+
|
|
548
|
+
// 6. 开始下载模版
|
|
549
|
+
try {
|
|
550
|
+
const result = await cloneRepository(projectTemplate, dest);
|
|
551
|
+
loading.succeed();
|
|
552
|
+
printSuccess("模版下载成功!");
|
|
553
|
+
|
|
554
|
+
// 删除.git文件夹
|
|
555
|
+
const gitDir = path.join(dest, ".git");
|
|
556
|
+
if (fs.existsSync(gitDir)) {
|
|
557
|
+
fs.removeSync(gitDir);
|
|
558
|
+
printSuccess("已清理 .git 文件夹");
|
|
559
|
+
}
|
|
635
560
|
|
|
561
|
+
// 新添加:如果是 webpack 子应用,进行环境配置
|
|
562
|
+
if (
|
|
563
|
+
architectureType === "microFrontend" &&
|
|
564
|
+
toolType === "webpack" &&
|
|
565
|
+
appDirection === "sub"
|
|
566
|
+
) {
|
|
636
567
|
console.log(); // 空行
|
|
637
|
-
|
|
638
|
-
} catch (error) {
|
|
639
|
-
loading.fail();
|
|
640
|
-
printError("模版下载失败:" + error);
|
|
641
|
-
process.exit(1);
|
|
568
|
+
await configureWebpackSubApp(dest, projectName);
|
|
642
569
|
}
|
|
570
|
+
|
|
571
|
+
console.log(); // 空行
|
|
572
|
+
printFinalInstructions(projectName, architectureType, appDirection);
|
|
573
|
+
} catch (error) {
|
|
574
|
+
loading.fail();
|
|
575
|
+
printError("模版下载失败:" + error);
|
|
576
|
+
process.exit(1);
|
|
643
577
|
}
|
|
644
578
|
});
|
|
645
579
|
|