@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
@@ -47,6 +47,17 @@ interface CopyResult {
47
47
  executionTime: number;
48
48
  }
49
49
 
50
+ /**
51
+ * 文件/目录条目信息
52
+ */
53
+ interface FileEntry {
54
+ /** 完整路径 */
55
+ path: string;
56
+ /** 是否为文件 */
57
+ isFile: boolean;
58
+ /** 是否为目录 */
59
+ isDirectory: boolean;
60
+ }
50
61
  /**
51
62
  * 检查源文件是否存在
52
63
  * @param sourcePath 源文件路径
@@ -60,12 +71,12 @@ declare function checkSourceExists(sourcePath: string): Promise<void>;
60
71
  */
61
72
  declare function ensureTargetDir(targetPath: string): Promise<void>;
62
73
  /**
63
- * 读取目录内容
74
+ * 读取目录内容(优化版:一次性获取文件类型信息)
64
75
  * @param dirPath 目录路径
65
76
  * @param recursive 是否递归读取
66
- * @returns 文件和目录列表
77
+ * @returns 文件和目录条目列表
67
78
  */
68
- declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<string[]>;
79
+ declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<FileEntry[]>;
69
80
  /**
70
81
  * 检查文件是否需要更新
71
82
  * @param sourceFile 源文件路径
@@ -74,7 +85,39 @@ declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<
74
85
  */
75
86
  declare function shouldUpdateFile(sourceFile: string, targetFile: string): Promise<boolean>;
76
87
  /**
77
- * 执行文件复制操作
88
+ * 检查文件是否存在
89
+ * @param filePath 文件路径
90
+ * @returns 是否存在
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * if (await fileExists('/path/to/file')) {
95
+ * console.log('文件存在')
96
+ * }
97
+ * ```
98
+ */
99
+ declare function fileExists(filePath: string): Promise<boolean>;
100
+ /**
101
+ * 带并发限制的批量执行
102
+ *
103
+ * @param items 待处理项
104
+ * @param handler 处理函数
105
+ * @param concurrency 并发数
106
+ * @returns 处理结果数组,顺序与输入项对应
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const urls = ['url1', 'url2', 'url3', 'url4', 'url5']
111
+ * const results = await runWithConcurrency(
112
+ * urls,
113
+ * async (url) => fetch(url),
114
+ * 3 // 最多同时处理3个请求
115
+ * )
116
+ * ```
117
+ */
118
+ declare function runWithConcurrency<T, R>(items: T[], handler: (item: T) => Promise<R>, concurrency: number): Promise<R[]>;
119
+ /**
120
+ * 执行文件复制操作(优化版:并行IO)
78
121
  * @param sourcePath 源文件或目录路径
79
122
  * @param targetPath 目标文件或目录路径
80
123
  * @param options 复制选项
@@ -97,13 +140,171 @@ declare function writeFileContent(filePath: string, content: string): Promise<vo
97
140
  */
98
141
  declare function readFileSync(filePath: string): string;
99
142
 
