@meng-xi/vite-plugin 0.0.3 → 0.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.
Files changed (38) hide show
  1. package/README-en.md +182 -150
  2. package/README.md +182 -84
  3. package/dist/common/index.cjs +1 -1
  4. package/dist/common/index.d.cts +207 -6
  5. package/dist/common/index.d.mts +207 -6
  6. package/dist/common/index.d.ts +207 -6
  7. package/dist/common/index.mjs +1 -1
  8. package/dist/factory/index.cjs +1 -1
  9. package/dist/factory/index.mjs +1 -1
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.d.cts +2 -2
  12. package/dist/index.d.mts +2 -2
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.mjs +1 -1
  15. package/dist/logger/index.cjs +1 -1
  16. package/dist/logger/index.mjs +1 -1
  17. package/dist/plugins/index.cjs +1 -1
  18. package/dist/plugins/index.d.cts +296 -1
  19. package/dist/plugins/index.d.mts +296 -1
  20. package/dist/plugins/index.d.ts +296 -1
  21. package/dist/plugins/index.mjs +1 -1
  22. package/dist/shared/vite-plugin.B88RyRN8.mjs +3 -0
  23. package/dist/shared/vite-plugin.BZsetDCm.cjs +1 -0
  24. package/dist/shared/vite-plugin.C7isVPKg.mjs +1 -0
  25. package/dist/shared/vite-plugin.CS9a5kjK.mjs +36 -0
  26. package/dist/shared/vite-plugin.CgnG5_UX.cjs +36 -0
  27. package/dist/shared/vite-plugin.DqWt65U-.cjs +1 -0
  28. package/dist/shared/vite-plugin.IGZeStMa.cjs +3 -0
  29. package/dist/shared/vite-plugin.YvjM8LxW.mjs +1 -0
  30. package/package.json +72 -72
  31. package/dist/shared/vite-plugin.BT1oHRKK.cjs +0 -1
  32. package/dist/shared/vite-plugin.BTKhc7n7.cjs +0 -3
  33. package/dist/shared/vite-plugin.BZqhBDYR.mjs +0 -1
  34. package/dist/shared/vite-plugin.Bn8mcCzy.cjs +0 -3
  35. package/dist/shared/vite-plugin.CY2ydccp.mjs +0 -3
  36. package/dist/shared/vite-plugin.ClHiVXD6.mjs +0 -1
  37. package/dist/shared/vite-plugin.DSRKYuae.mjs +0 -3
  38. package/dist/shared/vite-plugin.DrSzERYS.cjs +0 -1
