@4399ywkf/cli 0.0.15 → 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 +334 -216
- package/dist/templates.js +15 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -23,12 +23,18 @@ var templates$1 = {
|
|
|
23
23
|
{
|
|
24
24
|
value: "https://ywgit.gz4399.com/ywkf/webpack-mainApplicate_demo.git",
|
|
25
25
|
name: "webpack-mainApplicate_demo",
|
|
26
|
+
description: "基于 Webpack 的微前端主应用模板",
|
|
27
|
+
features: ["qiankun", "react", "antd", "路由管理"],
|
|
28
|
+
recommended: true,
|
|
26
29
|
},
|
|
27
30
|
],
|
|
28
31
|
sub: [
|
|
29
32
|
{
|
|
30
33
|
value: "https://ywgit.gz4399.com/ywkf/webpack-subApplicate_demo.git",
|
|
31
34
|
name: "webpack-subApplicate_demo",
|
|
35
|
+
description: "标准的微前端子应用模板",
|
|
36
|
+
features: ["react", "antd", "独立运行"],
|
|
37
|
+
recommended: true,
|
|
32
38
|
},
|
|
33
39
|
],
|
|
34
40
|
},
|
|
@@ -37,12 +43,18 @@ var templates$1 = {
|
|
|
37
43
|
{
|
|
38
44
|
value: "https://ywgit.gz4399.com/ywkf/vite-mainApplicate_demo.git",
|
|
39
45
|
name: "vite-mainApplicate_demo",
|
|
46
|
+
description: "基于 Vite 的微前端主应用模板",
|
|
47
|
+
features: ["qiankun", "react", "antd", "路由管理"],
|
|
48
|
+
recommended: true,
|
|
40
49
|
},
|
|
41
50
|
],
|
|
42
51
|
sub: [
|
|
43
52
|
{
|
|
44
53
|
value: "https://ywgit.gz4399.com/ywkf/vite-subApplicate_demo.git",
|
|
45
54
|
name: "vite-subApplicate_demo",
|
|
55
|
+
description: "标准的微前端子应用模板",
|
|
56
|
+
features: ["react", "antd", "独立运行"],
|
|
57
|
+
recommended: true,
|
|
46
58
|
},
|
|
47
59
|
],
|
|
48
60
|
},
|
|
@@ -52,6 +64,9 @@ var templates$1 = {
|
|
|
52
64
|
{
|
|
53
65
|
value: "https://ywgit.gz4399.com/ywkf/next-dome.git",
|
|
54
66
|
name: "next-demo",
|
|
67
|
+
description: "基于 Next.js 的全栈应用模板",
|
|
68
|
+
features: ["react", "antd", "next", "路由管理"],
|
|
69
|
+
recommended: true,
|
|
55
70
|
},
|
|
56
71
|
],
|
|
57
72
|
},
|
|
@@ -70,7 +85,7 @@ const chalk = require$$7;
|
|
|
70
85
|
const boxen = require$$8;
|
|
71
86
|
const figlet = require$$9;
|
|
72
87
|
const pkgInfo = {
|
|
73
|
-
version: "0.0.
|
|
88
|
+
version: "0.0.18",
|
|
74
89
|
};
|
|
75
90
|
|
|
76
91
|
// 美化输出函数
|
|
@@ -104,31 +119,44 @@ function printWarning(message) {
|
|
|
104
119
|
}
|
|
105
120
|
|
|
106
121
|
function printFinalInstructions(projectName) {
|
|
107
|
-
|
|
108
|
-
chalk.green("🎉 项目创建成功!"),
|
|
109
|
-
"",
|
|
110
|
-
chalk.cyan("接下来的步骤:"),
|
|
111
|
-
chalk.gray(" 1. 进入项目目录"),
|
|
112
|
-
chalk.white(` cd ${projectName}`),
|
|
113
|
-
chalk.gray(" 2. 切换Node版本"),
|
|
114
|
-
chalk.white(" nvm use"),
|
|
115
|
-
chalk.gray(" 3. 安装依赖"),
|
|
116
|
-
chalk.white(" pnpm i"),
|
|
117
|
-
chalk.gray(" 4. 启动项目"),
|
|
118
|
-
chalk.white(" pnpm start"),
|
|
119
|
-
"",
|
|
120
|
-
chalk.magenta("🚀 开始你的开发之旅吧!"),
|
|
121
|
-
].join("\n");
|
|
122
|
-
|
|
122
|
+
console.log();
|
|
123
123
|
console.log(
|
|
124
|
-
boxen(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
+
)
|
|
131
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
|
+
}
|
|
132
160
|
}
|
|
133
161
|
|
|
134
162
|
function cloneRepository(repoUrl, destination) {
|
|
@@ -300,30 +328,19 @@ async function configureWebpackSubApp(projectPath, projectName) {
|
|
|
300
328
|
}
|
|
301
329
|
}
|
|
302
330
|
|
|
331
|
+
// 支持无参数创建(在当前目录)
|
|
303
332
|
program
|
|
304
|
-
.command("create [
|
|
305
|
-
.description("
|
|
306
|
-
.option("-t, --template <template>", "
|
|
333
|
+
.command("create [project-name]") // 使project-name可选
|
|
334
|
+
.description("创建新项目")
|
|
335
|
+
.option("-t, --template <template>", "指定模版")
|
|
307
336
|
.action(async (projectName, options) => {
|
|
308
|
-
//
|
|
309
|
-
printBanner();
|
|
310
|
-
|
|
311
|
-
const getRepoLoading = ora({
|
|
312
|
-
text: "正在获取模版列表...",
|
|
313
|
-
spinner: "dots",
|
|
314
|
-
});
|
|
315
|
-
getRepoLoading.start();
|
|
316
|
-
|
|
317
|
-
getRepoLoading.succeed();
|
|
318
|
-
printSuccess("模版列表获取成功!");
|
|
319
|
-
console.log(); // 空行
|
|
320
|
-
|
|
321
|
-
// 1. 如果用户没有传入名称就交互式输入
|
|
337
|
+
// 如果没有提供项目名,询问用户
|
|
322
338
|
if (!projectName) {
|
|
323
339
|
const { name } = await inquirer.prompt({
|
|
324
340
|
type: "input",
|
|
325
341
|
name: "name",
|
|
326
342
|
message: chalk.cyan("📝 请输入项目名称:"),
|
|
343
|
+
default: "my-project",
|
|
327
344
|
validate: (input) => {
|
|
328
345
|
if (!input.trim()) {
|
|
329
346
|
return "项目名称不能为空!";
|
|
@@ -335,218 +352,319 @@ program
|
|
|
335
352
|
}
|
|
336
353
|
printInfo(`项目名称:${chalk.bold(projectName)}`);
|
|
337
354
|
|
|
338
|
-
//
|
|
339
|
-
const {
|
|
340
|
-
type: "
|
|
341
|
-
name: "
|
|
342
|
-
message: chalk.cyan("
|
|
343
|
-
|
|
344
|
-
{
|
|
345
|
-
name: `${chalk.blue("🧩 微前端架构")} - 支持主应用和子应用`,
|
|
346
|
-
value: "microFrontend",
|
|
347
|
-
},
|
|
348
|
-
{
|
|
349
|
-
name: `${chalk.green("📱 独立应用")} - 单体应用架构`,
|
|
350
|
-
value: "standalone",
|
|
351
|
-
},
|
|
352
|
-
],
|
|
355
|
+
// 添加预设选择(移到这里)
|
|
356
|
+
const { usePreset } = await inquirer.prompt({
|
|
357
|
+
type: "confirm",
|
|
358
|
+
name: "usePreset",
|
|
359
|
+
message: chalk.cyan("🎯 是否使用推荐预设?"),
|
|
360
|
+
default: true,
|
|
353
361
|
});
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
let projectTemplate;
|
|
361
|
-
let toolType, appDirection;
|
|
362
|
-
|
|
363
|
-
if (architectureType === "microFrontend") {
|
|
364
|
-
// 微前端架构流程
|
|
365
|
-
// 3. 选择工具类型
|
|
366
|
-
const toolTypeResult = await inquirer.prompt({
|
|
362
|
+
|
|
363
|
+
let architectureType, toolType, appDirection;
|
|
364
|
+
|
|
365
|
+
if (usePreset) {
|
|
366
|
+
// 预设选择逻辑
|
|
367
|
+
const { preset } = await inquirer.prompt({
|
|
367
368
|
type: "list",
|
|
368
|
-
name: "
|
|
369
|
-
message: chalk.cyan("
|
|
369
|
+
name: "preset",
|
|
370
|
+
message: chalk.cyan("📋 请选择预设:"),
|
|
370
371
|
choices: [
|
|
371
372
|
{
|
|
372
|
-
name: `${chalk.blue("
|
|
373
|
-
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,
|
|
374
403
|
},
|
|
375
|
-
{ name: `${chalk.green("⚡ Vite")} - 快速的构建工具`, value: "vite" },
|
|
376
404
|
],
|
|
377
405
|
});
|
|
378
|
-
toolType = toolTypeResult.toolType;
|
|
379
|
-
printInfo(`工具类型:${chalk.bold(toolType)}`);
|
|
380
406
|
|
|
381
|
-
|
|
382
|
-
|
|
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({
|
|
383
419
|
type: "list",
|
|
384
|
-
name: "
|
|
385
|
-
message: chalk.cyan("
|
|
420
|
+
name: "architectureType",
|
|
421
|
+
message: chalk.cyan("🏗️ 请选择架构类型:"),
|
|
386
422
|
choices: [
|
|
387
423
|
{
|
|
388
|
-
name: `${chalk.
|
|
389
|
-
value: "
|
|
424
|
+
name: `${chalk.blue("🧩 微前端架构")} - 支持主应用和子应用`,
|
|
425
|
+
value: "microFrontend",
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
name: `${chalk.green("📱 独立应用")} - 单体应用架构`,
|
|
429
|
+
value: "standalone",
|
|
390
430
|
},
|
|
391
|
-
{ name: `${chalk.yellow("🧩 子应用")} - 微前端子应用`, value: "sub" },
|
|
392
431
|
],
|
|
393
432
|
});
|
|
394
|
-
|
|
433
|
+
architectureType = selectedArchitecture;
|
|
395
434
|
printInfo(
|
|
396
|
-
|
|
435
|
+
`架构类型:${chalk.bold(
|
|
436
|
+
architectureType === "microFrontend" ? "微前端架构" : "独立应用"
|
|
437
|
+
)}`
|
|
397
438
|
);
|
|
398
439
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
+
);
|
|
411
485
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
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
|
+
}
|
|
415
498
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
//
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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
|
+
}
|
|
431
559
|
}
|
|
432
|
-
}
|
|
433
|
-
} else {
|
|
434
|
-
// 独立应用架构流程
|
|
435
|
-
// 3. 选择框架类型
|
|
436
|
-
const { frameworkType } = await inquirer.prompt({
|
|
437
|
-
type: "list",
|
|
438
|
-
name: "frameworkType",
|
|
439
|
-
message: chalk.cyan("⚛️ 请选择框架类型:"),
|
|
440
|
-
default: "nextjs",
|
|
441
|
-
choices: [
|
|
442
|
-
{
|
|
443
|
-
name: `${chalk.black("▲")} ${chalk.white(
|
|
444
|
-
"Next.js"
|
|
445
|
-
)} - React 全栈框架`,
|
|
446
|
-
value: "nextjs",
|
|
447
|
-
},
|
|
448
|
-
// 可以在这里添加更多独立应用框架
|
|
449
|
-
],
|
|
450
|
-
});
|
|
451
|
-
printInfo(`框架类型:${chalk.bold(frameworkType)}`);
|
|
452
560
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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
|
+
}
|
|
463
581
|
}
|
|
464
582
|
}
|
|
465
583
|
|
|
466
|
-
|
|
467
|
-
const availableTemplates = templates.standalone[frameworkType];
|
|
584
|
+
console.log(); // 空行
|
|
468
585
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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("已删除现有目录");
|
|
473
600
|
} else {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
type: "list",
|
|
477
|
-
name: "template",
|
|
478
|
-
message: chalk.cyan("📋 请选择模版:"),
|
|
479
|
-
choices: availableTemplates.map((t) => ({
|
|
480
|
-
name: `${chalk.white(t.name)}`,
|
|
481
|
-
value: t.value,
|
|
482
|
-
})),
|
|
483
|
-
});
|
|
484
|
-
projectTemplate = template;
|
|
601
|
+
printInfo("操作已取消");
|
|
602
|
+
process.exit(1);
|
|
485
603
|
}
|
|
486
604
|
}
|
|
487
|
-
}
|
|
488
605
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
// 判断文件夹是否存在,存在就交互询问用户是否覆盖
|
|
494
|
-
if (fs.existsSync(dest)) {
|
|
495
|
-
printWarning(`目录 "${projectName}" 已存在!`);
|
|
496
|
-
const { force } = await inquirer.prompt({
|
|
497
|
-
type: "confirm",
|
|
498
|
-
name: "force",
|
|
499
|
-
message: chalk.yellow("⚠️ 是否覆盖现有目录?"),
|
|
500
|
-
default: false,
|
|
606
|
+
// 开始loading
|
|
607
|
+
const loading = ora({
|
|
608
|
+
text: "正在下载模版...",
|
|
609
|
+
spinner: "bouncingBar",
|
|
501
610
|
});
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
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
|
+
}
|
|
510
625
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
const result = await cloneRepository(projectTemplate, dest);
|
|
521
|
-
loading.succeed();
|
|
522
|
-
printSuccess("模版下载成功!");
|
|
523
|
-
|
|
524
|
-
// 删除.git文件夹
|
|
525
|
-
const gitDir = path.join(dest, ".git");
|
|
526
|
-
if (fs.existsSync(gitDir)) {
|
|
527
|
-
fs.removeSync(gitDir);
|
|
528
|
-
printSuccess("已清理 .git 文件夹");
|
|
529
|
-
}
|
|
626
|
+
// 新添加:如果是 webpack 子应用,进行环境配置
|
|
627
|
+
if (
|
|
628
|
+
architectureType === "microFrontend" &&
|
|
629
|
+
toolType === "webpack" &&
|
|
630
|
+
appDirection === "sub"
|
|
631
|
+
) {
|
|
632
|
+
console.log(); // 空行
|
|
633
|
+
await configureWebpackSubApp(dest, projectName);
|
|
634
|
+
}
|
|
530
635
|
|
|
531
|
-
// 新添加:如果是 webpack 子应用,进行环境配置
|
|
532
|
-
if (
|
|
533
|
-
architectureType === "microFrontend" &&
|
|
534
|
-
toolType === "webpack" &&
|
|
535
|
-
appDirection === "sub"
|
|
536
|
-
) {
|
|
537
636
|
console.log(); // 空行
|
|
538
|
-
|
|
637
|
+
printFinalInstructions(projectName);
|
|
638
|
+
} catch (error) {
|
|
639
|
+
loading.fail();
|
|
640
|
+
printError("模版下载失败:" + error);
|
|
641
|
+
process.exit(1);
|
|
539
642
|
}
|
|
540
|
-
|
|
541
|
-
console.log(); // 空行
|
|
542
|
-
printFinalInstructions(projectName);
|
|
543
|
-
} catch (error) {
|
|
544
|
-
loading.fail();
|
|
545
|
-
printError("模版下载失败:" + error);
|
|
546
|
-
process.exit(1);
|
|
547
643
|
}
|
|
548
644
|
});
|
|
549
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
|
+
|
|
550
668
|
// 定义当前版本
|
|
551
669
|
program.version(`v${pkgInfo.version}`);
|
|
552
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
|
},
|