143
+ /**
144
+ * 数字补零格式化
145
+ *
146
+ * @param num 要格式化的数字
147
+ * @param length 目标长度
148
+ * @returns 补零后的字符串
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * padNumber(5, 2) // '05'
153
+ * padNumber(12, 3) // '012'
154
+ * padNumber(123, 2) // '123'
155
+ * ```
156
+ */
157
+ declare function padNumber(num: number, length?: number): string;
158
+ /**
159
+ * 生成随机哈希字符串
160
+ *
161
+ * @param length 哈希长度,范围 1-64
162
+ * @returns 随机哈希字符串
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * generateRandomHash(8) // 'a1b2c3d4'
167
+ * generateRandomHash(16) // 'a1b2c3d4e5f6g7h8'
168
+ * ```
169
+ */
170
+ declare function generateRandomHash(length?: number): string;
171
+ /**
172
+ * 日期格式化选项
173
+ */
174
+ interface DateFormatOptions {
175
+ /** 四位年份 */
176
+ YYYY: string;
177
+ /** 两位年份 */
178
+ YY: string;
179
+ /** 两位月份 */
180
+ MM: string;
181
+ /** 两位日期 */
182
+ DD: string;
183
+ /** 两位小时(24小时制) */
184
+ HH: string;
185
+ /** 两位分钟 */
186
+ mm: string;
187
+ /** 两位秒数 */
188
+ ss: string;
189
+ /** 三位毫秒 */
190
+ SSS: string;
191
+ /** 时间戳(毫秒) */
192
+ timestamp: string;
193
+ }
194
+ /**
195
+ * 获取日期格式化参数
196
+ *
197
+ * @param date 日期对象
198
+ * @returns 日期格式化参数对象
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * const params = getDateFormatParams(new Date())
203
+ * // { YYYY: '2026', MM: '02', DD: '03', HH: '15', mm: '30', ss: '00', ... }
204
+ * ```
205
+ */
206
+ declare function getDateFormatParams(date?: Date): DateFormatOptions;
207
+ /**
208
+ * 格式化日期
209
+ *
210
+ * @param date 日期对象
211
+ * @param format 格式模板
212
+ * @returns 格式化后的日期字符串
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * formatDate(new Date(), '{YYYY}-{MM}-{DD}') // '2026-02-03'
217
+ * formatDate(new Date(), '{YYYY}{MM}{DD}{HH}{mm}{ss}') // '20260203153000'
218
+ * formatDate(new Date(), '{YYYY}.{MM}.{DD}') // '2026.02.03'
219
+ * ```
220
+ */
221
+ declare function formatDate(date: Date, format: string): string;
222
+ /**
223
+ * 解析模板字符串,替换占位符
224
+ *
225
+ * @param template 模板字符串
226
+ * @param values 占位符值映射
227
+ * @returns 替换后的字符串
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * parseTemplate('{name}-{version}', { name: 'app', version: '1.0.0' })
232
+ * // 'app-1.0.0'
233
+ * ```
234
+ */
235
+ declare function parseTemplate(template: string, values: Record<string, string>): string;
236
+ /**
237
+ * 将字符串转换为驼峰命名(camelCase)
238
+ *
239
+ * @param str 输入字符串
240
+ * @param separators 分隔符正则,默认为斜杠和横线
241
+ * @returns 驼峰命名字符串
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * toCamelCase('pages/user/profile') // 'pagesUserProfile'
246
+ * toCamelCase('user-profile-page') // 'userProfilePage'
247
+ * toCamelCase('/pages/index') // 'pagesIndex'
248
+ * ```
249
+ */
250
+ declare function toCamelCase(str: string, separators?: RegExp): string;
251
+ /**
252
+ * 将字符串转换为帕斯卡命名(PascalCase)
253
+ *
254
+ * @param str 输入字符串
255
+ * @param separators 分隔符正则,默认为斜杠和横线
256
+ * @returns 帕斯卡命名字符串
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * toPascalCase('pages/user/profile') // 'PagesUserProfile'
261
+ * toPascalCase('user-profile-page') // 'UserProfilePage'
262
+ * toPascalCase('/pages/index') // 'PagesIndex'
263
+ * ```
264
+ */
265
+ declare function toPascalCase(str: string, separators?: RegExp): string;
266
+ /**
267
+ * 移除 JSON 字符串中的注释
268
+ *
269
+ * @param jsonString 包含注释的 JSON 字符串
270
+ * @returns 移除注释后的 JSON 字符串
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * stripJsonComments('{\n // comment\n "name": "test"\n}')
275
+ * // '{\n "name": "test"\n}'
276
+ * ```
277
+ */
278
+ declare function stripJsonComments(jsonString: string): string;
279
+
100
280
  /**
101
281
  * 深度合并对象
102
282
  *
103
- * @param target 目标对象
283
+ * @description 将多个源对象深度合并到一个新对象中。
284
+ * - undefined 值会被跳过,不会覆盖已有值
285
+ * - 嵌套对象会递归合并
286
+ * - 数组会直接覆盖,不会合并
287
+ * - null 值会覆盖已有值
288
+ *
104
289
  * @param sources 源对象列表
105
290
  * @returns 合并后的对象
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * // 基本合并
295
+ * deepMerge({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }
296
+ *
297
+ * // undefined 不覆盖
298
+ * deepMerge({ a: 1 }, { a: undefined }) // { a: 1 }
299
+ *
300
+ * // 嵌套对象合并
301
+ * deepMerge({ a: { b: 1 } }, { a: { c: 2 } }) // { a: { b: 1, c: 2 } }
302
+ *
303
+ * // 数组覆盖
304
+ * deepMerge({ a: [1, 2] }, { a: [3, 4] }) // { a: [3, 4] }
305
+ * ```
106
306
  */
107
307
  declare function deepMerge<T extends Record<string, any>>(...sources: Partial<T>[]): T;
108
308
 
109
- export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, readDirRecursive, readFileSync, shouldUpdateFile, writeFileContent };
309
+ export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, fileExists, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, runWithConcurrency, shouldUpdateFile, stripJsonComments, toCamelCase, toPascalCase, writeFileContent };
310
+ export type { DateFormatOptions };
@@ -47,6 +47,17 @@ interface CopyResult {
47
47
  executionTime: number;
48
48
  }
