@4399ywkf/cli 0.0.19 → 0.0.21

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 CHANGED
@@ -58,6 +58,26 @@ var templates$1 = {
58
58
  },
59
59
  ],
60
60
  },
61
+ rspack: {
62
+ main: [
63
+ {
64
+ value: "https://ywgit.gz4399.com/ywkf/rspack-subApplicate_demo.git",
65
+ name: "rspack-subApplicate_demo",
66
+ description: "基于 Rspack 的微前端子应用模板",
67
+ features: ["react", "antd", "独立运行"],
68
+ recommended: true,
69
+ },
70
+ ],
71
+ sub: [
72
+ {
73
+ value: "https://ywgit.gz4399.com/ywkf/rspack-subApplicate_demo.git",
74
+ name: "rspack-subApplicate_demo",
75
+ description: "基于 Rspack 的微前端子应用模板",
76
+ features: ["react", "antd", "独立运行"],
77
+ recommended: true,
78
+ },
79
+ ],
80
+ },
61
81
  },
62
82
  standalone: {
63
83
  nextjs: [
@@ -85,7 +105,7 @@ const chalk = require$$7;
85
105
  const boxen = require$$8;
86
106
  const figlet = require$$9;
87
107
  const pkgInfo = {
88
- version: "0.0.19",
108
+ version: "0.0.21",
89
109
  };
90
110
 
91
111
  // 美化输出函数
@@ -118,7 +138,7 @@ function printWarning(message) {
118
138
  console.log(chalk.yellow("⚠️ " + message));
119
139
  }
120
140
 
121
- function printFinalInstructions(projectName) {
141
+ function printFinalInstructions(projectName, architectureType, appDirection) {
122
142
  console.log();
123
143
  console.log(
124
144
  boxen(
@@ -129,8 +149,9 @@ function printFinalInstructions(projectName) {
129
149
  "",
130
150
  chalk.yellow("🚀 下一步:"),
131
151
  chalk.white(` cd ${projectName}`),
132
- chalk.white(" npm install # 或 pnpm install"),
133
- chalk.white(" npm run dev # 启动开发服务器"),
152
+ chalk.white(" nvm use "),
153
+ chalk.white(" pnpm install "),
154
+ chalk.white(" pnpm dev # 启动开发服务器"),
134
155
  "",
135
156
  chalk.gray("💡 提示:"),
136
157
  chalk.gray(" - 查看 README.md 了解更多信息"),
@@ -352,302 +373,233 @@ program
352
373
  }
353
374
  printInfo(`项目名称:${chalk.bold(projectName)}`);
354
375
 
355
- // 添加预设选择(移到这里)
356
- const { usePreset } = await inquirer.prompt({
357
- type: "confirm",
358
- name: "usePreset",
359
- message: chalk.cyan("🎯 是否使用推荐预设?"),
360
- default: true,
376
+ const { architectureType } = await inquirer.prompt({
377
+ type: "list",
378
+ name: "architectureType",
379
+ message: chalk.cyan("🏗️ 请选择架构类型:"),
380
+ choices: [
381
+ {
382
+ name: `${chalk.blue("🧩 微前端架构")} - 支持主应用和子应用`,
383
+ value: "microFrontend",
384
+ },
385
+ {
386
+ name: `${chalk.green("📱 独立应用")} - 单体应用架构`,
387
+ value: "standalone",
388
+ },
389
+ ],
361
390
  });
362
-
363
- let architectureType, toolType, appDirection;
364
-
365
- if (usePreset) {
366
- // 预设选择逻辑
367
- const { preset } = await inquirer.prompt({
391
+ printInfo(
392
+ `架构类型:${chalk.bold(
393
+ architectureType === "microFrontend" ? "微前端架构" : "独立应用"
394
+ )}`
395
+ );
396
+
397
+ let projectTemplate, toolType, appDirection;
398
+
399
+ if (architectureType === "microFrontend") {
400
+ // 微前端架构流程
401
+ // 3. 选择工具类型
402
+ const { toolType: toolTypeResult } = await inquirer.prompt({
368
403
  type: "list",
369
- name: "preset",
370
- message: chalk.cyan("📋 请选择预设:"),
404
+ name: "toolType",
405
+ message: chalk.cyan("🔧 请选择工具类型:"),
406
+ default: "rspack",
371
407
  choices: [
372
408
  {
373
- name: `${chalk.blue("🏠 Webpack 主应用")} - 企业级微前端主应用`,
374
- value: {
375
- architecture: "microFrontend",
376
- tool: "webpack",
377
- direction: "main",
378
- },
409
+ name: `${chalk.blue("📦 Webpack")} - 成熟稳定的打包工具`,
410
+ value: "webpack",
379
411
  },
380
412
  {
381
- name: `${chalk.green("🧩 Webpack 子应用")} - 业务子应用`,
382
- value: {
383
- architecture: "microFrontend",
384
- tool: "webpack",
385
- direction: "sub",
386
- },
413
+ name: `${chalk.green(" Vite")} - 快速的构建工具`,
414
+ value: "vite",
387
415
  },
388
416
  {
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
- },
403
- },
404
- {
405
- name: `${chalk.yellow("📱 Next.js 应用")} - 全栈应用`,
406
- value: { architecture: "standalone", framework: "nextjs" },
407
- },
408
- {
409
- name: `${chalk.gray("⚙️ 自定义配置")} - 手动选择所有选项`,
410
- value: null,
417
+ name: `${chalk.yellow("⚛️ Rspack")} - 快速的打包工具`,
418
+ value: "rspack",
411
419
  },
412
420
  ],
413
421
  });
422
+ toolType = toolTypeResult;
423
+ printInfo(`工具类型:${chalk.bold(toolType)}`);
414
424
 
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({
425
+ // 4. 选择应用方向
426
+ const { appDirection: appDirectionResult } = await inquirer.prompt({
427
427
  type: "list",
428
- name: "architectureType",
429
- message: chalk.cyan("🏗️ 请选择架构类型:"),
428
+ name: "appDirection",
429
+ message: chalk.cyan("🎯 请选择应用方向:"),
430
430
  choices: [
431
431
  {
432
- name: `${chalk.blue("🧩 微前端架构")} - 支持主应用和子应用`,
433
- value: "microFrontend",
432
+ name: `${chalk.magenta("🏠 主应用")} - 微前端主应用`,
433
+ value: "main",
434
434
  },
435
435
  {
436
- name: `${chalk.green("📱 独立应用")} - 单体应用架构`,
437
- value: "standalone",
436
+ name: `${chalk.yellow("🧩 子应用")} - 微前端子应用`,
437
+ value: "sub",
438
438
  },
439
439
  ],
440
440
  });
441
- architectureType = selectedArchitecture;
441
+ appDirection = appDirectionResult;
442
+
442
443
  printInfo(
443
- `架构类型:${chalk.bold(
444
- architectureType === "microFrontend" ? "微前端架构" : "独立应用"
445
- )}`
444
+ `应用方向:${chalk.bold(appDirection === "main" ? "主应用" : "子应用")}`
446
445
  );
447
446
 
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
- }
447
+ // 5. 选择模版
448
+ if (options.template) {
449
+ const foundTemplate = templates.microFrontend[toolType][
450
+ appDirection
451
+ ].find((template) => template.name === options.template);
452
+ if (foundTemplate) {
453
+ projectTemplate = foundTemplate.value;
454
+ printSuccess(`使用指定模版:${chalk.bold(options.template)}`);
455
+ } else {
456
+ printWarning(`未找到指定模版 "${options.template}",请重新选择`);
505
457
  }
458
+ }
506
459
 
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
- }
460
+ if (!projectTemplate) {
461
+ const availableTemplates =
462
+ templates.microFrontend[toolType][appDirection];
463
+
464
+ // 如果只有一个模版,直接使用它
465
+ if (availableTemplates.length === 1) {
466
+ projectTemplate = availableTemplates[0].value;
467
+ } else {
468
+ // 多个模版时让用户选择
469
+ const { template } = await inquirer.prompt({
470
+ type: "list",
471
+ name: "template",
472
+ message: chalk.cyan("📋 请选择模版:"),
473
+ choices: availableTemplates.map((t) => ({
474
+ name: [
475
+ `${t.recommended ? chalk.green("⭐") : " "} ${chalk.white(
476
+ t.name
477
+ )}`,
478
+ ` ${chalk.gray(t.description)}`,
479
+ ` ${chalk.blue(`特性: ${t.features.join(", ")}`)}`,
480
+ ].join("\n"),
481
+ value: t.value,
482
+ short: t.name,
483
+ })),
484
+ pageSize: 10,
485
+ });
486
+ projectTemplate = template;
567
487
  }
488
+ }
489
+ } else {
490
+ // 独立应用架构流程
491
+ // 3. 选择框架类型
492
+ const { frameworkType } = await inquirer.prompt({
493
+ type: "list",
494
+ name: "frameworkType",
495
+ message: chalk.cyan("⚛️ 请选择框架类型:"),
496
+ default: "nextjs",
497
+ choices: [
498
+ {
499
+ name: `${chalk.black("▲")} ${chalk.white(
500
+ "Next.js"
501
+ )} - React 全栈框架`,
502
+ value: "nextjs",
503
+ },
504
+ // 可以在这里添加更多独立应用框架
505
+ ],
506
+ });
507
+ printInfo(`框架类型:${chalk.bold(frameworkType)}`);
568
508
 
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
- }
509
+ // 4. 选择模版
510
+ if (options.template) {
511
+ const foundTemplate = templates.standalone[frameworkType].find(
512
+ (template) => template.name === options.template
513
+ );
514
+ if (foundTemplate) {
515
+ projectTemplate = foundTemplate.value;
516
+ printSuccess(`使用指定模版:${chalk.bold(options.template)}`);
517
+ } else {
518
+ printWarning(`未找到指定模版 "${options.template}",请重新选择`);
589
519
  }
590
520
  }
591
521
 
592
- console.log(); // 空行
522
+ if (!projectTemplate) {
523
+ const availableTemplates = templates.standalone[frameworkType];
593
524
 
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("已删除现有目录");
525
+ // 如果只有一个模版,直接使用它
526
+ if (availableTemplates.length === 1) {
527
+ projectTemplate = availableTemplates[0].value;
528
+ printInfo(`使用模版:${chalk.bold(availableTemplates[0].name)}`);
608
529
  } else {
609
- printInfo("操作已取消");
610
- process.exit(1);
530
+ // 多个模版时让用户选择
531
+ const { template } = await inquirer.prompt({
532
+ type: "list",
533
+ name: "template",
534
+ message: chalk.cyan("📋 请选择模版:"),
535
+ choices: availableTemplates.map((t) => ({
536
+ name: `${chalk.white(t.name)}`,
537
+ value: t.value,
538
+ })),
539
+ });
540
+ projectTemplate = template;
611
541
  }
612
542
  }
543
+ }
613
544
 
614
- // 开始loading
615
- const loading = ora({
616
- text: "正在下载模版...",
617
- spinner: "bouncingBar",
545
+ console.log(); // 空行
546
+
547
+ // 获取目标文件夹路径
548
+ const dest = path.join(process.cwd(), projectName);
549
+ // 判断文件夹是否存在,存在就交互询问用户是否覆盖
550
+ if (fs.existsSync(dest)) {
551
+ printWarning(`目录 "${projectName}" 已存在!`);
552
+ const { force } = await inquirer.prompt({
553
+ type: "confirm",
554
+ name: "force",
555
+ message: chalk.yellow("⚠️ 是否覆盖现有目录?"),
556
+ default: false,
618
557
  });
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
- }
558
+ if (force) {
559
+ fs.removeSync(dest);
560
+ printSuccess("已删除现有目录");
561
+ } else {
562
+ printInfo("操作已取消");
563
+ process.exit(1);
564
+ }
565
+ }
633
566
 
634
- // 新添加:如果是 webpack 子应用,进行环境配置
635
- if (
636
- architectureType === "microFrontend" &&
637
- toolType === "webpack" &&
638
- appDirection === "sub"
639
- ) {
640
- console.log(); // 空行
641
- await configureWebpackSubApp(dest, projectName);
642
- }
567
+ // 开始loading
568
+ const loading = ora({
569
+ text: "正在下载模版...",
570
+ spinner: "bouncingBar",
571
+ });
572
+ loading.start();
573
+
574
+ // 6. 开始下载模版
575
+ try {
576
+ const result = await cloneRepository(projectTemplate, dest);
577
+ loading.succeed();
578
+ printSuccess("模版下载成功!");
579
+
580
+ // 删除.git文件夹
581
+ const gitDir = path.join(dest, ".git");
582
+ if (fs.existsSync(gitDir)) {
583
+ fs.removeSync(gitDir);
584
+ printSuccess("已清理 .git 文件夹");
585
+ }
643
586
 
587
+ // 新添加:如果是 webpack 子应用,进行环境配置
588
+ if (
589
+ architectureType === "microFrontend" &&
590
+ toolType === "webpack" &&
591
+ appDirection === "sub"
592
+ ) {
644
593
  console.log(); // 空行
645
- printFinalInstructions(projectName);
646
- } catch (error) {
647
- loading.fail();
648
- printError("模版下载失败:" + error);
649
- process.exit(1);
594
+ await configureWebpackSubApp(dest, projectName);
650
595
  }
596
+
597
+ console.log(); // 空行
598
+ printFinalInstructions(projectName, architectureType, appDirection);
599
+ } catch (error) {
600
+ loading.fail();
601
+ printError("模版下载失败:" + error);
602
+ process.exit(1);
651
603
  }
652
604
  });
653
605
 
package/dist/templates.js CHANGED
@@ -48,6 +48,26 @@ var templates = {
48
48
  },
49
49
  ],
50
50
  },
51
+ rspack: {
52
+ main: [
53
+ {
54
+ value: "https://ywgit.gz4399.com/ywkf/rspack-subApplicate_demo.git",
55
+ name: "rspack-subApplicate_demo",
56
+ description: "基于 Rspack 的微前端子应用模板",
57
+ features: ["react", "antd", "独立运行"],
58
+ recommended: true,
59
+ },
60
+ ],
61
+ sub: [
62
+ {
63
+ value: "https://ywgit.gz4399.com/ywkf/rspack-subApplicate_demo.git",
64
+ name: "rspack-subApplicate_demo",
65
+ description: "基于 Rspack 的微前端子应用模板",
66
+ features: ["react", "antd", "独立运行"],
67
+ recommended: true,
68
+ },
69
+ ],
70
+ },
51
71
  },
52
72
  standalone: {
53
73
  nextjs: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4399ywkf/cli",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "运维开发部脚手架",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -47,6 +47,7 @@
47
47
  "debug": "node --inspect-brk bin/cli.js",
48
48
  "debug:create": "node --inspect-brk bin/cli.js create test-project",
49
49
  "debug:create-with-template": "node --inspect-brk bin/cli.js create test-project -t webpack-mainApplicate_demo",
50
+ "debug:create-with-template-rspack": "node --inspect-brk bin/cli.js create test-project -t rspack-subApplicate_demo",
50
51
  "debug:help": "node --inspect-brk bin/cli.js --help",
51
52
  "build": "rollup -c && node scripts/postbuild.js",
52
53
  "build:watch": "rollup -c -w",