@4399ywkf/core 4.0.85 → 5.0.0

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 (81) hide show
  1. package/dist/cli/index.js +2180 -0
  2. package/dist/cli/index.js.map +1 -0
  3. package/dist/config/index.d.ts +37 -0
  4. package/dist/config/index.js +143 -0
  5. package/dist/config/index.js.map +1 -0
  6. package/dist/index.d.ts +496 -6
  7. package/dist/index.js +3671 -49
  8. package/dist/index.js.map +1 -0
  9. package/dist/plugin/index.d.ts +110 -0
  10. package/dist/plugin/index.js +277 -0
  11. package/dist/plugin/index.js.map +1 -0
  12. package/dist/router/index.d.ts +126 -0
  13. package/dist/router/index.js +390 -0
  14. package/dist/router/index.js.map +1 -0
  15. package/dist/rspack/index.d.ts +29 -0
  16. package/dist/rspack/index.js +1574 -0
  17. package/dist/rspack/index.js.map +1 -0
  18. package/dist/runtime/index.d.ts +120 -0
  19. package/dist/runtime/index.js +406 -0
  20. package/dist/runtime/index.js.map +1 -0
  21. package/dist/schema-BuqmN_ra.d.ts +390 -0
  22. package/dist/types-BZV_2QtD.d.ts +97 -0
  23. package/package.json +88 -37
  24. package/README.md +0 -3
  25. package/compiled/dotenv/LICENSE +0 -23
  26. package/compiled/dotenv/index.js +0 -1
  27. package/compiled/dotenv/lib/main.d.ts +0 -73
  28. package/compiled/dotenv/package.json +0 -1
  29. package/compiled/dotenv/types/index.d.ts +0 -59
  30. package/compiled/dotenv-expand/LICENSE +0 -24
  31. package/compiled/dotenv-expand/index.js +0 -1
  32. package/compiled/dotenv-expand/lib/main.d.ts +0 -29
  33. package/compiled/dotenv-expand/package.json +0 -1
  34. package/compiled/just-diff/LICENSE +0 -21
  35. package/compiled/just-diff/index.d.ts +0 -20
  36. package/compiled/just-diff/index.js +0 -1
  37. package/compiled/just-diff/package.json +0 -1
  38. package/dist/config/config.d.ts +0 -62
  39. package/dist/config/config.js +0 -240
  40. package/dist/config/utils.d.ts +0 -8
  41. package/dist/config/utils.js +0 -40
  42. package/dist/constants.d.ts +0 -9
  43. package/dist/constants.js +0 -45
  44. package/dist/route/defineRoutes.d.ts +0 -1
  45. package/dist/route/defineRoutes.js +0 -61
  46. package/dist/route/route.d.ts +0 -3
  47. package/dist/route/route.js +0 -27
  48. package/dist/route/routeUtils.d.ts +0 -8
  49. package/dist/route/routeUtils.js +0 -46
  50. package/dist/route/routesConfig.d.ts +0 -6
  51. package/dist/route/routesConfig.js +0 -125
  52. package/dist/route/routesConvention.d.ts +0 -5
  53. package/dist/route/routesConvention.js +0 -88
  54. package/dist/route/utils.d.ts +0 -8
  55. package/dist/route/utils.js +0 -59
  56. package/dist/service/command.d.ts +0 -30
  57. package/dist/service/command.js +0 -39
  58. package/dist/service/env.d.ts +0 -4
  59. package/dist/service/env.js +0 -47
  60. package/dist/service/generatePlugin.d.ts +0 -4
  61. package/dist/service/generatePlugin.js +0 -102
  62. package/dist/service/generator.d.ts +0 -71
  63. package/dist/service/generator.js +0 -40
  64. package/dist/service/hook.d.ts +0 -16
  65. package/dist/service/hook.js +0 -52
  66. package/dist/service/path.d.ts +0 -15
  67. package/dist/service/path.js +0 -55
  68. package/dist/service/plugin.d.ts +0 -61
  69. package/dist/service/plugin.js +0 -174
  70. package/dist/service/pluginAPI.d.ts +0 -49
  71. package/dist/service/pluginAPI.js +0 -233
  72. package/dist/service/service.d.ts +0 -147
  73. package/dist/service/service.js +0 -544
  74. package/dist/service/servicePlugin.d.ts +0 -3
  75. package/dist/service/servicePlugin.js +0 -37
  76. package/dist/service/telemetry.d.ts +0 -32
  77. package/dist/service/telemetry.js +0 -127
  78. package/dist/service/utils.d.ts +0 -2
  79. package/dist/service/utils.js +0 -36
  80. package/dist/types.d.ts +0 -116
  81. package/dist/types.js +0 -77
