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