@vona-js/schema 0.0.1
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/LICENSE.md +21 -0
- package/README.md +1 -0
- package/dist/index.d.mts +626 -0
- package/dist/index.mjs +90 -0
- package/package.json +37 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-PRESENT asir <https://github.com/xuasir>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @lume.js/schema
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
import * as untyped0 from "untyped";
|
|
2
|
+
import { Schema, SchemaDefinition } from "untyped";
|
|
3
|
+
import { Hookable } from "hookable";
|
|
4
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
|
|
6
|
+
//#region src/config/index.d.ts
|
|
7
|
+
declare const _default: {
|
|
8
|
+
[x: string]: untyped0.InputObject | untyped0.JSValue;
|
|
9
|
+
$schema?: untyped0.Schema;
|
|
10
|
+
$resolve?: untyped0.ResolveFn;
|
|
11
|
+
$default?: any;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/types/env.d.ts
|
|
15
|
+
declare enum CodeEngineMode {
|
|
16
|
+
DEVELOPMENT = "development",
|
|
17
|
+
PRODUCTION = "production",
|
|
18
|
+
TEST = "test"
|
|
19
|
+
}
|
|
20
|
+
interface CodeEngineEnv {
|
|
21
|
+
mode: CodeEngineMode;
|
|
22
|
+
dev: boolean;
|
|
23
|
+
prod: boolean;
|
|
24
|
+
test: boolean;
|
|
25
|
+
/** 获取指定环境变量 */
|
|
26
|
+
get: (key: string) => string | undefined;
|
|
27
|
+
/** 获取所有以 prefix 开头的环境变量 */
|
|
28
|
+
getAll: () => Record<string, string>;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/types/layer.d.ts
|
|
32
|
+
declare enum ScanTypeEnum {
|
|
33
|
+
Layout = "layouts",
|
|
34
|
+
Component = "components",
|
|
35
|
+
Composable = "composables",
|
|
36
|
+
Store = "store",
|
|
37
|
+
Page = "pages",
|
|
38
|
+
Api = "api",
|
|
39
|
+
Icon = "icons",
|
|
40
|
+
Util = "utils"
|
|
41
|
+
}
|
|
42
|
+
declare enum ScanPriorityEnum {
|
|
43
|
+
Base = 0,
|
|
44
|
+
User = -9999999
|
|
45
|
+
}
|
|
46
|
+
interface ScanConfig<T extends ScanTypeEnum = ScanTypeEnum> {
|
|
47
|
+
/** 扫描模块类型 */
|
|
48
|
+
type: T;
|
|
49
|
+
/** 扫描模块工作目录 */
|
|
50
|
+
name: string;
|
|
51
|
+
/** 扫描匹配 Patterns */
|
|
52
|
+
pattern?: string | string[];
|
|
53
|
+
/** 忽略 Patterns */
|
|
54
|
+
ignore?: string[];
|
|
55
|
+
/**
|
|
56
|
+
* 这些属性(prefetch/preload)在生产环境中用于配置 webpack 如何通过其魔法注释处理带有 Lazy 前缀的组件。
|
|
57
|
+
* 更多信息请参阅 webpack 文档:https://webpack.js.org/api/module-methods/#magic-comments
|
|
58
|
+
*/
|
|
59
|
+
prefetch?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* 这些属性(prefetch/preload)在生产环境中用于配置 webpack 如何通过其魔法注释处理带有 Lazy 前缀的组件。
|
|
62
|
+
* 更多信息请参阅 webpack 文档:https://webpack.js.org/api/module-methods/#magic-comments
|
|
63
|
+
*/
|
|
64
|
+
preload?: boolean;
|
|
65
|
+
}
|
|
66
|
+
type LayerOptionScanConfig = Omit<ScanConfig, 'type'> & {
|
|
67
|
+
enabled: boolean;
|
|
68
|
+
};
|
|
69
|
+
interface LayerOptions {
|
|
70
|
+
/**
|
|
71
|
+
* 启用状态
|
|
72
|
+
* 默认开启用户最佳实践目录层扫描
|
|
73
|
+
* @default true
|
|
74
|
+
*/
|
|
75
|
+
enabled: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* 层名称
|
|
78
|
+
* @default 'app'
|
|
79
|
+
*/
|
|
80
|
+
name: string;
|
|
81
|
+
/**
|
|
82
|
+
* API 目录
|
|
83
|
+
* @default { name: 'api' }
|
|
84
|
+
*/
|
|
85
|
+
api: LayerOptionScanConfig;
|
|
86
|
+
/**
|
|
87
|
+
* 组件目录
|
|
88
|
+
* @default { name: 'components' }
|
|
89
|
+
*/
|
|
90
|
+
components: LayerOptionScanConfig;
|
|
91
|
+
/**
|
|
92
|
+
* 组合函数目录
|
|
93
|
+
* @default { name: 'composables' }
|
|
94
|
+
*/
|
|
95
|
+
composables: LayerOptionScanConfig;
|
|
96
|
+
/**
|
|
97
|
+
* 布局目录
|
|
98
|
+
* @default { name: 'layouts' }
|
|
99
|
+
*/
|
|
100
|
+
layouts: LayerOptionScanConfig;
|
|
101
|
+
/**
|
|
102
|
+
* 页面目录
|
|
103
|
+
* @default { name: 'pages' }
|
|
104
|
+
*/
|
|
105
|
+
pages: LayerOptionScanConfig;
|
|
106
|
+
/**
|
|
107
|
+
* 状态管理目录
|
|
108
|
+
* @default { name: 'store' }
|
|
109
|
+
*/
|
|
110
|
+
store: LayerOptionScanConfig;
|
|
111
|
+
/**
|
|
112
|
+
* 工具目录
|
|
113
|
+
* @default { name: 'utils' }
|
|
114
|
+
*/
|
|
115
|
+
utils: LayerOptionScanConfig;
|
|
116
|
+
/**
|
|
117
|
+
* 图标目录
|
|
118
|
+
* @default { name: 'icons' }
|
|
119
|
+
*/
|
|
120
|
+
icons: LayerOptionScanConfig;
|
|
121
|
+
}
|
|
122
|
+
interface CodeEngineLayerDefinition {
|
|
123
|
+
/** 层工作目录 */
|
|
124
|
+
cwd: string;
|
|
125
|
+
/** 层优先级 @default 0 */
|
|
126
|
+
priority?: number;
|
|
127
|
+
/** 忽略文件 */
|
|
128
|
+
ignore?: string[];
|
|
129
|
+
}
|
|
130
|
+
interface CodeEngineLayer {
|
|
131
|
+
/** 元数据 */
|
|
132
|
+
meta: {
|
|
133
|
+
/** Layer 名称 (e.g. "base") */layer: string; /** Layer 优先级 */
|
|
134
|
+
priority: number;
|
|
135
|
+
};
|
|
136
|
+
/** 路径信息 */
|
|
137
|
+
path: {
|
|
138
|
+
/** Layer 根目录绝对路径 */root: string; /** 模块完整地址 */
|
|
139
|
+
abs: string; /** 相对于 Root 的路径 (e.g. "components/Button.vue") */
|
|
140
|
+
relative: string; /** 相对扫描文件夹的地址 (e.g. "Button.vue") */
|
|
141
|
+
scan: string; /** 别名地址,相对于根目录 @cwd/xxx */
|
|
142
|
+
alias: string; /** vite 模式下 prefetch 地址 */
|
|
143
|
+
prefetch: string;
|
|
144
|
+
};
|
|
145
|
+
/** 命名变体 */
|
|
146
|
+
name: {
|
|
147
|
+
/** 原始文件名 */origin: string; /** 大驼峰 */
|
|
148
|
+
pascal: string; /** 懒加载大驼峰 */
|
|
149
|
+
lazyPascal: string; /** 中划线 */
|
|
150
|
+
kebab: string; /** 懒加载中划线 */
|
|
151
|
+
lazyKebab: string; /** 安全的变量名 */
|
|
152
|
+
safeVar: string; /** 安全的异步变量名 */
|
|
153
|
+
safeLazyVar: string; /** 独立包名 */
|
|
154
|
+
chunk: string;
|
|
155
|
+
};
|
|
156
|
+
/** 配置与加载 */
|
|
157
|
+
config: {
|
|
158
|
+
/** 导出 仅支持默认导出 */export: 'default'; /** 预请求 */
|
|
159
|
+
prefetch: boolean; /** 预加载 */
|
|
160
|
+
preload: boolean;
|
|
161
|
+
};
|
|
162
|
+
/** 运行时加载器 */
|
|
163
|
+
loader: {
|
|
164
|
+
/** 动态加载语句 */dynamicImport: () => string;
|
|
165
|
+
};
|
|
166
|
+
/** 扩展字段 */
|
|
167
|
+
[key: string]: any;
|
|
168
|
+
/** 覆盖历史:记录被当前层覆盖的下层资源 */
|
|
169
|
+
overrides?: Partial<CodeEngineLayer>[];
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/types/hooks.d.ts
|
|
173
|
+
type HookResult = Promise<void> | void;
|
|
174
|
+
interface CodeEngineHooks {
|
|
175
|
+
/**
|
|
176
|
+
* 代码引擎准备就绪
|
|
177
|
+
* @param ce 代码引擎实例
|
|
178
|
+
* @returns
|
|
179
|
+
*/
|
|
180
|
+
'ready': (ce: CodeEngine) => HookResult;
|
|
181
|
+
/**
|
|
182
|
+
* 代码引擎关闭
|
|
183
|
+
* @param ce 代码引擎实例
|
|
184
|
+
* @returns
|
|
185
|
+
*/
|
|
186
|
+
'close': (ce: CodeEngine) => HookResult;
|
|
187
|
+
/**
|
|
188
|
+
* 代码引擎模块安装之前
|
|
189
|
+
* @returns
|
|
190
|
+
*/
|
|
191
|
+
'modules:before': () => HookResult;
|
|
192
|
+
/**
|
|
193
|
+
* 代码引擎模块安装之后
|
|
194
|
+
* @returns
|
|
195
|
+
*/
|
|
196
|
+
'modules:done': () => HookResult;
|
|
197
|
+
/**
|
|
198
|
+
* 代码引擎 VFS 准备
|
|
199
|
+
* @param ce 代码引擎实例
|
|
200
|
+
* @returns
|
|
201
|
+
*/
|
|
202
|
+
'vfs:prepare': (ce: CodeEngine) => HookResult;
|
|
203
|
+
/**
|
|
204
|
+
* 代码引擎应用 VFS 生成之后
|
|
205
|
+
* @param ce 代码引擎实例
|
|
206
|
+
* @returns
|
|
207
|
+
*/
|
|
208
|
+
'vfs:generated': (ce: CodeEngine) => HookResult;
|
|
209
|
+
/**
|
|
210
|
+
* layer 扩展
|
|
211
|
+
* @param ce 代码引擎实例
|
|
212
|
+
* @returns
|
|
213
|
+
*/
|
|
214
|
+
'layer:extend': (ce: CodeEngine) => HookResult;
|
|
215
|
+
/**
|
|
216
|
+
* layer 加载完成
|
|
217
|
+
* @param ce 代码引擎实例
|
|
218
|
+
* @returns
|
|
219
|
+
*/
|
|
220
|
+
'layer:loaded': (layerMap: Record<ScanTypeEnum, CodeEngineLayer[]>, ce: CodeEngine) => HookResult;
|
|
221
|
+
/**
|
|
222
|
+
* layer 变更
|
|
223
|
+
* @param type 变更的 layer 类型
|
|
224
|
+
* @param layers 变更后的 layer 列表
|
|
225
|
+
* @param ce 代码引擎实例
|
|
226
|
+
* @returns
|
|
227
|
+
*/
|
|
228
|
+
'layer:change': (type: ScanTypeEnum, layers: CodeEngineLayer[], ce: CodeEngine) => HookResult;
|
|
229
|
+
/**
|
|
230
|
+
* 代码引擎应用写入 vite 配置文件
|
|
231
|
+
* @param ce 代码引擎实例
|
|
232
|
+
* @returns
|
|
233
|
+
*/
|
|
234
|
+
'vite:config': (ce: CodeEngine) => HookResult;
|
|
235
|
+
/**
|
|
236
|
+
* 代码引擎应用写入 rspack 配置文件
|
|
237
|
+
* @param ce 代码引擎实例
|
|
238
|
+
* @returns
|
|
239
|
+
*/
|
|
240
|
+
'rspack:config': (ce: CodeEngine) => HookResult;
|
|
241
|
+
/**
|
|
242
|
+
* 允许扩展默认配置。
|
|
243
|
+
* @param schemas 要扩展的配置
|
|
244
|
+
* @returns void
|
|
245
|
+
*/
|
|
246
|
+
'schema:extend': (schemas: SchemaDefinition[]) => void;
|
|
247
|
+
/**
|
|
248
|
+
* 允许扩展已解析的配置。
|
|
249
|
+
* @param schema 配置对象
|
|
250
|
+
* @returns void
|
|
251
|
+
*/
|
|
252
|
+
'schema:resolved': (schema: Schema) => void;
|
|
253
|
+
/**
|
|
254
|
+
* 在写入给定配置之前调用。
|
|
255
|
+
* @param schema 配置对象
|
|
256
|
+
* @returns void
|
|
257
|
+
*/
|
|
258
|
+
'schema:beforeWrite': (schema: Schema) => void;
|
|
259
|
+
/**
|
|
260
|
+
* 在配置写入后调用。
|
|
261
|
+
* @returns void
|
|
262
|
+
*/
|
|
263
|
+
'schema:written': () => void;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* 代码引擎内部钩子名称
|
|
267
|
+
*/
|
|
268
|
+
type CodeEngineInternalHookName = keyof CodeEngineHooks;
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/types/reactive.d.ts
|
|
271
|
+
/**
|
|
272
|
+
* 注入键
|
|
273
|
+
* 用于标识一个依赖项
|
|
274
|
+
* 使用 intersection type 而不是 interface extends Symbol 以避免 TS 限制
|
|
275
|
+
*/
|
|
276
|
+
type InjectionKey<T> = symbol & {
|
|
277
|
+
readonly description?: string;
|
|
278
|
+
readonly _?: T;
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* 副作用函数
|
|
282
|
+
*/
|
|
283
|
+
type EffectFn = () => any;
|
|
284
|
+
/**
|
|
285
|
+
* 响应式上下文接口
|
|
286
|
+
* CodeEngine 实现此接口以提供响应式能力
|
|
287
|
+
*/
|
|
288
|
+
interface ReactiveContext {
|
|
289
|
+
/**
|
|
290
|
+
* 供给数据
|
|
291
|
+
* @param key 类型化 Key
|
|
292
|
+
* @param value 值或 Getter 函数
|
|
293
|
+
*/
|
|
294
|
+
provide: <T>(key: InjectionKey<T>, value: T | (() => T)) => void;
|
|
295
|
+
/**
|
|
296
|
+
* 获取数据 (注入)
|
|
297
|
+
* 自动收集依赖
|
|
298
|
+
* @param key 类型化 Key
|
|
299
|
+
*/
|
|
300
|
+
get: <T>(key: InjectionKey<T>) => T | undefined;
|
|
301
|
+
/**
|
|
302
|
+
* 通知变更
|
|
303
|
+
* @param key 类型化 Key
|
|
304
|
+
*/
|
|
305
|
+
notify: (key: InjectionKey<any>) => void;
|
|
306
|
+
/**
|
|
307
|
+
* 运行副作用
|
|
308
|
+
* @param fn 副作用函数
|
|
309
|
+
*/
|
|
310
|
+
runEffect: (fn: EffectFn) => any;
|
|
311
|
+
}
|
|
312
|
+
//#endregion
|
|
313
|
+
//#region src/types/vfs.d.ts
|
|
314
|
+
/**
|
|
315
|
+
* 节点类型枚举
|
|
316
|
+
* - reference: 引用模式,指向物理磁盘路径
|
|
317
|
+
* - entity: 实体模式,由函数/字符串生成的内存内容
|
|
318
|
+
*/
|
|
319
|
+
type VfsKind = 'reference' | 'entity';
|
|
320
|
+
/**
|
|
321
|
+
* VFS 数据源类型
|
|
322
|
+
* - string: 物理路径(引用模式)或静态内容(实体模式)
|
|
323
|
+
* - function: 生成器函数(实体模式)
|
|
324
|
+
*/
|
|
325
|
+
type VfsSource = string | (() => string | Promise<string>);
|
|
326
|
+
interface VfsRecord {
|
|
327
|
+
/** 虚拟路径 (例如 /components/Button.vue) */
|
|
328
|
+
path: string;
|
|
329
|
+
/** 节点类型 */
|
|
330
|
+
kind: VfsKind;
|
|
331
|
+
/** 数据源 */
|
|
332
|
+
source: VfsSource;
|
|
333
|
+
/** 唯一标识 (用于去重/追踪) */
|
|
334
|
+
key: string;
|
|
335
|
+
/** Layer 名称 (e.g., 'app', 'base') */
|
|
336
|
+
layer?: string;
|
|
337
|
+
/** 原始物理路径 (用于 watcher 关联) */
|
|
338
|
+
originalPath?: string;
|
|
339
|
+
/** 扫描时使用的 pattern */
|
|
340
|
+
pattern?: string;
|
|
341
|
+
/** 来源方式 */
|
|
342
|
+
sourceType: 'mount' | 'write' | 'template';
|
|
343
|
+
/** 优先级 */
|
|
344
|
+
priority: number;
|
|
345
|
+
/** Scope 名称 */
|
|
346
|
+
scope?: string;
|
|
347
|
+
/** 依赖的文件模式(用于实体模式自动重算) */
|
|
348
|
+
watch?: string[];
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* VFS 模板定义
|
|
352
|
+
*/
|
|
353
|
+
interface VfsTemplate {
|
|
354
|
+
/** 虚拟路径 */
|
|
355
|
+
path: string;
|
|
356
|
+
/** 依赖的文件模式 */
|
|
357
|
+
watch?: string[];
|
|
358
|
+
/** 生成器函数 */
|
|
359
|
+
get: (ctx: VfsTemplateContext) => string | Promise<string>;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* 模板生成上下文
|
|
363
|
+
*/
|
|
364
|
+
interface VfsTemplateContext {
|
|
365
|
+
/** VFS 实例引用 */
|
|
366
|
+
vfs: VFS;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* VFS Scope 上下文
|
|
370
|
+
*/
|
|
371
|
+
interface VfsScopeContext {
|
|
372
|
+
/** Scope 名称 (通常对应 Layer 名称) */
|
|
373
|
+
name?: string;
|
|
374
|
+
/** 基础优先级 */
|
|
375
|
+
priority?: number;
|
|
376
|
+
/**
|
|
377
|
+
* 创建子 Scope
|
|
378
|
+
*/
|
|
379
|
+
scope: (options: {
|
|
380
|
+
name?: string;
|
|
381
|
+
priority?: number;
|
|
382
|
+
}) => VfsScopeContext;
|
|
383
|
+
/**
|
|
384
|
+
* 挂载单个文件(引用模式)
|
|
385
|
+
* @param virtualPath 虚拟路径
|
|
386
|
+
* @param physicalPath 物理路径
|
|
387
|
+
* @param options 元数据选项
|
|
388
|
+
*/
|
|
389
|
+
mount: (virtualPath: string, physicalPath: string, options?: {
|
|
390
|
+
priority?: number;
|
|
391
|
+
originalPath?: string;
|
|
392
|
+
pattern?: string;
|
|
393
|
+
}) => void;
|
|
394
|
+
/**
|
|
395
|
+
* 写入单个文件(实体模式)
|
|
396
|
+
* @param virtualPath 虚拟路径
|
|
397
|
+
* @param content 文件内容或生成器
|
|
398
|
+
* @param priority 优先级覆盖(可选)
|
|
399
|
+
*/
|
|
400
|
+
write: (virtualPath: string, content: VfsSource, priority?: number) => void;
|
|
401
|
+
/**
|
|
402
|
+
* 添加模板文件(实体模式 + 响应式依赖)
|
|
403
|
+
* @param template 模板定义
|
|
404
|
+
*/
|
|
405
|
+
addTemplate: (template: VfsTemplate) => void;
|
|
406
|
+
/**
|
|
407
|
+
* 移除文件
|
|
408
|
+
* @param virtualPath 虚拟路径
|
|
409
|
+
*/
|
|
410
|
+
remove: (virtualPath: string) => void;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* VFS 事件钩子
|
|
414
|
+
*/
|
|
415
|
+
interface VfsHooks {
|
|
416
|
+
/**
|
|
417
|
+
* 文件添加事件
|
|
418
|
+
*/
|
|
419
|
+
'file:added': (record: VfsRecord) => void | Promise<void>;
|
|
420
|
+
/**
|
|
421
|
+
* 文件更新事件
|
|
422
|
+
*/
|
|
423
|
+
'file:updated': (record: VfsRecord) => void | Promise<void>;
|
|
424
|
+
/**
|
|
425
|
+
* 文件移除事件
|
|
426
|
+
*/
|
|
427
|
+
'file:removed': (path: string) => void | Promise<void>;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* VFS 调试信息
|
|
431
|
+
*/
|
|
432
|
+
interface VfsInspectResult {
|
|
433
|
+
/** 虚拟路径 */
|
|
434
|
+
path: string;
|
|
435
|
+
/** 节点类型 */
|
|
436
|
+
kind: VfsKind;
|
|
437
|
+
/** 当前生效的数据源 */
|
|
438
|
+
activeSource: VfsSource;
|
|
439
|
+
/** 当前生效的优先级 */
|
|
440
|
+
activePriority: number;
|
|
441
|
+
/** 当前生效的 Scope */
|
|
442
|
+
activeScope?: string;
|
|
443
|
+
/** 历史记录(所有注册过的源) */
|
|
444
|
+
history: Array<{
|
|
445
|
+
scope?: string;
|
|
446
|
+
source: VfsSource;
|
|
447
|
+
priority: number;
|
|
448
|
+
}>;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* VFS 主接口
|
|
452
|
+
*/
|
|
453
|
+
interface VFS extends VfsScopeContext {
|
|
454
|
+
/** 事件钩子系统 */
|
|
455
|
+
hooks: Hookable<VfsHooks>;
|
|
456
|
+
/**
|
|
457
|
+
* 读取单个文件
|
|
458
|
+
* @param path 虚拟路径
|
|
459
|
+
* @returns 文件记录,不存在时返回 undefined
|
|
460
|
+
*/
|
|
461
|
+
read: (path: string) => VfsRecord | undefined;
|
|
462
|
+
/**
|
|
463
|
+
* 模式匹配查询 (基于内存中的虚拟文件)
|
|
464
|
+
* @param pattern Glob 模式
|
|
465
|
+
* @returns 匹配的文件记录数组
|
|
466
|
+
*/
|
|
467
|
+
glob: (pattern: string) => VfsRecord[];
|
|
468
|
+
/**
|
|
469
|
+
* 查看文件调试信息
|
|
470
|
+
* @param path 虚拟路径
|
|
471
|
+
* @returns 调试信息,不存在时返回 undefined
|
|
472
|
+
*/
|
|
473
|
+
inspect: (path: string) => VfsInspectResult | undefined;
|
|
474
|
+
/**
|
|
475
|
+
* 应用 VFS Setup
|
|
476
|
+
* @param setup VFS Setup 函数
|
|
477
|
+
*/
|
|
478
|
+
use: (setup: VfsSetup) => void | Promise<void>;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* VFS 创建选项
|
|
482
|
+
*/
|
|
483
|
+
interface VfsOptions {
|
|
484
|
+
/** 根目录 */
|
|
485
|
+
root: string;
|
|
486
|
+
/** 是否为开发模式 */
|
|
487
|
+
isDev?: boolean;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* VFS Setup 函数 (原 VfsModule)
|
|
491
|
+
* 负责执行 IO 扫描并注册文件
|
|
492
|
+
*/
|
|
493
|
+
type VfsSetup = (ctx: VfsScopeContext) => void | Promise<void>;
|
|
494
|
+
/**
|
|
495
|
+
* VFS Setup 定义辅助函数类型
|
|
496
|
+
*/
|
|
497
|
+
type DefineVfsSetup = (setup: VfsSetup) => VfsSetup;
|
|
498
|
+
//#endregion
|
|
499
|
+
//#region src/types/engine.d.ts
|
|
500
|
+
interface CodeEngine extends ReactiveContext {
|
|
501
|
+
/** 名称 */
|
|
502
|
+
__name: string;
|
|
503
|
+
/** 版本 */
|
|
504
|
+
__version: string;
|
|
505
|
+
/** 当前运行的 CodeEngine 模块实例的 AsyncLocalStorage */
|
|
506
|
+
__asyncLocalStorageModule: AsyncLocalStorage<CodeEngineModule>;
|
|
507
|
+
/** 依赖 */
|
|
508
|
+
__dependencies?: Set<string>;
|
|
509
|
+
/** 加载后的配置 */
|
|
510
|
+
options: CodeEngineOptions;
|
|
511
|
+
/** 钩子 */
|
|
512
|
+
hooks: Hookable<CodeEngineHooks>;
|
|
513
|
+
hook: CodeEngine['hooks']['hook'];
|
|
514
|
+
/** 触发钩子 */
|
|
515
|
+
callHook: CodeEngine['hooks']['callHook'];
|
|
516
|
+
addHooks: CodeEngine['hooks']['addHooks'];
|
|
517
|
+
/** 基于上下文运行 */
|
|
518
|
+
runWithContext: <T extends (...args: any[]) => any>(fn: T) => ReturnType<T>;
|
|
519
|
+
/** 虚拟文件系统 */
|
|
520
|
+
vfs: VFS;
|
|
521
|
+
/** 环境 */
|
|
522
|
+
env: CodeEngineEnv;
|
|
523
|
+
/** 生命周期 */
|
|
524
|
+
ready: () => Promise<void>;
|
|
525
|
+
close: () => Promise<void>;
|
|
526
|
+
}
|
|
527
|
+
//#endregion
|
|
528
|
+
//#region src/types/module.d.ts
|
|
529
|
+
interface ModuleMeta {
|
|
530
|
+
/** 模块名称 */
|
|
531
|
+
name: string;
|
|
532
|
+
/** 模块版本 */
|
|
533
|
+
version: string;
|
|
534
|
+
/** 配置文件 key */
|
|
535
|
+
configKey?: string;
|
|
536
|
+
[key: string]: unknown;
|
|
537
|
+
}
|
|
538
|
+
/** 模块选项 */
|
|
539
|
+
type ModuleOptions = Record<string, any>;
|
|
540
|
+
/** 模块安装结果 */
|
|
541
|
+
interface ModuleSetupInstallResult {
|
|
542
|
+
/**
|
|
543
|
+
* 初始设置的定时信息
|
|
544
|
+
*/
|
|
545
|
+
timings?: {
|
|
546
|
+
/** 模块设置所花费的总时间 */setup?: number;
|
|
547
|
+
[key: string]: number | undefined;
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
type Awaitable<T> = T | Promise<T>;
|
|
551
|
+
type ModuleSetupReturn = Awaitable<false | void | ModuleSetupInstallResult>;
|
|
552
|
+
/** 模块定义 */
|
|
553
|
+
interface ModuleDefinition<TOptions extends ModuleOptions, TOptionsDefaults extends Partial<TOptions>> {
|
|
554
|
+
meta: ModuleMeta;
|
|
555
|
+
defaults?: TOptionsDefaults | ((ce: CodeEngine) => Awaitable<TOptionsDefaults>);
|
|
556
|
+
schema?: TOptions;
|
|
557
|
+
hooks?: Partial<CodeEngineHooks>;
|
|
558
|
+
setup?: (this: void, resolvedOptions: TOptions, ce: CodeEngine) => ModuleSetupReturn;
|
|
559
|
+
}
|
|
560
|
+
/** 实例 */
|
|
561
|
+
interface CodeEngineModule<TOptions extends ModuleOptions = ModuleOptions> {
|
|
562
|
+
(this: void, resolvedOptions: TOptions, ce: CodeEngine): ModuleSetupReturn;
|
|
563
|
+
getOptions?: (inlineOptions?: Partial<TOptions>, ce?: CodeEngine) => Promise<TOptions>;
|
|
564
|
+
getMeta?: () => Promise<ModuleMeta & {
|
|
565
|
+
configKey: string;
|
|
566
|
+
}>;
|
|
567
|
+
}
|
|
568
|
+
//#endregion
|
|
569
|
+
//#region src/types/schema.d.ts
|
|
570
|
+
interface ConfigSchema {
|
|
571
|
+
/** 配置继承 */
|
|
572
|
+
extends: string;
|
|
573
|
+
/** 扩展模块 */
|
|
574
|
+
modules: Array<CodeEngineModule | string | [CodeEngineModule, ModuleOptions] | [string, ModuleOptions]>;
|
|
575
|
+
/** debug 模式 */
|
|
576
|
+
debug: boolean;
|
|
577
|
+
/** 层配置 */
|
|
578
|
+
layers: LayerOptions;
|
|
579
|
+
/**
|
|
580
|
+
* 配置文件路径
|
|
581
|
+
* @private
|
|
582
|
+
*/
|
|
583
|
+
__configFile: string;
|
|
584
|
+
}
|
|
585
|
+
//#endregion
|
|
586
|
+
//#region src/types/config.d.ts
|
|
587
|
+
type DeepPartial<T> = T extends Function ? T : T extends Record<string, any> ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
|
|
588
|
+
interface CodeEngineConfig extends DeepPartial<ConfigSchema> {
|
|
589
|
+
/** 配置 */
|
|
590
|
+
$schema?: SchemaDefinition;
|
|
591
|
+
}
|
|
592
|
+
interface CodeEngineOptions extends ConfigSchema {
|
|
593
|
+
/** 项目根目录 */
|
|
594
|
+
__rootDir: string;
|
|
595
|
+
/** 模式 */
|
|
596
|
+
__mode: CodeEngineMode;
|
|
597
|
+
/** 当前命令 */
|
|
598
|
+
__command?: {
|
|
599
|
+
name: string;
|
|
600
|
+
args: Record<string, any>;
|
|
601
|
+
};
|
|
602
|
+
/**
|
|
603
|
+
* 代码工程的层
|
|
604
|
+
*/
|
|
605
|
+
__layers: CodeEngineLayerDefinition[];
|
|
606
|
+
/**
|
|
607
|
+
* 内部模块
|
|
608
|
+
*/
|
|
609
|
+
__internalModules: Array<CodeEngineModule | [CodeEngineModule, ModuleOptions]>;
|
|
610
|
+
/**
|
|
611
|
+
* 加载过的模块
|
|
612
|
+
*/
|
|
613
|
+
__requiredModules: Record<string, boolean>;
|
|
614
|
+
/**
|
|
615
|
+
* 安装过的模块
|
|
616
|
+
*/
|
|
617
|
+
__installedModules: Array<{
|
|
618
|
+
meta: ModuleMeta;
|
|
619
|
+
module: CodeEngineModule;
|
|
620
|
+
timings: ModuleSetupInstallResult['timings'];
|
|
621
|
+
}>;
|
|
622
|
+
/** 配置 */
|
|
623
|
+
$schema?: SchemaDefinition;
|
|
624
|
+
}
|
|
625
|
+
//#endregion
|
|
626
|
+
export { CodeEngine, CodeEngineConfig, _default as CodeEngineConfigSchema, CodeEngineEnv, CodeEngineHooks, CodeEngineInternalHookName, CodeEngineLayer, CodeEngineLayerDefinition, CodeEngineMode, CodeEngineModule, CodeEngineOptions, ConfigSchema, DefineVfsSetup, EffectFn, HookResult, InjectionKey, LayerOptionScanConfig, LayerOptions, ModuleDefinition, ModuleMeta, ModuleOptions, ModuleSetupInstallResult, ModuleSetupReturn, ReactiveContext, ScanConfig, ScanPriorityEnum, ScanTypeEnum, VFS, VfsHooks, VfsInspectResult, VfsKind, VfsOptions, VfsRecord, VfsScopeContext, VfsSetup, VfsSource, VfsTemplate, VfsTemplateContext };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
//#region src/utils/def.ts
|
|
2
|
+
function defineResolvers(config) {
|
|
3
|
+
return config;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/config/common.ts
|
|
8
|
+
var common_default = defineResolvers({
|
|
9
|
+
extends: void 0,
|
|
10
|
+
modules: [],
|
|
11
|
+
debug: false,
|
|
12
|
+
__configFile: void 0
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/config/layer.ts
|
|
17
|
+
var layer_default = defineResolvers({ layers: {
|
|
18
|
+
enabled: true,
|
|
19
|
+
name: "app",
|
|
20
|
+
api: {
|
|
21
|
+
enabled: true,
|
|
22
|
+
name: "api"
|
|
23
|
+
},
|
|
24
|
+
components: {
|
|
25
|
+
enabled: true,
|
|
26
|
+
name: "components"
|
|
27
|
+
},
|
|
28
|
+
composables: {
|
|
29
|
+
enabled: true,
|
|
30
|
+
name: "composables"
|
|
31
|
+
},
|
|
32
|
+
layouts: {
|
|
33
|
+
enabled: true,
|
|
34
|
+
name: "layouts"
|
|
35
|
+
},
|
|
36
|
+
pages: {
|
|
37
|
+
enabled: true,
|
|
38
|
+
name: "pages"
|
|
39
|
+
},
|
|
40
|
+
store: {
|
|
41
|
+
enabled: true,
|
|
42
|
+
name: "store"
|
|
43
|
+
},
|
|
44
|
+
utils: {
|
|
45
|
+
enabled: true,
|
|
46
|
+
name: "utils"
|
|
47
|
+
},
|
|
48
|
+
icons: {
|
|
49
|
+
enabled: true,
|
|
50
|
+
name: "icons"
|
|
51
|
+
}
|
|
52
|
+
} });
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/config/index.ts
|
|
56
|
+
var config_default = {
|
|
57
|
+
...common_default,
|
|
58
|
+
...layer_default
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/types/env.ts
|
|
63
|
+
let CodeEngineMode = /* @__PURE__ */ function(CodeEngineMode) {
|
|
64
|
+
CodeEngineMode["DEVELOPMENT"] = "development";
|
|
65
|
+
CodeEngineMode["PRODUCTION"] = "production";
|
|
66
|
+
CodeEngineMode["TEST"] = "test";
|
|
67
|
+
return CodeEngineMode;
|
|
68
|
+
}({});
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/types/layer.ts
|
|
72
|
+
let ScanTypeEnum = /* @__PURE__ */ function(ScanTypeEnum) {
|
|
73
|
+
ScanTypeEnum["Layout"] = "layouts";
|
|
74
|
+
ScanTypeEnum["Component"] = "components";
|
|
75
|
+
ScanTypeEnum["Composable"] = "composables";
|
|
76
|
+
ScanTypeEnum["Store"] = "store";
|
|
77
|
+
ScanTypeEnum["Page"] = "pages";
|
|
78
|
+
ScanTypeEnum["Api"] = "api";
|
|
79
|
+
ScanTypeEnum["Icon"] = "icons";
|
|
80
|
+
ScanTypeEnum["Util"] = "utils";
|
|
81
|
+
return ScanTypeEnum;
|
|
82
|
+
}({});
|
|
83
|
+
let ScanPriorityEnum = /* @__PURE__ */ function(ScanPriorityEnum) {
|
|
84
|
+
ScanPriorityEnum[ScanPriorityEnum["Base"] = 0] = "Base";
|
|
85
|
+
ScanPriorityEnum[ScanPriorityEnum["User"] = -9999999] = "User";
|
|
86
|
+
return ScanPriorityEnum;
|
|
87
|
+
}({});
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { config_default as CodeEngineConfigSchema, CodeEngineMode, ScanPriorityEnum, ScanTypeEnum };
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vona-js/schema",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "_description_",
|
|
6
|
+
"author": "xuasir",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/xuasir/code-engine.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": "https://github.com/xuasir/code-engine/issues",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"code-engine",
|
|
15
|
+
"vite",
|
|
16
|
+
"web",
|
|
17
|
+
"vue"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./dist/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.mjs",
|
|
24
|
+
"module": "./dist/index.mjs",
|
|
25
|
+
"types": "./dist/index.d.mts",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"hookable": "^5.5.3",
|
|
31
|
+
"untyped": "^2.0.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsdown",
|
|
35
|
+
"dev": "tsdown --watch"
|
|
36
|
+
}
|
|
37
|
+
}
|