@meng-xi/vite-plugin 0.0.2 → 0.0.4
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/README-en.md +37 -23
- package/README.md +64 -5
- package/dist/common/index.cjs +1 -0
- package/dist/common/index.d.cts +235 -0
- package/dist/common/index.d.mts +235 -0
- package/dist/common/index.d.ts +235 -0
- package/dist/common/index.mjs +1 -0
- package/dist/factory/index.cjs +1 -0
- package/dist/factory/index.d.cts +260 -0
- package/dist/factory/index.d.mts +260 -0
- package/dist/factory/index.d.ts +260 -0
- package/dist/factory/index.mjs +1 -0
- package/dist/index.cjs +1 -5
- package/dist/index.d.cts +7 -241
- package/dist/index.d.mts +7 -241
- package/dist/index.d.ts +7 -241
- package/dist/index.mjs +1 -5
- package/dist/logger/index.cjs +1 -0
- package/dist/logger/index.d.cts +1 -0
- package/dist/logger/index.d.mts +1 -0
- package/dist/logger/index.d.ts +1 -0
- package/dist/logger/index.mjs +1 -0
- package/dist/plugins/index.cjs +1 -0
- package/dist/plugins/index.d.cts +375 -0
- package/dist/plugins/index.d.mts +375 -0
- package/dist/plugins/index.d.ts +375 -0
- package/dist/plugins/index.mjs +1 -0
- package/dist/shared/vite-plugin.B3PARlU9.d.cts +119 -0
- package/dist/shared/vite-plugin.B3PARlU9.d.mts +119 -0
- package/dist/shared/vite-plugin.B3PARlU9.d.ts +119 -0
- package/dist/shared/vite-plugin.B88RyRN8.mjs +3 -0
- package/dist/shared/vite-plugin.C7isVPKg.mjs +1 -0
- package/dist/shared/vite-plugin.CiHfwMiN.d.cts +91 -0
- package/dist/shared/vite-plugin.CiHfwMiN.d.mts +91 -0
- package/dist/shared/vite-plugin.CiHfwMiN.d.ts +91 -0
- package/dist/shared/vite-plugin.D6NYITpX.cjs +1 -0
- package/dist/shared/vite-plugin.D8HTI0Ni.cjs +2 -0
- package/dist/shared/vite-plugin.Dd2ogbSe.mjs +2 -0
- package/dist/shared/vite-plugin.DqWt65U-.cjs +1 -0
- package/dist/shared/vite-plugin.HZb-1B5l.mjs +1 -0
- package/dist/shared/vite-plugin.IGZeStMa.cjs +3 -0
- package/dist/shared/vite-plugin.UkE7CdSe.d.cts +43 -0
- package/dist/shared/vite-plugin.UkE7CdSe.d.mts +43 -0
- package/dist/shared/vite-plugin.UkE7CdSe.d.ts +43 -0
- package/package.json +24 -5
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { B as BasePluginOptions, P as PluginFactory } from '../shared/vite-plugin.UkE7CdSe.js';
|
|
2
|
+
import 'vite';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 复制文件插件的配置选项接口
|
|
6
|
+
*
|
|
7
|
+
* @interface CopyFileOptions
|
|
8
|
+
*/
|
|
9
|
+
interface CopyFileOptions extends BasePluginOptions {
|
|
10
|
+
/**
|
|
11
|
+
* 源文件目录的路径
|
|
12
|
+
*
|
|
13
|
+
* @example 'src/assets'
|
|
14
|
+
*/
|
|
15
|
+
sourceDir: string;
|
|
16
|
+
/**
|
|
17
|
+
* 目标文件目录的路径
|
|
18
|
+
*
|
|
19
|
+
* @example 'dist/assets'
|
|
20
|
+
*/
|
|
21
|
+
targetDir: string;
|
|
22
|
+
/**
|
|
23
|
+
* 是否覆盖同名文件
|
|
24
|
+
*
|
|
25
|
+
* @default true
|
|
26
|
+
*/
|
|
27
|
+
overwrite?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* 是否支持递归复制
|
|
30
|
+
*
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
recursive?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* 是否启用增量复制
|
|
36
|
+
*
|
|
37
|
+
* @default true
|
|
38
|
+
*/
|
|
39
|
+
incremental?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 复制文件插件
|
|
44
|
+
*
|
|
45
|
+
* @param {CopyFileOptions} options - 插件配置选项
|
|
46
|
+
* @returns {Plugin} 一个 Vite 插件实例
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // 基本使用
|
|
51
|
+
* copyFile({
|
|
52
|
+
* sourceDir: 'src/assets',
|
|
53
|
+
* targetDir: 'dist/assets'
|
|
54
|
+
* })
|
|
55
|
+
*
|
|
56
|
+
* // 高级配置
|
|
57
|
+
* copyFile({
|
|
58
|
+
* sourceDir: 'src/static',
|
|
59
|
+
* targetDir: 'dist/static',
|
|
60
|
+
* overwrite: false,
|
|
61
|
+
* recursive: true,
|
|
62
|
+
* incremental: true,
|
|
63
|
+
* enabled: true,
|
|
64
|
+
* verbose: true,
|
|
65
|
+
* errorStrategy: 'throw'
|
|
66
|
+
* })
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* 该插件会在 Vite 构建完成后执行,将指定源目录的所有文件和子目录复制到目标目录。
|
|
71
|
+
* 支持增量复制、递归复制和覆盖控制等功能。
|
|
72
|
+
*/
|
|
73
|
+
declare const copyFile: PluginFactory<CopyFileOptions, CopyFileOptions>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 版本号格式类型
|
|
77
|
+
*
|
|
78
|
+
* @description
|
|
79
|
+
* - 'timestamp': 时间戳格式,如 '20260203153000'
|
|
80
|
+
* - 'date': 日期格式,如 '2026.02.03'
|
|
81
|
+
* - 'datetime': 日期时间格式,如 '2026.02.03.153000'
|
|
82
|
+
* - 'semver': 语义化版本格式,如 '1.0.0'
|
|
83
|
+
* - 'hash': 随机哈希格式,如 'a1b2c3d4'
|
|
84
|
+
* - 'custom': 自定义格式,需要配合 customFormat 使用
|
|
85
|
+
*/
|
|
86
|
+
type VersionFormat = 'timestamp' | 'date' | 'datetime' | 'semver' | 'hash' | 'custom';
|
|
87
|
+
/**
|
|
88
|
+
* 版本号输出类型
|
|
89
|
+
*
|
|
90
|
+
* @description
|
|
91
|
+
* - 'file': 输出到文件
|
|
92
|
+
* - 'define': 通过 Vite 的 define 注入到代码中
|
|
93
|
+
* - 'both': 同时输出到文件和注入代码
|
|
94
|
+
*/
|
|
95
|
+
type OutputType = 'file' | 'define' | 'both';
|
|
96
|
+
/**
|
|
97
|
+
* 自动生成版本号插件的配置选项接口
|
|
98
|
+
*
|
|
99
|
+
* @interface GenerateVersionOptions
|
|
100
|
+
*/
|
|
101
|
+
interface GenerateVersionOptions extends BasePluginOptions {
|
|
102
|
+
/**
|
|
103
|
+
* 版本号格式
|
|
104
|
+
*
|
|
105
|
+
* @default 'timestamp'
|
|
106
|
+
*/
|
|
107
|
+
format?: VersionFormat;
|
|
108
|
+
/**
|
|
109
|
+
* 自定义格式模板,仅当 format 为 'custom' 时有效
|
|
110
|
+
*
|
|
111
|
+
* @description 支持以下占位符:
|
|
112
|
+
* - {YYYY}: 四位年份
|
|
113
|
+
* - {MM}: 两位月份
|
|
114
|
+
* - {DD}: 两位日期
|
|
115
|
+
* - {HH}: 两位小时
|
|
116
|
+
* - {mm}: 两位分钟
|
|
117
|
+
* - {ss}: 两位秒数
|
|
118
|
+
* - {timestamp}: 时间戳
|
|
119
|
+
* - {hash}: 随机哈希
|
|
120
|
+
* - {major}: 主版本号(需配合 semverBase)
|
|
121
|
+
* - {minor}: 次版本号(需配合 semverBase)
|
|
122
|
+
* - {patch}: 补丁版本号(需配合 semverBase)
|
|
123
|
+
*
|
|
124
|
+
* @example '{YYYY}.{MM}.{DD}-{hash}'
|
|
125
|
+
*/
|
|
126
|
+
customFormat?: string;
|
|
127
|
+
/**
|
|
128
|
+
* 语义化版本基础值,用于 semver 格式
|
|
129
|
+
*
|
|
130
|
+
* @default '1.0.0'
|
|
131
|
+
*/
|
|
132
|
+
semverBase?: string;
|
|
133
|
+
/**
|
|
134
|
+
* 是否自动递增补丁版本号
|
|
135
|
+
*
|
|
136
|
+
* @default false
|
|
137
|
+
*/
|
|
138
|
+
autoIncrement?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* 输出类型
|
|
141
|
+
*
|
|
142
|
+
* @default 'file'
|
|
143
|
+
*/
|
|
144
|
+
outputType?: OutputType;
|
|
145
|
+
/**
|
|
146
|
+
* 输出文件路径(相对于构建输出目录)
|
|
147
|
+
*
|
|
148
|
+
* @default 'version.json'
|
|
149
|
+
*/
|
|
150
|
+
outputFile?: string;
|
|
151
|
+
/**
|
|
152
|
+
* 注入到代码中的全局变量名
|
|
153
|
+
*
|
|
154
|
+
* @default '__APP_VERSION__'
|
|
155
|
+
*/
|
|
156
|
+
defineName?: string;
|
|
157
|
+
/**
|
|
158
|
+
* 哈希长度
|
|
159
|
+
*
|
|
160
|
+
* @default 8
|
|
161
|
+
*/
|
|
162
|
+
hashLength?: number;
|
|
163
|
+
/**
|
|
164
|
+
* 版本号前缀
|
|
165
|
+
*
|
|
166
|
+
* @example 'v'
|
|
167
|
+
*/
|
|
168
|
+
prefix?: string;
|
|
169
|
+
/**
|
|
170
|
+
* 版本号后缀
|
|
171
|
+
*
|
|
172
|
+
* @example '-beta'
|
|
173
|
+
*/
|
|
174
|
+
suffix?: string;
|
|
175
|
+
/**
|
|
176
|
+
* 额外的版本信息,会包含在输出的 JSON 文件中
|
|
177
|
+
*/
|
|
178
|
+
extra?: Record<string, any>;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 自动生成版本号插件
|
|
183
|
+
*
|
|
184
|
+
* @param {GenerateVersionOptions} options - 插件配置选项
|
|
185
|
+
* @returns {Plugin} 一个 Vite 插件实例
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* // 基本使用 - 时间戳格式
|
|
190
|
+
* generateVersion()
|
|
191
|
+
*
|
|
192
|
+
* // 日期格式
|
|
193
|
+
* generateVersion({
|
|
194
|
+
* format: 'date'
|
|
195
|
+
* })
|
|
196
|
+
*
|
|
197
|
+
* // 语义化版本格式
|
|
198
|
+
* generateVersion({
|
|
199
|
+
* format: 'semver',
|
|
200
|
+
* semverBase: '2.0.0',
|
|
201
|
+
* prefix: 'v'
|
|
202
|
+
* })
|
|
203
|
+
*
|
|
204
|
+
* // 自定义格式
|
|
205
|
+
* generateVersion({
|
|
206
|
+
* format: 'custom',
|
|
207
|
+
* customFormat: '{YYYY}.{MM}.{DD}-{hash}',
|
|
208
|
+
* hashLength: 6
|
|
209
|
+
* })
|
|
210
|
+
*
|
|
211
|
+
* // 注入到代码中
|
|
212
|
+
* generateVersion({
|
|
213
|
+
* outputType: 'define',
|
|
214
|
+
* defineName: '__VERSION__'
|
|
215
|
+
* })
|
|
216
|
+
*
|
|
217
|
+
* // 同时输出文件和注入代码
|
|
218
|
+
* generateVersion({
|
|
219
|
+
* outputType: 'both',
|
|
220
|
+
* outputFile: 'build-info.json',
|
|
221
|
+
* defineName: '__BUILD_VERSION__',
|
|
222
|
+
* extra: {
|
|
223
|
+
* environment: 'production',
|
|
224
|
+
* author: 'MengXi Studio'
|
|
225
|
+
* }
|
|
226
|
+
* })
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
229
|
+
* @remarks
|
|
230
|
+
* 该插件会在 Vite 构建过程中自动生成版本号,支持多种格式:
|
|
231
|
+
* - timestamp: 时间戳格式 (20260203153000)
|
|
232
|
+
* - date: 日期格式 (2026.02.03)
|
|
233
|
+
* - datetime: 日期时间格式 (2026.02.03.153000)
|
|
234
|
+
* - semver: 语义化版本格式 (1.0.0)
|
|
235
|
+
* - hash: 随机哈希格式 (a1b2c3d4)
|
|
236
|
+
* - custom: 自定义格式
|
|
237
|
+
*/
|
|
238
|
+
declare const generateVersion: PluginFactory<GenerateVersionOptions, GenerateVersionOptions>;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 图标配置项接口
|
|
242
|
+
*
|
|
243
|
+
* @interface Icon
|
|
244
|
+
*/
|
|
245
|
+
interface Icon {
|
|
246
|
+
/**
|
|
247
|
+
* 图标关系类型
|
|
248
|
+
*/
|
|
249
|
+
rel: string;
|
|
250
|
+
/**
|
|
251
|
+
* 图标 URL
|
|
252
|
+
*/
|
|
253
|
+
href: string;
|
|
254
|
+
/**
|
|
255
|
+
* 图标尺寸
|
|
256
|
+
*/
|
|
257
|
+
sizes?: string;
|
|
258
|
+
/**
|
|
259
|
+
* 图标 MIME 类型
|
|
260
|
+
*/
|
|
261
|
+
type?: string;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* 图标文件复制配置选项接口
|
|
265
|
+
*
|
|
266
|
+
* @interface CopyOptions
|
|
267
|
+
*/
|
|
268
|
+
interface CopyOptions {
|
|
269
|
+
/**
|
|
270
|
+
* 图标源文件目录,用于复制图标到打包目录
|
|
271
|
+
*
|
|
272
|
+
* @example 'src/assets/icons'
|
|
273
|
+
*/
|
|
274
|
+
sourceDir: string;
|
|
275
|
+
/**
|
|
276
|
+
* 图标目标目录(打包目录),用于复制图标到打包目录
|
|
277
|
+
*
|
|
278
|
+
* @example 'dist/assets/icons'
|
|
279
|
+
*/
|
|
280
|
+
targetDir: string;
|
|
281
|
+
/**
|
|
282
|
+
* 是否覆盖同名文件
|
|
283
|
+
*
|
|
284
|
+
* @default true
|
|
285
|
+
*/
|
|
286
|
+
overwrite?: boolean;
|
|
287
|
+
/**
|
|
288
|
+
* 是否支持递归复制
|
|
289
|
+
*
|
|
290
|
+
* @default true
|
|
291
|
+
*/
|
|
292
|
+
recursive?: boolean;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* 注入网站图标链接的配置选项接口
|
|
296
|
+
*
|
|
297
|
+
* @interface InjectIcoOptions
|
|
298
|
+
*/
|
|
299
|
+
interface InjectIcoOptions extends BasePluginOptions {
|
|
300
|
+
/**
|
|
301
|
+
* 图标文件的基础路径,默认为根路径 '/'
|
|
302
|
+
*
|
|
303
|
+
* @default '/'
|
|
304
|
+
* @example '/assets'
|
|
305
|
+
*/
|
|
306
|
+
base?: string;
|
|
307
|
+
/**
|
|
308
|
+
* 图标的完整 URL,如果提供则优先使用(覆盖 base + favicon.ico)
|
|
309
|
+
*
|
|
310
|
+
* @example 'https://example.com/favicon.ico'
|
|
311
|
+
*/
|
|
312
|
+
url?: string;
|
|
313
|
+
/**
|
|
314
|
+
* 自定义的完整 link 标签 HTML,如果提供则优先使用(覆盖 url 和 base)
|
|
315
|
+
*
|
|
316
|
+
* @example '<link rel="icon" href="/favicon.svg" type="image/svg+xml" />'
|
|
317
|
+
*/
|
|
318
|
+
link?: string;
|
|
319
|
+
/**
|
|
320
|
+
* 自定义图标数组,支持多种图标格式和尺寸
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* [
|
|
324
|
+
* { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
|
|
325
|
+
* { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' },
|
|
326
|
+
* { rel: 'icon', href: '/favicon-16x16.png', sizes: '16x16', type: 'image/png' }
|
|
327
|
+
* ]
|
|
328
|
+
*/
|
|
329
|
+
icons?: Icon[];
|
|
330
|
+
/**
|
|
331
|
+
* 图标文件复制配置选项
|
|
332
|
+
*
|
|
333
|
+
* @remarks
|
|
334
|
+
* 当此对象存在时,才会开启图标文件复制功能
|
|
335
|
+
*/
|
|
336
|
+
copyOptions?: CopyOptions;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* 创建注入图标插件实例
|
|
341
|
+
*
|
|
342
|
+
* @export
|
|
343
|
+
* @param {string | InjectIcoOptions} [options] - 插件配置选项,可以是字符串形式的 base 路径或完整的配置对象
|
|
344
|
+
* @returns {Plugin} Vite 插件实例,用于在构建过程中注入图标链接到 HTML 文件
|
|
345
|
+
* @example
|
|
346
|
+
* ```typescript
|
|
347
|
+
* // 基本使用
|
|
348
|
+
* injectIco() // 使用默认配置
|
|
349
|
+
*
|
|
350
|
+
* // 使用字符串配置 base 路径
|
|
351
|
+
* injectIco('/assets')
|
|
352
|
+
*
|
|
353
|
+
* // 使用完整配置
|
|
354
|
+
* injectIco({
|
|
355
|
+
* base: '/assets',
|
|
356
|
+
* icons: [
|
|
357
|
+
* { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
|
|
358
|
+
* { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' }
|
|
359
|
+
* ],
|
|
360
|
+
* copyOptions: {
|
|
361
|
+
* sourceDir: 'src/assets/icons',
|
|
362
|
+
* targetDir: 'dist/assets/icons'
|
|
363
|
+
* }
|
|
364
|
+
* })
|
|
365
|
+
* ```
|
|
366
|
+
* @remarks
|
|
367
|
+
* 该函数创建并返回一个 Vite 插件实例,该实例会在构建过程中:
|
|
368
|
+
* 1. 将图标链接注入到 HTML 文件的 `<head>` 标签中
|
|
369
|
+
* 2. 如果配置了 copyOptions,将图标文件复制到目标目录
|
|
370
|
+
*
|
|
371
|
+
* 支持自定义图标链接、图标数组配置以及图标文件复制功能。
|
|
372
|
+
*/
|
|
373
|
+
declare const injectIco: PluginFactory<InjectIcoOptions, string | InjectIcoOptions>;
|
|
374
|
+
|
|
375
|
+
export { copyFile, generateVersion, injectIco };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{c as copyFile,g as generateVersion,i as injectIco}from"../shared/vite-plugin.Dd2ogbSe.mjs";import"../shared/vite-plugin.C7isVPKg.mjs";import"../logger/index.mjs";import"fs";import"path";import"crypto";import"../shared/vite-plugin.B88RyRN8.mjs";import"../shared/vite-plugin.HZb-1B5l.mjs";
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 构造函数参数接口
|
|
3
|
+
*/
|
|
4
|
+
interface LoggerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 插件名称
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* 是否启用日志
|
|
11
|
+
*/
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 日志工具类(单例模式)
|
|
17
|
+
* @description 全局单例日志管理器,统一管理所有插件的日志输出
|
|
18
|
+
*/
|
|
19
|
+
declare class Logger {
|
|
20
|
+
/**
|
|
21
|
+
* 单例实例
|
|
22
|
+
*/
|
|
23
|
+
private static instance;
|
|
24
|
+
/**
|
|
25
|
+
* 库名称
|
|
26
|
+
*/
|
|
27
|
+
private readonly libName;
|
|
28
|
+
/**
|
|
29
|
+
* 插件日志配置映射表
|
|
30
|
+
* @description 存储每个插件的日志开关状态
|
|
31
|
+
*/
|
|
32
|
+
private pluginConfigs;
|
|
33
|
+
/**
|
|
34
|
+
* 日志类型映射
|
|
35
|
+
*/
|
|
36
|
+
private readonly logTypes;
|
|
37
|
+
/**
|
|
38
|
+
* 私有构造函数,防止外部实例化
|
|
39
|
+
*/
|
|
40
|
+
private constructor();
|
|
41
|
+
/**
|
|
42
|
+
* 获取单例实例
|
|
43
|
+
* @returns Logger 单例实例
|
|
44
|
+
*/
|
|
45
|
+
private static getInstance;
|
|
46
|
+
/**
|
|
47
|
+
* 创建日志记录器(工厂方法)
|
|
48
|
+
* @param options 配置选项
|
|
49
|
+
* @returns Logger 单例实例
|
|
50
|
+
* @description 为插件创建日志记录器,实际返回单例实例并注册插件配置
|
|
51
|
+
*/
|
|
52
|
+
static create(options: LoggerOptions): Logger;
|
|
53
|
+
/**
|
|
54
|
+
* 注册插件日志配置
|
|
55
|
+
* @param pluginName 插件名称
|
|
56
|
+
* @param enabled 是否启用日志
|
|
57
|
+
*/
|
|
58
|
+
private registerPlugin;
|
|
59
|
+
/**
|
|
60
|
+
* 生成日志前缀
|
|
61
|
+
* @param pluginName 插件名称
|
|
62
|
+
* @returns 格式化的日志前缀
|
|
63
|
+
*/
|
|
64
|
+
private formatPrefix;
|
|
65
|
+
/**
|
|
66
|
+
* 检查插件日志是否启用
|
|
67
|
+
* @param pluginName 插件名称
|
|
68
|
+
* @returns 是否启用
|
|
69
|
+
*/
|
|
70
|
+
private isPluginEnabled;
|
|
71
|
+
/**
|
|
72
|
+
* 统一日志输出方法
|
|
73
|
+
* @param pluginName 插件名称
|
|
74
|
+
* @param type 日志类型
|
|
75
|
+
* @param message 日志消息
|
|
76
|
+
* @param data 附加数据
|
|
77
|
+
*/
|
|
78
|
+
private log;
|
|
79
|
+
/**
|
|
80
|
+
* 创建插件日志代理对象
|
|
81
|
+
* @param pluginName 插件名称
|
|
82
|
+
* @returns 插件日志代理对象
|
|
83
|
+
* @internal 供 BasePlugin 内部使用
|
|
84
|
+
*/
|
|
85
|
+
createPluginLogger(pluginName: string): PluginLogger;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 插件日志代理接口
|
|
89
|
+
* @description 为每个插件提供独立的日志接口
|
|
90
|
+
*/
|
|
91
|
+
interface PluginLogger {
|
|
92
|
+
/**
|
|
93
|
+
* 输出成功日志
|
|
94
|
+
* @param message 日志消息
|
|
95
|
+
* @param data 附加数据
|
|
96
|
+
*/
|
|
97
|
+
success(message: string, data?: any): void;
|
|
98
|
+
/**
|
|
99
|
+
* 输出信息日志
|
|
100
|
+
* @param message 日志消息
|
|
101
|
+
* @param data 附加数据
|
|
102
|
+
*/
|
|
103
|
+
info(message: string, data?: any): void;
|
|
104
|
+
/**
|
|
105
|
+
* 输出警告日志
|
|
106
|
+
* @param message 日志消息
|
|
107
|
+
* @param data 附加数据
|
|
108
|
+
*/
|
|
109
|
+
warn(message: string, data?: any): void;
|
|
110
|
+
/**
|
|
111
|
+
* 输出错误日志
|
|
112
|
+
* @param message 日志消息
|
|
113
|
+
* @param data 附加数据
|
|
114
|
+
*/
|
|
115
|
+
error(message: string, data?: any): void;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { Logger as L };
|
|
119
|
+
export type { PluginLogger as P, LoggerOptions as a };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 构造函数参数接口
|
|
3
|
+
*/
|
|
4
|
+
interface LoggerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 插件名称
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* 是否启用日志
|
|
11
|
+
*/
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 日志工具类(单例模式)
|
|
17
|
+
* @description 全局单例日志管理器,统一管理所有插件的日志输出
|
|
18
|
+
*/
|
|
19
|
+
declare class Logger {
|
|
20
|
+
/**
|
|
21
|
+
* 单例实例
|
|
22
|
+
*/
|
|
23
|
+
private static instance;
|
|
24
|
+
/**
|
|
25
|
+
* 库名称
|
|
26
|
+
*/
|
|
27
|
+
private readonly libName;
|
|
28
|
+
/**
|
|
29
|
+
* 插件日志配置映射表
|
|
30
|
+
* @description 存储每个插件的日志开关状态
|
|
31
|
+
*/
|
|
32
|
+
private pluginConfigs;
|
|
33
|
+
/**
|
|
34
|
+
* 日志类型映射
|
|
35
|
+
*/
|
|
36
|
+
private readonly logTypes;
|
|
37
|
+
/**
|
|
38
|
+
* 私有构造函数,防止外部实例化
|
|
39
|
+
*/
|
|
40
|
+
private constructor();
|
|
41
|
+
/**
|
|
42
|
+
* 获取单例实例
|
|
43
|
+
* @returns Logger 单例实例
|
|
44
|
+
*/
|
|
45
|
+
private static getInstance;
|
|
46
|
+
/**
|
|
47
|
+
* 创建日志记录器(工厂方法)
|
|
48
|
+
* @param options 配置选项
|
|
49
|
+
* @returns Logger 单例实例
|
|
50
|
+
* @description 为插件创建日志记录器,实际返回单例实例并注册插件配置
|
|
51
|
+
*/
|
|
52
|
+
static create(options: LoggerOptions): Logger;
|
|
53
|
+
/**
|
|
54
|
+
* 注册插件日志配置
|
|
55
|
+
* @param pluginName 插件名称
|
|
56
|
+
* @param enabled 是否启用日志
|
|
57
|
+
*/
|
|
58
|
+
private registerPlugin;
|
|
59
|
+
/**
|
|
60
|
+
* 生成日志前缀
|
|
61
|
+
* @param pluginName 插件名称
|
|
62
|
+
* @returns 格式化的日志前缀
|
|
63
|
+
*/
|
|
64
|
+
private formatPrefix;
|
|
65
|
+
/**
|
|
66
|
+
* 检查插件日志是否启用
|
|
67
|
+
* @param pluginName 插件名称
|
|
68
|
+
* @returns 是否启用
|
|
69
|
+
*/
|
|
70
|
+
private isPluginEnabled;
|
|
71
|
+
/**
|
|
72
|
+
* 统一日志输出方法
|
|
73
|
+
* @param pluginName 插件名称
|
|
74
|
+
* @param type 日志类型
|
|
75
|
+
* @param message 日志消息
|
|
76
|
+
* @param data 附加数据
|
|
77
|
+
*/
|
|
78
|
+
private log;
|
|
79
|
+
/**
|
|
80
|
+
* 创建插件日志代理对象
|
|
81
|
+
* @param pluginName 插件名称
|
|
82
|
+
* @returns 插件日志代理对象
|
|
83
|
+
* @internal 供 BasePlugin 内部使用
|
|
84
|
+
*/
|
|
85
|
+
createPluginLogger(pluginName: string): PluginLogger;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 插件日志代理接口
|
|
89
|
+
* @description 为每个插件提供独立的日志接口
|
|
90
|
+
*/
|
|
91
|
+
interface PluginLogger {
|
|
92
|
+
/**
|
|
93
|
+
* 输出成功日志
|
|
94
|
+
* @param message 日志消息
|
|
95
|
+
* @param data 附加数据
|
|
96
|
+
*/
|
|
97
|
+
success(message: string, data?: any): void;
|
|
98
|
+
/**
|
|
99
|
+
* 输出信息日志
|
|
100
|
+
* @param message 日志消息
|
|
101
|
+
* @param data 附加数据
|
|
102
|
+
*/
|
|
103
|
+
info(message: string, data?: any): void;
|
|
104
|
+
/**
|
|
105
|
+
* 输出警告日志
|
|
106
|
+
* @param message 日志消息
|
|
107
|
+
* @param data 附加数据
|
|
108
|
+
*/
|
|
109
|
+
warn(message: string, data?: any): void;
|
|
110
|
+
/**
|
|
111
|
+
* 输出错误日志
|
|
112
|
+
* @param message 日志消息
|
|
113
|
+
* @param data 附加数据
|
|
114
|
+
*/
|
|
115
|
+
error(message: string, data?: any): void;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { Logger as L };
|
|
119
|
+
export type { PluginLogger as P, LoggerOptions as a };
|