49
49
 
50
+ /**
51
+ * 文件/目录条目信息
52
+ */
53
+ interface FileEntry {
54
+ /** 完整路径 */
55
+ path: string;
56
+ /** 是否为文件 */
57
+ isFile: boolean;
58
+ /** 是否为目录 */
59
+ isDirectory: boolean;
60
+ }
50
61
  /**
51
62
  * 检查源文件是否存在
52
63
  * @param sourcePath 源文件路径
@@ -60,12 +71,12 @@ declare function checkSourceExists(sourcePath: string): Promise<void>;
60
71
  */
61
72
  declare function ensureTargetDir(targetPath: string): Promise<void>;
62
73
  /**
63
- * 读取目录内容
74
+ * 读取目录内容(优化版:一次性获取文件类型信息)
64
75
  * @param dirPath 目录路径
65
76
  * @param recursive 是否递归读取
66
- * @returns 文件和目录列表
77
+ * @returns 文件和目录条目列表
67
78
  */
68
- declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<string[]>;
79
+ declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<FileEntry[]>;
69
80
  /**
70
81
  * 检查文件是否需要更新
71
82
  * @param sourceFile 源文件路径
@@ -74,7 +85,39 @@ declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<
74
85
  */
75
86
  declare function shouldUpdateFile(sourceFile: string, targetFile: string): Promise<boolean>;
76
87
  /**
77
- * 执行文件复制操作
88
+ * 检查文件是否存在
89
+ * @param filePath 文件路径
90
+ * @returns 是否存在
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * if (await fileExists('/path/to/file')) {
95
+ * console.log('文件存在')
96
+ * }
97
+ * ```
98
+ */
99
+ declare function fileExists(filePath: string): Promise<boolean>;
100
+ /**
101
+ * 带并发限制的批量执行
102
+ *
103
+ * @param items 待处理项
104
+ * @param handler 处理函数
105
+ * @param concurrency 并发数
106
+ * @returns 处理结果数组,顺序与输入项对应
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const urls = ['url1', 'url2', 'url3', 'url4', 'url5']
111
+ * const results = await runWithConcurrency(
112
+ * urls,
113
+ * async (url) => fetch(url),
114
+ * 3 // 最多同时处理3个请求
115
+ * )
116
+ * ```
117
+ */
118
+ declare function runWithConcurrency<T, R>(items: T[], handler: (item: T) => Promise<R>, concurrency: number): Promise<R[]>;
119
+ /**
120
+ * 执行文件复制操作(优化版:并行IO)
78
121
  * @param sourcePath 源文件或目录路径
79
122
  * @param targetPath 目标文件或目录路径
80
123
  * @param options 复制选项
@@ -97,13 +140,171 @@ declare function writeFileContent(filePath: string, content: string): Promise<vo
97
140
  */
98
141
  declare function readFileSync(filePath: string): string;
99
142
 