@@ -72,6 +72,301 @@ interface CopyFileOptions extends BasePluginOptions {
72
72
  */
73
73
  declare const copyFile: PluginFactory<CopyFileOptions, CopyFileOptions>;
74
74
 
75
+ /**
76
+ * 输出文件格式类型
77
+ */
78
+ type OutputFormat = 'ts' | 'js';
79
+ /**
80
+ * 路由名称生成策略
81
+ */
82
+ type NameStrategy = 'path' | 'camelCase' | 'pascalCase' | 'custom';
83
+ /**
84
+ * 生成路由配置插件选项
85
+ */
86
+ interface GenerateRouterOptions extends BasePluginOptions {
87
+ /**
88
+ * pages.json 文件路径(相对于项目根目录)
89
+ *
90
+ * @default 'src/pages.json'
91
+ */
92
+ pagesJsonPath?: string;
93
+ /**
94
+ * 输出文件路径(相对于项目根目录)
95
+ *
96
+ * @default 'src/router.config.ts'
97
+ */
98
+ outputPath?: string;
99
+ /**
100
+ * 输出文件格式
101
+ *
102
+ * @default 'ts'
103
+ */
104
+ outputFormat?: OutputFormat;
105
+ /**
106
+ * 路由名称生成策略
107
+ *
108
+ * @default 'camelCase'
109
+ */
110
+ nameStrategy?: NameStrategy;
111
+ /**
112
+ * 自定义路由名称生成函数
113
+ *
114
+ * @param path - 页面路径
115
+ * @returns 路由名称
116
+ */
117
+ customNameGenerator?: (path: string) => string;
118
+ /**
119
+ * 是否包含子包路由
120
+ *
121
+ * @default true
122
+ */
123
+ includeSubPackages?: boolean;
124
+ /**
125
+ * 是否监听 pages.json 变化并自动重新生成
126
+ *
127
+ * @default true
128
+ */
129
+ watch?: boolean;
130
+ /**
131
+ * 额外的元信息字段映射
132
+ *
133
+ * @description 将 pages.json 中 style 的字段映射到 meta 中
134
+ * @example { 'navigationBarTitleText': 'title', 'requireAuth': 'requireAuth' }
135
+ */
136
+ metaMapping?: Record<string, string>;
137
+ /**
138
+ * 是否导出类型定义
139
+ *
140
+ * @default true
141
+ */
142
+ exportTypes?: boolean;
143
+ /**
144
+ * 是否保留用户对 routes 配置的修改
145
+ *
146
+ * @description 开启后,用户在 routes 数组中修改的字段将被保留
147
+ * @default true
148
+ */
149
+ preserveRouteChanges?: boolean;
150
+ }
151
+
152
+ /**
153
+ * 生成路由配置插件
154
+ *
155
+ * @param {GenerateRouterOptions} options - 插件配置选项
156
+ * @returns {Plugin} 一个 Vite 插件实例
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * // 基本使用 - 使用默认配置
161
+ * generateRouter()
162
+ *
163
+ * // 自定义 pages.json 路径
164
+ * generateRouter({
165
+ * pagesJsonPath: 'pages.json'
166
+ * })
167
+ *
168
+ * // 输出 JavaScript 文件
169
+ * generateRouter({
170
+ * outputFormat: 'js',
171
+ * outputPath: 'src/router.config.js'
172
+ * })
173
+ *
174
+ * // 使用帕斯卡命名策略
175
+ * generateRouter({
176
+ * nameStrategy: 'pascalCase'
177
+ * })
178
+ *
179
+ * // 自定义路由名称生成
180
+ * generateRouter({
181
+ * nameStrategy: 'custom',
182
+ * customNameGenerator: (path) => `route_${path.replace(/\//g, '_')}`
183
+ * })
184
+ *
185
+ * // 自定义元信息映射
186
+ * generateRouter({
187
+ * metaMapping: {
188
+ * navigationBarTitleText: 'title',
189
+ * requireAuth: 'requireAuth',
190
+ * customField: 'custom'
191
+ * }
192
+ * })
193
+ * ```
194
+ *
195
+ * @remarks
196
+ * 该插件会读取 uni-app 项目的 pages.json 文件,自动生成路由配置文件:
197
+ * - 支持主包和子包页面
198
+ * - 自动识别 tabBar 页面
199
+ * - 支持多种路由名称生成策略
200
+ * - 支持自定义元信息字段映射
201
+ * - 开发模式下自动监听 pages.json 变化并重新生成
202
+ */
203
+ declare const generateRouter: PluginFactory<GenerateRouterOptions, GenerateRouterOptions>;
204
+
205
+ /**
206
+ * 版本号格式类型
207
+ *
208
+ * @description
209
+ * - 'timestamp': 时间戳格式,如 '20260203153000'
210
+ * - 'date': 日期格式,如 '2026.02.03'
211
+ * - 'datetime': 日期时间格式,如 '2026.02.03.153000'
212
+ * - 'semver': 语义化版本格式,如 '1.0.0'
213
+ * - 'hash': 随机哈希格式,如 'a1b2c3d4'
214
+ * - 'custom': 自定义格式,需要配合 customFormat 使用
215
+ */
216
+ type VersionFormat = 'timestamp' | 'date' | 'datetime' | 'semver' | 'hash' | 'custom';
217
+ /**
218
+ * 版本号输出类型
219
+ *
220
+ * @description
221
+ * - 'file': 输出到文件
222
+ * - 'define': 通过 Vite 的 define 注入到代码中
223
+ * - 'both': 同时输出到文件和注入代码
224
+ */
225
+ type OutputType = 'file' | 'define' | 'both';
226
+ /**
227
+ * 自动生成版本号插件的配置选项接口
228
+ *
229
+ * @interface GenerateVersionOptions
230
+ */
231
+ interface GenerateVersionOptions extends BasePluginOptions {
232
+ /**
233
+ * 版本号格式
234
+ *
235
+ * @default 'timestamp'
236
+ */
237
+ format?: VersionFormat;
238
+ /**
239
+ * 自定义格式模板,仅当 format 为 'custom' 时有效
240
+ *
241
+ * @description 支持以下占位符:
242
+ * - {YYYY}: 四位年份
243
+ * - {MM}: 两位月份
244
+ * - {DD}: 两位日期
245
+ * - {HH}: 两位小时
246
+ * - {mm}: 两位分钟
247
+ * - {ss}: 两位秒数
248
+ * - {timestamp}: 时间戳
249
+ * - {hash}: 随机哈希
250
+ * - {major}: 主版本号(需配合 semverBase)
251
+ * - {minor}: 次版本号(需配合 semverBase)
252
+ * - {patch}: 补丁版本号(需配合 semverBase)
253
+ *
254
+ * @example '{YYYY}.{MM}.{DD}-{hash}'
255
+ */
256
+ customFormat?: string;
257
+ /**
258
+ * 语义化版本基础值,用于 semver 格式
259
+ *
260
+ * @default '1.0.0'
261
+ */
262
+ semverBase?: string;
263
+ /**
264
+ * 是否自动递增补丁版本号
265
+ *
266
+ * @default false
267
+ */
268
+ autoIncrement?: boolean;
269
+ /**
270
+ * 输出类型
271
+ *
272
+ * @default 'file'
273
+ */
274
+ outputType?: OutputType;
275
+ /**
276
+ * 输出文件路径(相对于构建输出目录)
277
+ *
278
+ * @default 'version.json'
279
+ */
280
+ outputFile?: string;
281
+ /**
282
+ * 注入到代码中的全局变量名
283
+ *
284
+ * @default '__APP_VERSION__'
285
+ */
286
+ defineName?: string;
287
+ /**
288
+ * 哈希长度
289
+ *
290
+ * @default 8
291
+ */
292
+ hashLength?: number;
293
+ /**
294
+ * 版本号前缀
295
+ *
296
+ * @example 'v'
297
+ */
298
+ prefix?: string;
299
+ /**
300
+ * 版本号后缀
301
+ *
302
+ * @example '-beta'
303
+ */
304
+ suffix?: string;
305
+ /**
306
+ * 额外的版本信息,会包含在输出的 JSON 文件中
307
+ */
308
+ extra?: Record<string, any>;
309
+ }
310
+
311
+ /**
312
+ * 自动生成版本号插件
313
+ *
314
+ * @param {GenerateVersionOptions} options - 插件配置选项
315
+ * @returns {Plugin} 一个 Vite 插件实例
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * // 基本使用 - 时间戳格式
320
+ * generateVersion()
321
+ *
322
+ * // 日期格式
323
+ * generateVersion({
324
+ * format: 'date'
325
+ * })
326
+ *
327
+ * // 语义化版本格式
328
+ * generateVersion({
329
+ * format: 'semver',
330
+ * semverBase: '2.0.0',
331
+ * prefix: 'v'
332
+ * })
333
+ *
334
+ * // 自定义格式
335
+ * generateVersion({
336
+ * format: 'custom',
337
+ * customFormat: '{YYYY}.{MM}.{DD}-{hash}',
338
+ * hashLength: 6
339
+ * })
340
+ *
341
+ * // 注入到代码中
342
+ * generateVersion({
343
+ * outputType: 'define',
344
+ * defineName: '__VERSION__'
345
+ * })
346
+ *
347
+ * // 同时输出文件和注入代码
348
+ * generateVersion({
349
+ * outputType: 'both',
350
+ * outputFile: 'build-info.json',
351
+ * defineName: '__BUILD_VERSION__',
352
+ * extra: {
353
+ * environment: 'production',
354
+ * author: 'MengXi Studio'
355
+ * }
356
+ * })
357
+ * ```
358
+ *
359
+ * @remarks
360
+ * 该插件会在 Vite 构建过程中自动生成版本号,支持多种格式:
361
+ * - timestamp: 时间戳格式 (20260203153000)
362
+ * - date: 日期格式 (2026.02.03)
363
+ * - datetime: 日期时间格式 (2026.02.03.153000)
364
+ * - semver: 语义化版本格式 (1.0.0)
365
+ * - hash: 随机哈希格式 (a1b2c3d4)
366
+ * - custom: 自定义格式
367
+ */
368
+ declare const generateVersion: PluginFactory<GenerateVersionOptions, GenerateVersionOptions>;
369
+
75
370
  /**
76
371
  * 图标配置项接口
77
372
  *
@@ -207,4 +502,4 @@ interface InjectIcoOptions extends BasePluginOptions {
207
502
  */
208
503
  declare const injectIco: PluginFactory<InjectIcoOptions, string | InjectIcoOptions>;
209
504
 
210
- export { copyFile, injectIco };
505
+ export { copyFile, generateRouter, generateVersion, injectIco };
@@ -72,6 +72,301 @@ interface CopyFileOptions extends BasePluginOptions {
72
72
  */
73
73
  declare const copyFile: PluginFactory<CopyFileOptions, CopyFileOptions>;
74
74
 
75
+ /**
76
+ * 输出文件格式类型
77
+ */
78
+ type OutputFormat = 'ts' | 'js';
79
+ /**
80
+ * 路由名称生成策略
81
+ */
82
+ type NameStrategy = 'path' | 'camelCase' | 'pascalCase' | 'custom';
83
+ /**
84
+ * 生成路由配置插件选项
85
+ */
86
+ interface GenerateRouterOptions extends BasePluginOptions {
87
+ /**
88
+ * pages.json 文件路径(相对于项目根目录)
89
+ *
90
+ * @default 'src/pages.json'
91
+ */
92
+ pagesJsonPath?: string;
93
+ /**
94
+ * 输出文件路径(相对于项目根目录)
95
+ *
96
+ * @default 'src/router.config.ts'
97
+ */
98
+ outputPath?: string;
99
+ /**
100
+ * 输出文件格式
101
+ *
102
+ * @default 'ts'
103
+ */
104
+ outputFormat?: OutputFormat;
105
+ /**
106
+ * 路由名称生成策略
107
+ *
108
+ * @default 'camelCase'
109
+ */
110
+ nameStrategy?: NameStrategy;
111
+ /**
112
+ * 自定义路由名称生成函数
113
+ *
114
+ * @param path - 页面路径
115
+ * @returns 路由名称
116
+ */
117
+ customNameGenerator?: (path: string) => string;
118
+ /**
119
+ * 是否包含子包路由
120
+ *
121
+ * @default true
122
+ */
123
+ includeSubPackages?: boolean;
124
+ /**
125
+ * 是否监听 pages.json 变化并自动重新生成
126
+ *
127
+ * @default true
128
+ */
129
+ watch?: boolean;
130
+ /**
131
+ * 额外的元信息字段映射
132
+ *
133
+ * @description 将 pages.json 中 style 的字段映射到 meta 中
134
+ * @example { 'navigationBarTitleText': 'title', 'requireAuth': 'requireAuth' }
135
+ */
136
+ metaMapping?: Record<string, string>;
137
+ /**
138
+ * 是否导出类型定义
139
+ *
140
+ * @default true
141
+ */
142
+ exportTypes?: boolean;
143
+ /**
144
+ * 是否保留用户对 routes 配置的修改
145
+ *
146
+ * @description 开启后,用户在 routes 数组中修改的字段将被保留
147
+ * @default true
148
+ */
149
+ preserveRouteChanges?: boolean;
150
+ }
151
+
152
+ /**
153
+ * 生成路由配置插件
154
+ *
155
+ * @param {GenerateRouterOptions} options - 插件配置选项
156
+ * @returns {Plugin} 一个 Vite 插件实例
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * // 基本使用 - 使用默认配置
161
+ * generateRouter()
162
+ *
163
+ * // 自定义 pages.json 路径
164
+ * generateRouter({
165
+ * pagesJsonPath: 'pages.json'
166
+ * })
167
+ *
168
+ * // 输出 JavaScript 文件
169
+ * generateRouter({
170
+ * outputFormat: 'js',
171
+ * outputPath: 'src/router.config.js'
172
+ * })
173
+ *
174
+ * // 使用帕斯卡命名策略
175
+ * generateRouter({
176
+ * nameStrategy: 'pascalCase'
177
+ * })
178
+ *
179
+ * // 自定义路由名称生成
180
+ * generateRouter({
181
+ * nameStrategy: 'custom',
182
+ * customNameGenerator: (path) => `route_${path.replace(/\//g, '_')}`
183
+ * })
184
+ *
185
+ * // 自定义元信息映射
186
+ * generateRouter({
187
+ * metaMapping: {
188
+ * navigationBarTitleText: 'title',
189
+ * requireAuth: 'requireAuth',
190
+ * customField: 'custom'
191
+ * }
192
+ * })
193
+ * ```
194
+ *
195
+ * @remarks
196
+ * 该插件会读取 uni-app 项目的 pages.json 文件,自动生成路由配置文件:
197
+ * - 支持主包和子包页面
198
+ * - 自动识别 tabBar 页面
199
+ * - 支持多种路由名称生成策略
200
+ * - 支持自定义元信息字段映射
201
+ * - 开发模式下自动监听 pages.json 变化并重新生成
202
+ */
203
+ declare const generateRouter: PluginFactory<GenerateRouterOptions, GenerateRouterOptions>;
204
+
205
+ /**
206
+ * 版本号格式类型
207
+ *
208
+ * @description
209
+ * - 'timestamp': 时间戳格式,如 '20260203153000'
210
+ * - 'date': 日期格式,如 '2026.02.03'
211
+ * - 'datetime': 日期时间格式,如 '2026.02.03.153000'
212
+ * - 'semver': 语义化版本格式,如 '1.0.0'
213
+ * - 'hash': 随机哈希格式,如 'a1b2c3d4'
214
+ * - 'custom': 自定义格式,需要配合 customFormat 使用
215
+ */
216
+ type VersionFormat = 'timestamp' | 'date' | 'datetime' | 'semver' | 'hash' | 'custom';
217
+ /**
218
+ * 版本号输出类型
219
+ *
220
+ * @description
221
+ * - 'file': 输出到文件
222
+ * - 'define': 通过 Vite 的 define 注入到代码中
223
+ * - 'both': 同时输出到文件和注入代码
224
+ */
225
+ type OutputType = 'file' | 'define' | 'both';
226
+ /**
227
+ * 自动生成版本号插件的配置选项接口
228
+ *
229
+ * @interface GenerateVersionOptions
230
+ */
231
+ interface GenerateVersionOptions extends BasePluginOptions {
232
+ /**
233
+ * 版本号格式
234
+ *
235
+ * @default 'timestamp'
236
+ */
237
+ format?: VersionFormat;
238
+ /**
239
+ * 自定义格式模板,仅当 format 为 'custom' 时有效
240
+ *
241
+ * @description 支持以下占位符:
242
+ * - {YYYY}: 四位年份
243
+ * - {MM}: 两位月份
244
+ * - {DD}: 两位日期
245
+ * - {HH}: 两位小时
246
+ * - {mm}: 两位分钟
247
+ * - {ss}: 两位秒数
248
+ * - {timestamp}: 时间戳
249
+ * - {hash}: 随机哈希
250
+ * - {major}: 主版本号(需配合 semverBase)
251
+ * - {minor}: 次版本号(需配合 semverBase)
252
+ * - {patch}: 补丁版本号(需配合 semverBase)
253
+ *
254
+ * @example '{YYYY}.{MM}.{DD}-{hash}'
255
+ */
256
+ customFormat?: string;
257
+ /**
258
+ * 语义化版本基础值,用于 semver 格式
259
+ *
260
+ * @default '1.0.0'
261
+ */
262
+ semverBase?: string;
263
+ /**
264
+ * 是否自动递增补丁版本号
265
+ *
266
+ * @default false
267
+ */
268
+ autoIncrement?: boolean;
269
+ /**
270
+ * 输出类型
271
+ *
272
+ * @default 'file'
273
+ */
274
+ outputType?: OutputType;
275
+ /**
276
+ * 输出文件路径(相对于构建输出目录)
277
+ *
278
+ * @default 'version.json'
279
+ */
280
+ outputFile?: string;
281
+ /**
282
+ * 注入到代码中的全局变量名
283
+ *
284
+ * @default '__APP_VERSION__'
285
+ */
286
+ defineName?: string;
287
+ /**
288
+ * 哈希长度
289
+ *
290
+ * @default 8
291
+ */
292
+ hashLength?: number;
293
+ /**
294
+ * 版本号前缀
295
+ *
296
+ * @example 'v'
297
+ */
298
+ prefix?: string;
299
+ /**
300
+ * 版本号后缀
301
+ *
302
+ * @example '-beta'
303
+ */
304
+ suffix?: string;
305
+ /**
306
+ * 额外的版本信息,会包含在输出的 JSON 文件中
307
+ */
308
+ extra?: Record<string, any>;
309
+ }
310
+
311
+ /**
312
+ * 自动生成版本号插件
313
+ *
314
+ * @param {GenerateVersionOptions} options - 插件配置选项
315
+ * @returns {Plugin} 一个 Vite 插件实例
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * // 基本使用 - 时间戳格式
320
+ * generateVersion()
321
+ *
322
+ * // 日期格式
323
+ * generateVersion({
324
+ * format: 'date'
325
+ * })
326
+ *
327
+ * // 语义化版本格式
328
+ * generateVersion({
329
+ * format: 'semver',
330
+ * semverBase: '2.0.0',
331
+ * prefix: 'v'
332
+ * })
333
+ *
334
+ * // 自定义格式
335
+ * generateVersion({
336
+ * format: 'custom',
337
+ * customFormat: '{YYYY}.{MM}.{DD}-{hash}',
338
+ * hashLength: 6
339
+ * })
340
+ *
341
+ * // 注入到代码中
342
+ * generateVersion({
343
+ * outputType: 'define',
344
+ * defineName: '__VERSION__'
345
+ * })
346
+ *
347
+ * // 同时输出文件和注入代码
348
+ * generateVersion({
349
+ * outputType: 'both',
350
+ * outputFile: 'build-info.json',
351
+ * defineName: '__BUILD_VERSION__',
352
+ * extra: {
353
+ * environment: 'production',
354
+ * author: 'MengXi Studio'
355
+ * }
356
+ * })
357
+ * ```
358
+ *
359
+ * @remarks
360
+ * 该插件会在 Vite 构建过程中自动生成版本号,支持多种格式:
361
+ * - timestamp: 时间戳格式 (20260203153000)
362
+ * - date: 日期格式 (2026.02.03)
363
+ * - datetime: 日期时间格式 (2026.02.03.153000)
364
+ * - semver: 语义化版本格式 (1.0.0)
365
+ * - hash: 随机哈希格式 (a1b2c3d4)
366
+ * - custom: 自定义格式
367
+ */
368
+ declare const generateVersion: PluginFactory<GenerateVersionOptions, GenerateVersionOptions>;
369
+
75
370
  /**
76
371
  * 图标配置项接口
77
372
  *
@@ -207,4 +502,4 @@ interface InjectIcoOptions extends BasePluginOptions {
207
502
  */
208
503
  declare const injectIco: PluginFactory<InjectIcoOptions, string | InjectIcoOptions>;
209
504
 
210
- export { copyFile, injectIco };
505
+ export { copyFile, generateRouter, generateVersion, injectIco };
@@ -1 +1 @@
1
- export{c as copyFile,i as injectIco}from"../shared/vite-plugin.CY2ydccp.mjs";import"../shared/vite-plugin.ClHiVXD6.mjs";import"../logger/index.mjs";import"fs";import"path";import"../shared/vite-plugin.DSRKYuae.mjs";import"../shared/vite-plugin.BZqhBDYR.mjs";
1
+ export{c as copyFile,g as generateRouter,a as generateVersion,i as injectIco}from"../shared/vite-plugin.CS9a5kjK.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.YvjM8LxW.mjs";
@@ -0,0 +1,3 @@
1
+ function s(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)&&Object.prototype.toString.call(i)==="[object Object]"}function o(...i){const u={};for(const r of i)if(r)for(const t in r){if(!Object.prototype.hasOwnProperty.call(r,t))continue;const e=r[t],n=u[t];e!==void 0&&(s(e)&&s(n)?u[t]=o(n,e):u[t]=e)}return u}class l{options;currentField=null;errors=[];constructor(u){this.options=u}field(u){const r=this;return r.currentField=u,r}required(){if(this.currentField===null)throw new Error("\u5FC5\u987B\u5148\u8C03\u7528 field() \u65B9\u6CD5\u6307\u5B9A\u8981\u9A8C\u8BC1\u7684\u5B57\u6BB5");return this.options[this.currentField]==null&&this.errors.push(`${String(this.currentField)} \u662F\u5FC5\u586B\u5B57\u6BB5`),this}string(){if(this.currentField===null)throw new Error("\u5FC5\u987B\u5148\u8C03\u7528 field() \u65B9\u6CD5\u6307\u5B9A\u8981\u9A8C\u8BC1\u7684\u5B57\u6BB5");const u=this.options[this.currentField];return u!=null&&typeof u!="string"&&this.errors.push(`${String(this.currentField)} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u7C7B\u578B`),this}boolean(){if(this.currentField===null)throw new Error("\u5FC5\u987B\u5148\u8C03\u7528 field() \u65B9\u6CD5\u6307\u5B9A\u8981\u9A8C\u8BC1\u7684\u5B57\u6BB5");const u=this.options[this.currentField];return u!=null&&typeof u!="boolean"&&this.errors.push(`${String(this.currentField)} \u5FC5\u987B\u662F\u5E03\u5C14\u7C7B\u578B`),this}number(){if(this.currentField===null)throw new Error("\u5FC5\u987B\u5148\u8C03\u7528 field() \u65B9\u6CD5\u6307\u5B9A\u8981\u9A8C\u8BC1\u7684\u5B57\u6BB5");const u=this.options[this.currentField];return u!=null&&typeof u!="number"&&this.errors.push(`${String(this.currentField)} \u5FC5\u987B\u662F\u6570\u5B57\u7C7B\u578B`),this}array(){if(this.currentField===null)throw new Error("\u5FC5\u987B\u5148\u8C03\u7528 field() \u65B9\u6CD5\u6307\u5B9A\u8981\u9A8C\u8BC1\u7684\u5B57\u6BB5");const u=this.options[this.currentField];return u!=null&&!Array.isArray(u)&&this.errors.push(`${String(this.currentField)} \u5FC5\u987B\u662F\u6570\u7EC4\u7C7B\u578B`),this}object(){if(this.currentField===null)throw new Error("\u5FC5\u987B\u5148\u8C03\u7528 field() \u65B9\u6CD5\u6307\u5B9A\u8981\u9A8C\u8BC1\u7684\u5B57\u6BB5");const u=this.options[this.currentField];return u!=null&&typeof u!="object"&&!Array.isArray(u)&&this.errors.push(`${String(this.currentField)} \u5FC5\u987B\u662F\u5BF9\u8C61\u7C7B\u578B`),this}default(u){if(this.currentField===null)throw new Error("\u5FC5\u987B\u5148\u8C03\u7528 field() \u65B9\u6CD5\u6307\u5B9A\u8981\u9A8C\u8BC1\u7684\u5B57\u6BB5");return this.options[this.currentField]==null&&(this.options[this.currentField]=u),this}custom(u,r){if(this.currentField===null)throw new Error("\u5FC5\u987B\u5148\u8C03\u7528 field() \u65B9\u6CD5\u6307\u5B9A\u8981\u9A8C\u8BC1\u7684\u5B57\u6BB5");const t=this.options[this.currentField];return t!=null&&!u(t)&&this.errors.push(r),this}validate(){if(this.errors.length>0)throw new Error(`\u914D\u7F6E\u9A8C\u8BC1\u5931\u8D25\uFF1A
2
+ ${this.errors.map(u=>`- ${u}`).join(`
3
+ `)}`);return this.options}}export{l as V,o as d};
@@ -0,0 +1 @@
1
+ "use strict";const o=require("fs"),u=require("path"),crypto=require("crypto");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const o__default=_interopDefaultCompat(o),u__default=_interopDefaultCompat(u),g=10;async function checkSourceExists(e){try{await o__default.promises.access(e,o__default.constants.F_OK)}catch(t){const r=t;throw r.code==="ENOENT"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${e}`):r.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6E90\u6587\u4EF6 - ${e}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u68C0\u67E5\u6E90\u6587\u4EF6\u65F6\u51FA\u9519 - ${e}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}async function ensureTargetDir(e){try{await o__default.promises.mkdir(e,{recursive:!0})}catch(t){const r=t;throw r.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u521B\u5EFA\u76EE\u6807\u76EE\u5F55 - ${e}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u521B\u5EFA\u76EE\u6807\u76EE\u5F55\u65F6\u51FA\u9519 - ${e}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}async function readDirRecursive(e,t){const r=await o__default.promises.readdir(e,{withFileTypes:!0}),s=[];for(const n of r){const i=u__default.join(e,n.name),l=n.isFile(),F=n.isDirectory();if(s.push({path:i,isFile:l,isDirectory:F}),F&&t){const p=await readDirRecursive(i,t);s.push(...p)}}return s}async function shouldUpdateFile(e,t){try{const[r,s]=await Promise.all([o__default.promises.stat(e),o__default.promises.stat(t)]);return r.mtimeMs>s.mtimeMs||r.size!==s.size}catch{return!0}}async function fileExists(e){try{return await o__default.promises.access(e,o__default.constants.F_OK),!0}catch{return!1}}async function runWithConcurrency(e,t,r){const s=[];let n=0;async function i(){for(;n<e.length;){const F=n++,p=await t(e[F]);s[F]=p}}const l=Array(Math.min(r,e.length)).fill(null).map(()=>i());return await Promise.all(l),s}async function copySourceToTarget(e,t,r){const s=Date.now(),{recursive:n,overwrite:i,incremental:l=!1,parallelLimit:F=g}=r;let p=0,f=0,d=0;if((await o__default.promises.stat(e)).isDirectory()){await ensureTargetDir(t);const c=await readDirRecursive(e,n),D=c.filter(a=>a.isFile);d=c.filter(a=>a.isDirectory).length;const h=new Set;for(const a of D){const w=u__default.relative(e,a.path),m=u__default.dirname(u__default.join(t,w));h.add(m)}await Promise.all([...h].map(a=>ensureTargetDir(a)));const C=await runWithConcurrency(D,async a=>{const w=u__default.relative(e,a.path),m=u__default.join(t,w);let E=i;return E||(E=!await fileExists(m)),l&&E&&(E=await shouldUpdateFile(a.path,m)),E?(await o__default.promises.copyFile(a.path,m),{copied:!0,skipped:!1}):{copied:!1,skipped:!0}},F);for(const a of C)a.copied&&p++,a.skipped&&f++}else{await ensureTargetDir(u__default.dirname(t));let c=i;c||(c=!await fileExists(t)),l&&c&&(c=await shouldUpdateFile(e,t)),c?(await o__default.promises.copyFile(e,t),p++):f++}const y=Date.now()-s;return{copiedFiles:p,skippedFiles:f,copiedDirs:d,executionTime:y}}async function writeFileContent(e,t){try{await o__default.promises.writeFile(e,t,"utf-8")}catch(r){const s=r;throw s.code==="EACCES"?new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u5199\u5165\u6587\u4EF6 - ${e}`):new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u5199\u5165\u6587\u4EF6\u65F6\u51FA\u9519 - ${e}\uFF0C\u9519\u8BEF\uFF1A${s.message}`)}}function readFileSync(e){try{return o__default.readFileSync(e,"utf-8")}catch(t){const r=t;throw r.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${e}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${e}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}function padNumber(e,t=2){return e.toString().padStart(t,"0")}function generateRandomHash(e=8){const t=Math.max(1,Math.min(64,e));return crypto.randomBytes(Math.ceil(t/2)).toString("hex").slice(0,t)}function getDateFormatParams(e=new Date){return{YYYY:e.getFullYear().toString(),YY:e.getFullYear().toString().slice(-2),MM:padNumber(e.getMonth()+1),DD:padNumber(e.getDate()),HH:padNumber(e.getHours()),mm:padNumber(e.getMinutes()),ss:padNumber(e.getSeconds()),SSS:padNumber(e.getMilliseconds(),3),timestamp:e.getTime().toString()}}function formatDate(e,t){const r=getDateFormatParams(e);let s=t;for(const[n,i]of Object.entries(r))s=s.replace(new RegExp(`\\{${n}\\}`,"g"),i);return s}function parseTemplate(e,t){let r=e;for(const[s,n]of Object.entries(t))r=r.replace(new RegExp(`\\{${s}\\}`,"g"),n);return r}function toCamelCase(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map((r,s)=>s===0?r.toLowerCase():r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function toPascalCase(e,t=/[/-]/){return e.replace(/^\/+/,"").split(t).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join("")}function stripJsonComments(e){return e.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}exports.checkSourceExists=checkSourceExists,exports.copySourceToTarget=copySourceToTarget,exports.ensureTargetDir=ensureTargetDir,exports.fileExists=fileExists,exports.formatDate=formatDate,exports.generateRandomHash=generateRandomHash,exports.getDateFormatParams=getDateFormatParams,exports.padNumber=padNumber,exports.parseTemplate=parseTemplate,exports.readDirRecursive=readDirRecursive,exports.readFileSync=readFileSync,exports.runWithConcurrency=runWithConcurrency,exports.shouldUpdateFile=shouldUpdateFile,exports.stripJsonComments=stripJsonComments,exports.toCamelCase=toCamelCase,exports.toPascalCase=toPascalCase,exports.writeFileContent=writeFileContent;
@@ -0,0 +1 @@
1
+ import{Logger as s}from"../logger/index.mjs";import"fs";import"path";import"crypto";import{V as g,d as a}from"./vite-plugin.B88RyRN8.mjs";class u{options;logger;validator;viteConfig=null;constructor(t,e){this.options=this.mergeOptions(t),this.logger=this.initLogger(e),this.validator=new g(this.options),this.safeExecuteSync(()=>this.validateOptions(),"\u63D2\u4EF6\u914D\u7F6E\u9A8C\u8BC1")}mergeOptions(t){const e={enabled:!0,verbose:!0,errorStrategy:"throw"},r=this.getDefaultOptions();return a(e,r,t)}initLogger(t){return s.create({name:this.getPluginName(),enabled:this.options.verbose,...t}).createPluginLogger(this.getPluginName())}validateOptions(){}getEnforce(){}onConfigResolved(t){this.viteConfig=t,this.logger.info("\u914D\u7F6E\u89E3\u6790\u5B8C\u6210\uFF0C\u63D2\u4EF6\u5DF2\u521D\u59CB\u5316")}safeExecuteSync(t,e){try{return t()}catch(r){return this.handleError(r,e)}}async safeExecute(t,e){try{return await t()}catch(r){return this.handleError(r,e)}}handleError(t,e){let r=`${e}: `;switch(t instanceof Error?r+=t.message:typeof t=="string"?r+=t:r+=String(t),this.options.errorStrategy){case"throw":throw this.logger.error(r),t;case"log":case"ignore":this.logger.error(r);return;default:throw this.logger.error(r),t}}toPlugin(){const t={name:this.getPluginName(),enforce:this.getEnforce(),configResolved:e=>{this.options.enabled&&this.onConfigResolved(e)}};return this.addPluginHooks(t),t}}function l(o,t){return e=>{const r=t?t(e):e,i=new o(r),n=i.toPlugin();return n.pluginInstance=i,n}}export{u as B,l as c};