@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.
Files changed (2) hide show
  1. package/dist/cli.js +186 -252
  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.18",
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
- 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.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.gray("⚙️ 自定义配置")} - 手动选择所有选项`,
402
- value: null,
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
- 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({
399
+ // 4. 选择应用方向
400
+ const { appDirection: appDirectionResult } = await inquirer.prompt({
419
401
  type: "list",
420
- name: "architectureType",
421
- message: chalk.cyan("🏗️ 请选择架构类型:"),
402
+ name: "appDirection",
403
+ message: chalk.cyan("🎯 请选择应用方向:"),
422
404
  choices: [
423
405
  {
424
- name: `${chalk.blue("🧩 微前端架构")} - 支持主应用和子应用`,
425
- value: "microFrontend",
406
+ name: `${chalk.magenta("🏠 主应用")} - 微前端主应用`,
407
+ value: "main",
426
408
  },
427
409
  {
428
- name: `${chalk.green("📱 独立应用")} - 单体应用架构`,
429
- value: "standalone",
410
+ name: `${chalk.yellow("🧩 子应用")} - 微前端子应用`,
411
+ value: "sub",
430
412
  },
431
413
  ],
432
414
  });
433
- architectureType = selectedArchitecture;
415
+ appDirection = appDirectionResult;
416
+
434
417
  printInfo(
435
- `架构类型:${chalk.bold(
436
- architectureType === "microFrontend" ? "微前端架构" : "独立应用"
437
- )}`
418
+ `应用方向:${chalk.bold(appDirection === "main" ? "主应用" : "子应用")}`
438
419
  );
439
420
 
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
- );
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
- 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
- }
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
- 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
- }
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
- console.log(); // 空行
496
+ if (!projectTemplate) {
497
+ const availableTemplates = templates.standalone[frameworkType];
585
498
 
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("已删除现有目录");
499
+ // 如果只有一个模版,直接使用它
500
+ if (availableTemplates.length === 1) {
501
+ projectTemplate = availableTemplates[0].value;
502
+ printInfo(`使用模版:${chalk.bold(availableTemplates[0].name)}`);
600
503
  } else {
601
- printInfo("操作已取消");
602
- 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;
603
515
  }
604
516
  }
517
+ }
605
518
 
606
- // 开始loading
607
- const loading = ora({
608
- text: "正在下载模版...",
609
- 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,
610
531
  });
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
- }
532
+ if (force) {
533
+ fs.removeSync(dest);
534
+ printSuccess("已删除现有目录");
535
+ } else {
536
+ printInfo("操作已取消");
537
+ process.exit(1);
538
+ }
539
+ }
625
540
 
626
- // 新添加:如果是 webpack 子应用,进行环境配置
627
- if (
628
- architectureType === "microFrontend" &&
629
- toolType === "webpack" &&
630
- appDirection === "sub"
631
- ) {
632
- console.log(); // 空行
633
- await configureWebpackSubApp(dest, projectName);
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
- printFinalInstructions(projectName);
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4399ywkf/cli",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "运维开发部脚手架",
5
5
  "main": "dist/index.js",
6
6
  "bin": {