143
+ /**
144
+ * 数字补零格式化
145
+ *
146
+ * @param num 要格式化的数字
147
+ * @param length 目标长度
148
+ * @returns 补零后的字符串
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * padNumber(5, 2) // '05'
153
+ * padNumber(12, 3) // '012'
154
+ * padNumber(123, 2) // '123'
155
+ * ```
156
+ */
157
+ declare function padNumber(num: number, length?: number): string;
158
+ /**
159
+ * 生成随机哈希字符串
160
+ *
161
+ * @param length 哈希长度,范围 1-64
162
+ * @returns 随机哈希字符串
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * generateRandomHash(8) // 'a1b2c3d4'
167
+ * generateRandomHash(16) // 'a1b2c3d4e5f6g7h8'
168
+ * ```
169
+ */
170
+ declare function generateRandomHash(length?: number): string;
171
+ /**
172
+ * 日期格式化选项
173
+ */
174
+ interface DateFormatOptions {
175
+ /** 四位年份 */
176
+ YYYY: string;
177
+ /** 两位年份 */
178
+ YY: string;
179
+ /** 两位月份 */
180
+ MM: string;
181
+ /** 两位日期 */
182
+ DD: string;
183
+ /** 两位小时(24小时制) */
184
+ HH: string;
185
+ /** 两位分钟 */
186
+ mm: string;
187
+ /** 两位秒数 */
188
+ ss: string;
189
+ /** 三位毫秒 */
190
+ SSS: string;
191
+ /** 时间戳(毫秒) */
192
+ timestamp: string;
193
+ }
194
+ /**
195
+ * 获取日期格式化参数
196
+ *
197
+ * @param date 日期对象
198
+ * @returns 日期格式化参数对象
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * const params = getDateFormatParams(new Date())
203
+ * // { YYYY: '2026', MM: '02', DD: '03', HH: '15', mm: '30', ss: '00', ... }
204
+ * ```
205
+ */
206
+ declare function getDateFormatParams(date?: Date): DateFormatOptions;
207
+ /**
208
+ * 格式化日期
209
+ *
210
+ * @param date 日期对象
211
+ * @param format 格式模板
212
+ * @returns 格式化后的日期字符串
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * formatDate(new Date(), '{YYYY}-{MM}-{DD}') // '2026-02-03'
217
+ * formatDate(new Date(), '{YYYY}{MM}{DD}{HH}{mm}{ss}') // '20260203153000'
218
+ * formatDate(new Date(), '{YYYY}.{MM}.{DD}') // '2026.02.03'
219
+ * ```
220
+ */
221
+ declare function formatDate(date: Date, format: string): string;
222
+ /**
223
+ * 解析模板字符串,替换占位符
224
+ *
225
+ * @param template 模板字符串
226
+ * @param values 占位符值映射
227
+ * @returns 替换后的字符串
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * parseTemplate('{name}-{version}', { name: 'app', version: '1.0.0' })
232
+ * // 'app-1.0.0'
233
+ * ```
234
+ */
235
+ declare function parseTemplate(template: string, values: Record<string, string>): string;
236
+ /**
237
+ * 将字符串转换为驼峰命名(camelCase)
238
+ *
239
+ * @param str 输入字符串
240
+ * @param separators 分隔符正则,默认为斜杠和横线
241
+ * @returns 驼峰命名字符串
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * toCamelCase('pages/user/profile') // 'pagesUserProfile'
246
+ * toCamelCase('user-profile-page') // 'userProfilePage'
247
+ * toCamelCase('/pages/index') // 'pagesIndex'
248
+ * ```
249
+ */
250
+ declare function toCamelCase(str: string, separators?: RegExp): string;
251
+ /**
252
+ * 将字符串转换为帕斯卡命名(PascalCase)
253
+ *
254
+ * @param str 输入字符串
255
+ * @param separators 分隔符正则,默认为斜杠和横线
256
+ * @returns 帕斯卡命名字符串
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * toPascalCase('pages/user/profile') // 'PagesUserProfile'
261
+ * toPascalCase('user-profile-page') // 'UserProfilePage'
262
+ * toPascalCase('/pages/index') // 'PagesIndex'
263
+ * ```
264
+ */
265
+ declare function toPascalCase(str: string, separators?: RegExp): string;
266
+ /**
267
+ * 移除 JSON 字符串中的注释
268
+ *
269
+ * @param jsonString 包含注释的 JSON 字符串
270
+ * @returns 移除注释后的 JSON 字符串
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * stripJsonComments('{\n // comment\n "name": "test"\n}')
275
+ * // '{\n "name": "test"\n}'
276
+ * ```
277
+ */
278
+ declare function stripJsonComments(jsonString: string): string;
279
+
100
280
  /**
101
281
  * 深度合并对象
102
282
  *
103
- * @param target 目标对象
283
+ * @description 将多个源对象深度合并到一个新对象中。
284
+ * - undefined 值会被跳过,不会覆盖已有值
285
+ * - 嵌套对象会递归合并
286
+ * - 数组会直接覆盖,不会合并
287
+ * - null 值会覆盖已有值
288
+ *
104
289
  * @param sources 源对象列表
105
290
  * @returns 合并后的对象
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * // 基本合并
295
+ * deepMerge({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }
296
+ *
297
+ * // undefined 不覆盖
298
+ * deepMerge({ a: 1 }, { a: undefined }) // { a: 1 }
299
+ *
300
+ * // 嵌套对象合并
301
+ * deepMerge({ a: { b: 1 } }, { a: { c: 2 } }) // { a: { b: 1, c: 2 } }
302
+ *
303
+ * // 数组覆盖
304
+ * deepMerge({ a: [1, 2] }, { a: [3, 4] }) // { a: [3, 4] }
305
+ * ```
106
306
  */
107
307
  declare function deepMerge<T extends Record<string, any>>(...sources: Partial<T>[]): T;
108
308
 
109
- export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, readDirRecursive, readFileSync, shouldUpdateFile, writeFileContent };
309
+ export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, fileExists, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, runWithConcurrency, shouldUpdateFile, stripJsonComments, toCamelCase, toPascalCase, writeFileContent };
310
+ export type { DateFormatOptions };