package/dist/index.d.ts CHANGED
@@ -1,6 +1,496 @@
1
- export * from './config/config';
2
- export * from './route/route';
3
- export { Generator, GeneratorType } from './service/generator';
4
- export * from './service/pluginAPI';
5
- export * from './service/service';
6
- export { Env, IAdd, IEvent, IModify, IRoute } from './types';
1
+ import { G as GeneratorContext, b as PluginHooks, Y as YwkfConfig, c as PluginConfig, e as YwkfPlugin } from './schema-BuqmN_ra.js';
2
+ export { B as BuildHooks, C as CodeInjection, D as DevServerConfig, E as EnvConfig, j as GeneratedFile, i as GeneratorHooks, H as HtmlConfig, M as MicroFrontendConfig, O as OutputConfig, P as PerformanceConfig, f as PluginContext, R as RouterConfig, g as RouterHooks, h as RuntimeHooks, S as StyleConfig, T as ToolsConfig, a as defaultConfig, d as defineConfig } from './schema-BuqmN_ra.js';
3
+ export { createBaseConfig, createDevConfig, createProdConfig, createRspackConfig } from './rspack/index.js';
4
+ export { ConventionalRouteGenerator, ConventionalRoutePlugin, ConventionalRoutePluginOptions, GeneratorOptions, RouteConfig, generateConventionalRoutes } from './router/index.js';
5
+ import { Compiler } from '@rspack/core';
6
+ export { a as AntdConfig, A as AppConfig, b as AppContextValue, L as LifecycleHooks, M as MicroAppConfig, P as ProviderConfig } from './types-BZV_2QtD.js';
7
+ export { AppContext, AppContextProvider, ErrorBoundary, RootProvider, bootstrap, createMicroApp, createProvider, getMicroAppPublicPath, isMicroAppEnv, unmount, useApp, useAppName, useBasename, useEnv, useIsDev } from './runtime/index.js';
8
+ export { PluginManager, createPlugin, definePlugin } from './plugin/index.js';
9
+ import 'react';
10
+ import 'react-router';
11
+ import 'react/jsx-runtime';
12
+
13
+ /**
14
+ * .ywkf 目录代码生成器
15
+ *
16
+ * 生成的文件:
17
+ * - index.tsx - 应用入口
18
+ * - routes.tsx - 约定式路由
19
+ * - bootstrap.tsx - 启动逻辑
20
+ * - types/routes.d.ts - 路由类型
21
+ * - types/env.d.ts - 环境变量类型
22
+ * - config.json - 配置快照
23
+ */
24
+ declare class YwkfGenerator {
25
+ private context;
26
+ private pluginHooks;
27
+ private lastGeneratedContent;
28
+ constructor(context: Omit<GeneratorContext, "outputDir"> & {
29
+ outputDir?: string;
30
+ }, pluginHooks?: PluginHooks[]);
31
+ /**
32
+ * 生成所有文件
33
+ */
34
+ generate(): Promise<void>;
35
+ /**
36
+ * 生成配置快照
37
+ */
38
+ private generateConfigSnapshot;
39
+ /**
40
+ * 生成约定式路由
41
+ */
42
+ private generateRoutes;
43
+ /**
44
+ * 生成启动文件
45
+ */
46
+ private generateBootstrapFile;
47
+ /**
48
+ * 生成入口文件
49
+ */
50
+ private generateEntryFile;
51
+ /**
52
+ * 收集插件代码注入
53
+ */
54
+ private collectInjections;
55
+ /**
56
+ * 生成插件附加文件
57
+ */
58
+ private generatePluginFiles;
59
+ /**
60
+ * 生成类型定义
61
+ */
62
+ private generateTypes;
63
+ /**
64
+ * 确保目录存在
65
+ */
66
+ private ensureDir;
67
+ /**
68
+ * 只在内容变化时写入文件(避免触发不必要的热更新)
69
+ */
70
+ private writeFileIfChanged;
71
+ /**
72
+ * 标准化内容(去掉时间戳等动态部分)
73
+ */
74
+ private normalizeContent;
75
+ }
76
+
77
+ interface YwkfGeneratorPluginOptions {
78
+ /** 项目根目录 */
79
+ cwd: string;
80
+ /** 解析后的配置 */
81
+ config: Required<YwkfConfig>;
82
+ /** 输出目录(.ywkf) */
83
+ outputDir: string;
84
+ /** 是否开发模式 */
85
+ isDev: boolean;
86
+ /** 用户配置的插件列表(PluginConfig 格式) */
87
+ pluginConfigs?: PluginConfig[];
88
+ }
89
+ /**
90
+ * .ywkf 目录生成插件
91
+ *
92
+ * 在编译前生成 .ywkf 目录下的所有文件
93
+ */
94
+ declare class YwkfGeneratorPlugin {
95
+ private options;
96
+ private hasGenerated;
97
+ private isWatching;
98
+ private generator;
99
+ private pluginHooks;
100
+ private initialized;
101
+ constructor(options: YwkfGeneratorPluginOptions);
102
+ /**
103
+ * 解析插件配置为插件实例
104
+ */
105
+ private resolvePlugin;
106
+ /**
107
+ * 初始化插件钩子
108
+ */
109
+ private initialize;
110
+ apply(compiler: Compiler): void;
111
+ /**
112
+ * 监听页面目录变化
113
+ */
114
+ private watchPages;
115
+ }
116
+
117
+ interface GarfishPluginOptions {
118
+ /** 应用名称(微前端标识) */
119
+ appName?: string;
120
+ /** 是否作为主应用 */
121
+ master?: boolean;
122
+ /** 子应用列表(主应用模式) */
123
+ apps?: {
124
+ name: string;
125
+ entry: string;
126
+ activeRule: string;
127
+ basename?: string;
128
+ }[];
129
+ /** 沙箱配置 */
130
+ sandbox?: {
131
+ /** 是否开启 JS 沙箱 */
132
+ open?: boolean;
133
+ /** 是否开启快照沙箱 */
134
+ snapshot?: boolean;
135
+ /** 样式隔离 */
136
+ strictStyleIsolation?: boolean;
137
+ };
138
+ }
139
+ /**
140
+ * Garfish 微前端插件
141
+ *
142
+ * 通过插件方式启用微前端功能,支持子应用和主应用两种模式。
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * // ywkf.config.ts - 子应用模式
147
+ * import { defineConfig, garfishPlugin } from "@4399ywkf/core";
148
+ *
149
+ * export default defineConfig({
150
+ * plugins: [
151
+ * garfishPlugin({
152
+ * appName: "sub-app",
153
+ * }),
154
+ * ],
155
+ * });
156
+ * ```
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * // ywkf.config.ts - 主应用模式
161
+ * import { defineConfig, garfishPlugin } from "@4399ywkf/core";
162
+ *
163
+ * export default defineConfig({
164
+ * plugins: [
165
+ * garfishPlugin({
166
+ * master: true,
167
+ * apps: [
168
+ * { name: "sub-app", entry: "http://localhost:3001", activeRule: "/sub" },
169
+ * ],
170
+ * }),
171
+ * ],
172
+ * });
173
+ * ```
174
+ */
175
+ declare const garfishPlugin: (options?: GarfishPluginOptions | undefined) => YwkfPlugin;
176
+
177
+ interface TailwindPluginOptions {
178
+ /**
179
+ * 自定义暗色模式选择器
180
+ * @default '&:where([data-theme="dark"], [data-theme="dark"] *)'
181
+ */
182
+ darkModeSelector?: string;
183
+ /**
184
+ * 是否生成 postcss.config.js(如果不存在)
185
+ * @default true
186
+ */
187
+ autoConfig?: boolean;
188
+ /**
189
+ * 额外的 CSS 内容(追加到 index.css 之后)
190
+ */
191
+ extraCSS?: string;
192
+ }
193
+ /**
194
+ * Tailwind CSS 插件
195
+ *
196
+ * 自动配置 Tailwind CSS:
197
+ * - 注入 `@import "tailwindcss"` 到 index.css
198
+ * - 确保 postcss.config.js 存在
199
+ * - 修改 Rspack 配置添加 postcss-loader
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * import { defineConfig, tailwindPlugin } from "@4399ywkf/core";
204
+ *
205
+ * export default defineConfig({
206
+ * plugins: [
207
+ * tailwindPlugin(),
208
+ * ],
209
+ * });
210
+ * ```
211
+ */
212
+ declare const tailwindPlugin: (options?: TailwindPluginOptions | undefined) => YwkfPlugin;
213
+
214
+ interface I18nPluginOptions {
215
+ /**
216
+ * 默认语言
217
+ * @default "zh-CN"
218
+ */
219
+ defaultLocale?: string;
220
+ /**
221
+ * 支持的语言列表
222
+ * @default ["zh-CN", "en-US"]
223
+ */
224
+ locales?: string[];
225
+ /**
226
+ * 翻译文件目录(相对于项目根目录)
227
+ * @default "locales"
228
+ */
229
+ localesDir?: string;
230
+ /**
231
+ * 默认命名空间
232
+ * @default ["common"]
233
+ */
234
+ defaultNS?: string[];
235
+ /**
236
+ * 是否自动生成初始翻译文件
237
+ * @default true
238
+ */
239
+ autoScaffold?: boolean;
240
+ }
241
+ /**
242
+ * 国际化插件
243
+ *
244
+ * 自动配置 i18next:
245
+ * - 生成 i18n 初始化代码到 .ywkf/i18n.ts
246
+ * - 注入 I18nextProvider 到启动文件
247
+ * - 自动生成初始翻译文件(可选)
248
+ *
249
+ * @example
250
+ * ```ts
251
+ * import { defineConfig, i18nPlugin } from "@4399ywkf/core";
252
+ *
253
+ * export default defineConfig({
254
+ * plugins: [
255
+ * i18nPlugin({
256
+ * defaultLocale: "zh-CN",
257
+ * locales: ["zh-CN", "en-US", "ja-JP"],
258
+ * }),
259
+ * ],
260
+ * });
261
+ * ```
262
+ */
263
+ declare const i18nPlugin: (options?: I18nPluginOptions | undefined) => YwkfPlugin;
264
+
265
+ interface ThemePluginOptions {
266
+ /**
267
+ * 是否启用暗色模式
268
+ * @default true
269
+ */
270
+ darkMode?: boolean;
271
+ /**
272
+ * 默认主题模式
273
+ * @default "auto"
274
+ */
275
+ defaultAppearance?: "light" | "dark" | "auto";
276
+ /**
277
+ * 主色调
278
+ * @default "blue"
279
+ */
280
+ primaryColor?: string;
281
+ /**
282
+ * antd 前缀
283
+ * @default "ant"
284
+ */
285
+ prefixCls?: string;
286
+ /**
287
+ * 是否启用 CSS 变量
288
+ * @default true
289
+ */
290
+ cssVar?: boolean;
291
+ /**
292
+ * 是否注入全局样式重置
293
+ * @default true
294
+ */
295
+ globalReset?: boolean;
296
+ }
297
+ /**
298
+ * 主题系统插件
299
+ *
300
+ * 基于 antd-style 提供主题管理能力:
301
+ * - 生成 ThemeProvider 包裹组件到 .ywkf/theme.tsx
302
+ * - 注入 ThemeProvider 到 bootstrap
303
+ * - 支持亮/暗色自动切换
304
+ *
305
+ * @example
306
+ * ```ts
307
+ * import { defineConfig, themePlugin } from "@4399ywkf/core";
308
+ *
309
+ * export default defineConfig({
310
+ * plugins: [
311
+ * themePlugin({
312
+ * darkMode: true,
313
+ * defaultAppearance: "auto",
314
+ * primaryColor: "blue",
315
+ * }),
316
+ * ],
317
+ * });
318
+ * ```
319
+ */
320
+ declare const themePlugin: (options?: ThemePluginOptions | undefined) => YwkfPlugin;
321
+
322
+ interface MockPluginOptions {
323
+ /** Mock 文件目录 */
324
+ mockDir?: string;
325
+ /** 是否在生产环境启用 */
326
+ enableInProd?: boolean;
327
+ /** 延迟时间(模拟网络延迟) */
328
+ delay?: number;
329
+ /** 前缀路径 */
330
+ prefix?: string;
331
+ }
332
+ /**
333
+ * Mock 数据插件
334
+ *
335
+ * @example
336
+ * ```ts
337
+ * // ywkf.config.ts
338
+ * import { mockPlugin } from "@4399ywkf/core/plugin";
339
+ *
340
+ * export default defineConfig({
341
+ * plugins: [
342
+ * mockPlugin({
343
+ * mockDir: "mock",
344
+ * prefix: "/api",
345
+ * }),
346
+ * ],
347
+ * });
348
+ * ```
349
+ *
350
+ * Mock 文件示例 (mock/user.ts):
351
+ * ```ts
352
+ * export default {
353
+ * "GET /api/users": [
354
+ * { id: 1, name: "张三" },
355
+ * ],
356
+ * "POST /api/users": (req, res) => {
357
+ * res.json({ success: true });
358
+ * },
359
+ * };
360
+ * ```
361
+ */
362
+ declare const mockPlugin: (options?: MockPluginOptions | undefined) => YwkfPlugin;
363
+
364
+ interface AnalyticsPluginOptions {
365
+ /** 是否启用构建分析 */
366
+ buildAnalysis?: boolean;
367
+ /** 是否输出构建时间 */
368
+ timing?: boolean;
369
+ /** 是否分析 bundle 大小 */
370
+ bundleSize?: boolean;
371
+ /** 大文件警告阈值(KB) */
372
+ sizeWarningThreshold?: number;
373
+ }
374
+ /**
375
+ * 构建分析插件
376
+ *
377
+ * @example
378
+ * ```ts
379
+ * import { analyticsPlugin } from "@4399ywkf/core/plugin";
380
+ *
381
+ * export default defineConfig({
382
+ * plugins: [
383
+ * analyticsPlugin({
384
+ * timing: true,
385
+ * bundleSize: true,
386
+ * sizeWarningThreshold: 500, // 500KB
387
+ * }),
388
+ * ],
389
+ * });
390
+ * ```
391
+ */
392
+ declare const analyticsPlugin: (options?: AnalyticsPluginOptions | undefined) => YwkfPlugin;
393
+
394
+ interface ReactQueryPluginOptions {
395
+ /**
396
+ * 默认 staleTime(毫秒)
397
+ * @default 5 * 60 * 1000 (5 分钟)
398
+ */
399
+ staleTime?: number;
400
+ /**
401
+ * 默认 gcTime(毫秒)
402
+ * @default 10 * 60 * 1000 (10 分钟)
403
+ */
404
+ gcTime?: number;
405
+ /**
406
+ * 默认重试次数
407
+ * @default 1
408
+ */
409
+ retry?: number | boolean;
410
+ /**
411
+ * 是否开启 React Query DevTools(仅开发模式生效)
412
+ * @default true
413
+ */
414
+ devtools?: boolean;
415
+ /**
416
+ * axios baseURL
417
+ * @default ""
418
+ */
419
+ baseURL?: string;
420
+ /**
421
+ * 请求超时时间(毫秒)
422
+ * @default 15000
423
+ */
424
+ timeout?: number;
425
+ }
426
+ /**
427
+ * React Query + Axios 请求层插件
428
+ *
429
+ * - 自动注入 QueryClientProvider
430
+ * - 生成 .ywkf/query-client.ts(QueryClient 实例 + 默认配置)
431
+ * - 生成 .ywkf/request.ts(axios 封装 + 拦截器骨架)
432
+ * - 开发模式可选开启 React Query DevTools
433
+ *
434
+ * @example
435
+ * ```ts
436
+ * import { defineConfig, reactQueryPlugin } from "@4399ywkf/core";
437
+ *
438
+ * export default defineConfig({
439
+ * plugins: [
440
+ * reactQueryPlugin({ staleTime: 5 * 60 * 1000 }),
441
+ * ],
442
+ * });
443
+ * ```
444
+ */
445
+ declare const reactQueryPlugin: (options?: ReactQueryPluginOptions | undefined) => YwkfPlugin;
446
+
447
+ interface ZustandPluginOptions {
448
+ /**
449
+ * 是否自动生成 store 脚手架(仅在 store/ 目录不存在时)
450
+ * @default true
451
+ */
452
+ scaffold?: boolean;
453
+ /**
454
+ * store 目录路径(相对于项目根目录)
455
+ * @default "store"
456
+ */
457
+ storeDir?: string;
458
+ }
459
+ /**
460
+ * Zustand 状态管理插件
461
+ *
462
+ * 采用扁平域/Slice 架构:
463
+ * - store/{domain}/slices/ 按业务域拆分
464
+ * - 每个 slice 拆为 initialState.ts + actions.ts
465
+ * - 域级 store.ts 聚合所有 slice
466
+ * - 使用 StateCreator<Store, [['zustand/devtools', never]], [], Action> 标准范式
467
+ * - 内置 devtools + subscribeWithSelector 中间件
468
+ *
469
+ * @example
470
+ * ```ts
471
+ * import { defineConfig, zustandPlugin } from "@4399ywkf/core";
472
+ *
473
+ * export default defineConfig({
474
+ * plugins: [
475
+ * zustandPlugin(),
476
+ * ],
477
+ * });
478
+ * ```
479
+ */
480
+ declare const zustandPlugin: (options?: ZustandPluginOptions | undefined) => YwkfPlugin;
481
+
482
+ /**
483
+ * 启动开发服务器
484
+ */
485
+ declare function dev(options?: {
486
+ cwd?: string;
487
+ }): Promise<void>;
488
+
489
+ /**
490
+ * 执行生产构建
491
+ */
492
+ declare function build(options?: {
493
+ cwd?: string;
494
+ }): Promise<void>;
495
+
496
+ export { type AnalyticsPluginOptions, type GarfishPluginOptions, GeneratorContext, type I18nPluginOptions, type MockPluginOptions, PluginConfig, PluginHooks, type ReactQueryPluginOptions, type TailwindPluginOptions, type ThemePluginOptions, YwkfConfig, YwkfGenerator, YwkfGeneratorPlugin, type YwkfGeneratorPluginOptions, YwkfPlugin, type ZustandPluginOptions, analyticsPlugin, build, dev, garfishPlugin, i18nPlugin, mockPlugin, reactQueryPlugin, tailwindPlugin, themePlugin, zustandPlugin };