@4399ywkf/cli 2.0.3 → 2.0.5
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/index.js
CHANGED
|
@@ -74,7 +74,8 @@ const DEFAULT_DATA = {
|
|
|
74
74
|
registry: ERegistry.npm,
|
|
75
75
|
withHusky: false,
|
|
76
76
|
extraNpmrc: "",
|
|
77
|
-
appTemplate: "app" /* app
|
|
77
|
+
appTemplate: "app" /* app */,
|
|
78
|
+
microRole: "none" /* none */
|
|
78
79
|
};
|
|
79
80
|
var index = async ({
|
|
80
81
|
cwd,
|
|
@@ -86,6 +87,7 @@ var index = async ({
|
|
|
86
87
|
let registry = ERegistry.npm;
|
|
87
88
|
let gitTemplate;
|
|
88
89
|
let appTemplate = (defaultData == null ? void 0 : defaultData.appTemplate) || "app" /* app */;
|
|
90
|
+
let microRole = (defaultData == null ? void 0 : defaultData.microRole) || "none" /* none */;
|
|
89
91
|
const { username, email } = await utils.getGitInfo();
|
|
90
92
|
const author = email && username ? `${username} <${email}>` : "";
|
|
91
93
|
let pluginName = `${name || "demo"}`;
|
|
@@ -145,6 +147,30 @@ var index = async ({
|
|
|
145
147
|
initialValue: ERegistry.npm
|
|
146
148
|
});
|
|
147
149
|
};
|
|
150
|
+
const selectMicroFrontend = async () => {
|
|
151
|
+
const enableMicro = await confirm({
|
|
152
|
+
message: "\u662F\u5426\u542F\u7528\u5FAE\u524D\u7AEF\uFF08Garfish\uFF09\uFF1F",
|
|
153
|
+
initialValue: false
|
|
154
|
+
});
|
|
155
|
+
if (isCancel(enableMicro)) {
|
|
156
|
+
exitPrompt();
|
|
157
|
+
}
|
|
158
|
+
if (!enableMicro) {
|
|
159
|
+
microRole = "none" /* none */;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
microRole = await select({
|
|
163
|
+
message: "\u9009\u62E9\u5FAE\u524D\u7AEF\u89D2\u8272",
|
|
164
|
+
options: [
|
|
165
|
+
{ label: "\u5B50\u5E94\u7528", value: "sub" /* sub */, hint: "\u63A5\u5165\u4E3B\u5E94\u7528\u7684\u72EC\u7ACB\u6A21\u5757" },
|
|
166
|
+
{ label: "\u4E3B\u5E94\u7528\uFF08\u57FA\u5EA7\uFF09", value: "master" /* master */, hint: "\u7BA1\u7406\u548C\u8C03\u5EA6\u5B50\u5E94\u7528" }
|
|
167
|
+
],
|
|
168
|
+
initialValue: "sub" /* sub */
|
|
169
|
+
});
|
|
170
|
+
if (isCancel(microRole)) {
|
|
171
|
+
exitPrompt();
|
|
172
|
+
}
|
|
173
|
+
};
|
|
148
174
|
const selectGitTemplate = async () => {
|
|
149
175
|
const gitTemplate2 = await text({
|
|
150
176
|
message: "\u8BF7\u8F93\u5165 Git \u6A21\u677F\u540D\u79F0",
|
|
@@ -202,6 +228,7 @@ var index = async ({
|
|
|
202
228
|
if (isCancel(registry)) {
|
|
203
229
|
exitPrompt();
|
|
204
230
|
}
|
|
231
|
+
await selectMicroFrontend();
|
|
205
232
|
outro(utils.chalk.green(`\u2728 \u4E00\u5207\u5C31\u7EEA, \u5F00\u59CB\u521B\u5EFA\u9879\u76EE...`));
|
|
206
233
|
};
|
|
207
234
|
const useDefaultData = !!args.default;
|
|
@@ -296,7 +323,11 @@ Git\u6A21\u677F: ${gitTemplate}
|
|
|
296
323
|
withHusky,
|
|
297
324
|
extraNpmrc: isPnpm ? pnpmExtraNpmrc : "",
|
|
298
325
|
pluginName,
|
|
299
|
-
name
|
|
326
|
+
name,
|
|
327
|
+
microRole,
|
|
328
|
+
enableMicro: microRole !== "none" /* none */,
|
|
329
|
+
isMasterApp: microRole === "master" /* master */,
|
|
330
|
+
isSubApp: microRole === "sub" /* sub */
|
|
300
331
|
}
|
|
301
332
|
});
|
|
302
333
|
await generator.run();
|
|
@@ -345,15 +376,16 @@ Git\u6A21\u677F: ${gitTemplate}
|
|
|
345
376
|
);
|
|
346
377
|
}
|
|
347
378
|
}
|
|
348
|
-
printSuccess({ name, target, npmClient });
|
|
379
|
+
printSuccess({ name, target, npmClient, microRole });
|
|
349
380
|
};
|
|
350
381
|
function printSuccess(opts) {
|
|
351
|
-
const { name, target, npmClient } = opts;
|
|
382
|
+
const { name, target, npmClient, microRole } = opts;
|
|
352
383
|
const { outro } = utils.clackPrompts;
|
|
384
|
+
const microLabel = microRole === "master" ? "\u4E3B\u5E94\u7528\uFF08\u57FA\u5EA7\uFF09" : microRole === "sub" ? "\u5B50\u5E94\u7528" : "\u672A\u542F\u7528";
|
|
353
385
|
console.log("");
|
|
354
386
|
console.log(
|
|
355
387
|
boxen(
|
|
356
|
-
utils.chalk.green.bold("\u{1F389} \u9879\u76EE\u521B\u5EFA\u6210\u529F\uFF01\n\n") + utils.chalk.white("\u{1F4E6} \u9879\u76EE\u4FE1\u606F\n") + utils.chalk.gray("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n") + utils.chalk.cyan("\u540D\u79F0: ") + utils.chalk.white(name) + "\n" + utils.chalk.cyan("\u8DEF\u5F84: ") + utils.chalk.white(target) + "\n" + utils.chalk.cyan("\u5305\u7BA1\u7406\u5668: ") + utils.chalk.white(npmClient) + "\n\n" + utils.chalk.white("\u{1F680} \u5FEB\u901F\u5F00\u59CB\n") + utils.chalk.gray("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n") + utils.chalk.white("1. \u8FDB\u5165\u9879\u76EE\u76EE\u5F55\n") + utils.chalk.cyan(` cd ${name}
|
|
388
|
+
utils.chalk.green.bold("\u{1F389} \u9879\u76EE\u521B\u5EFA\u6210\u529F\uFF01\n\n") + utils.chalk.white("\u{1F4E6} \u9879\u76EE\u4FE1\u606F\n") + utils.chalk.gray("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n") + utils.chalk.cyan("\u540D\u79F0: ") + utils.chalk.white(name) + "\n" + utils.chalk.cyan("\u8DEF\u5F84: ") + utils.chalk.white(target) + "\n" + utils.chalk.cyan("\u5305\u7BA1\u7406\u5668: ") + utils.chalk.white(npmClient) + "\n" + utils.chalk.cyan("\u5FAE\u524D\u7AEF: ") + utils.chalk.white(microLabel) + "\n\n" + utils.chalk.white("\u{1F680} \u5FEB\u901F\u5F00\u59CB\n") + utils.chalk.gray("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n") + utils.chalk.white("1. \u8FDB\u5165\u9879\u76EE\u76EE\u5F55\n") + utils.chalk.cyan(` cd ${name}
|
|
357
389
|
|
|
358
390
|
`) + utils.chalk.white("2. \u542F\u52A8\u5F00\u53D1\u670D\u52A1\u5668\n") + utils.chalk.cyan(` ${npmClient} run dev
|
|
359
391
|
|
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
import { defineConfig } from "@4399ywkf/core/config";
|
|
2
|
-
import { tailwindPlugin, reactQueryPlugin, zustandPlugin } from "@4399ywkf/core";
|
|
2
|
+
import { tailwindPlugin, reactQueryPlugin, zustandPlugin{{#enableMicro}}, garfishPlugin{{/enableMicro}} } from "@4399ywkf/core";
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* YWKF 框架配置
|
|
6
|
-
*
|
|
7
|
-
* 所有扩展功能通过插件按需启用:
|
|
8
|
-
* - reactQueryPlugin() — React Query + Axios 请求层(默认开启)
|
|
9
|
-
* - zustandPlugin() — Zustand 状态管理(默认开启)
|
|
10
|
-
* - tailwindPlugin() — Tailwind CSS(默认开启)
|
|
11
|
-
* - garfishPlugin() — 微前端
|
|
12
|
-
* - i18nPlugin() — 国际化
|
|
13
|
-
* - themePlugin() — antd-style 主题
|
|
14
|
-
*
|
|
15
|
-
* 示例:
|
|
16
|
-
* import { garfishPlugin, i18nPlugin, themePlugin } from "@4399ywkf/core";
|
|
17
|
-
*/
|
|
18
4
|
export default defineConfig({
|
|
19
|
-
appName: process.env.APP_NAME || "
|
|
5
|
+
appName: process.env.APP_NAME || "{{{ name }}}",
|
|
20
6
|
appCName: process.env.APP_CNAME || "应用",
|
|
21
7
|
|
|
22
8
|
dev: {
|
|
@@ -31,7 +17,7 @@ export default defineConfig({
|
|
|
31
17
|
|
|
32
18
|
html: {
|
|
33
19
|
title: process.env.APP_CNAME || "应用",
|
|
34
|
-
mountRoot: process.env.APP_NAME || "
|
|
20
|
+
mountRoot: process.env.APP_NAME || "{{{ name }}}",
|
|
35
21
|
},
|
|
36
22
|
|
|
37
23
|
router: {
|
|
@@ -50,17 +36,27 @@ export default defineConfig({
|
|
|
50
36
|
},
|
|
51
37
|
|
|
52
38
|
plugins: [
|
|
53
|
-
// 请求层(默认开启)
|
|
54
39
|
reactQueryPlugin(),
|
|
55
|
-
|
|
56
|
-
// 状态管理(默认开启)
|
|
57
40
|
zustandPlugin(),
|
|
58
|
-
|
|
59
|
-
// 样式
|
|
60
41
|
tailwindPlugin(),
|
|
42
|
+
{{#isSubApp}}
|
|
43
|
+
|
|
44
|
+
// 微前端 · 子应用模式
|
|
45
|
+
garfishPlugin({
|
|
46
|
+
appName: process.env.APP_NAME || "{{{ name }}}",
|
|
47
|
+
}),
|
|
48
|
+
{{/isSubApp}}
|
|
49
|
+
{{#isMasterApp}}
|
|
61
50
|
|
|
62
|
-
//
|
|
63
|
-
|
|
51
|
+
// 微前端 · 主应用(基座)模式
|
|
52
|
+
garfishPlugin({
|
|
53
|
+
master: true,
|
|
54
|
+
apps: [
|
|
55
|
+
// 在此注册子应用
|
|
56
|
+
// { name: "sub-app", entry: "http://localhost:3001", activeRule: "/sub" },
|
|
57
|
+
],
|
|
58
|
+
}),
|
|
59
|
+
{{/isMasterApp}}
|
|
64
60
|
|
|
65
61
|
// 国际化(按需启用)
|
|
66
62
|
// i18nPlugin({ defaultLocale: "zh-CN", locales: ["zh-CN", "en-US"] }),
|