@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.
- package/README-en.md +182 -150
- package/README.md +182 -84
- package/dist/common/index.cjs +1 -1
- package/dist/common/index.d.cts +207 -6
- package/dist/common/index.d.mts +207 -6
- package/dist/common/index.d.ts +207 -6
- package/dist/common/index.mjs +1 -1
- package/dist/factory/index.cjs +1 -1
- package/dist/factory/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/logger/index.cjs +1 -1
- package/dist/logger/index.mjs +1 -1
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +296 -1
- package/dist/plugins/index.d.mts +296 -1
- package/dist/plugins/index.d.ts +296 -1
- package/dist/plugins/index.mjs +1 -1
- package/dist/shared/vite-plugin.B88RyRN8.mjs +3 -0
- package/dist/shared/vite-plugin.BZsetDCm.cjs +1 -0
- package/dist/shared/vite-plugin.C7isVPKg.mjs +1 -0
- package/dist/shared/vite-plugin.CS9a5kjK.mjs +36 -0
- package/dist/shared/vite-plugin.CgnG5_UX.cjs +36 -0
- package/dist/shared/vite-plugin.DqWt65U-.cjs +1 -0
- package/dist/shared/vite-plugin.IGZeStMa.cjs +3 -0
- package/dist/shared/vite-plugin.YvjM8LxW.mjs +1 -0
- package/package.json +72 -72
- package/dist/shared/vite-plugin.BT1oHRKK.cjs +0 -1
- package/dist/shared/vite-plugin.BTKhc7n7.cjs +0 -3
- package/dist/shared/vite-plugin.BZqhBDYR.mjs +0 -1
- package/dist/shared/vite-plugin.Bn8mcCzy.cjs +0 -3
- package/dist/shared/vite-plugin.CY2ydccp.mjs +0 -3
- package/dist/shared/vite-plugin.ClHiVXD6.mjs +0 -1
- package/dist/shared/vite-plugin.DSRKYuae.mjs +0 -3
- package/dist/shared/vite-plugin.DrSzERYS.cjs +0 -1
package/dist/common/index.d.ts
CHANGED
|
@@ -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<
|
|
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
|
-
* @
|
|
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 };
|
package/dist/common/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{c as checkSourceExists,a as copySourceToTarget,e as ensureTargetDir,r as readDirRecursive,
|
|
1
|
+
export{c as checkSourceExists,a as copySourceToTarget,e as ensureTargetDir,f as fileExists,b as formatDate,g as generateRandomHash,d as getDateFormatParams,p as padNumber,h as parseTemplate,r as readDirRecursive,i as readFileSync,j as runWithConcurrency,s as shouldUpdateFile,k as stripJsonComments,t as toCamelCase,l as toPascalCase,w as writeFileContent}from"../shared/vite-plugin.YvjM8LxW.mjs";export{V as Validator,d as deepMerge}from"../shared/vite-plugin.B88RyRN8.mjs";import"fs";import"path";import"crypto";
|
package/dist/factory/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const index=require("../shared/vite-plugin.
|
|
1
|
+
"use strict";const index=require("../shared/vite-plugin.DqWt65U-.cjs");require("../logger/index.cjs"),require("fs"),require("path"),require("crypto"),require("../shared/vite-plugin.IGZeStMa.cjs"),exports.BasePlugin=index.BasePlugin,exports.createPluginFactory=index.createPluginFactory;
|
package/dist/factory/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{B as BasePlugin,c as createPluginFactory}from"../shared/vite-plugin.
|
|
1
|
+
export{B as BasePlugin,c as createPluginFactory}from"../shared/vite-plugin.C7isVPKg.mjs";import"../logger/index.mjs";import"fs";import"path";import"crypto";import"../shared/vite-plugin.B88RyRN8.mjs";
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const format=require("./shared/vite-plugin.BZsetDCm.cjs"),validation=require("./shared/vite-plugin.IGZeStMa.cjs"),index=require("./shared/vite-plugin.DqWt65U-.cjs"),logger_index=require("./logger/index.cjs"),index$1=require("./shared/vite-plugin.CgnG5_UX.cjs");require("fs"),require("path"),require("crypto"),exports.checkSourceExists=format.checkSourceExists,exports.copySourceToTarget=format.copySourceToTarget,exports.ensureTargetDir=format.ensureTargetDir,exports.fileExists=format.fileExists,exports.formatDate=format.formatDate,exports.generateRandomHash=format.generateRandomHash,exports.getDateFormatParams=format.getDateFormatParams,exports.padNumber=format.padNumber,exports.parseTemplate=format.parseTemplate,exports.readDirRecursive=format.readDirRecursive,exports.readFileSync=format.readFileSync,exports.runWithConcurrency=format.runWithConcurrency,exports.shouldUpdateFile=format.shouldUpdateFile,exports.stripJsonComments=format.stripJsonComments,exports.toCamelCase=format.toCamelCase,exports.toPascalCase=format.toPascalCase,exports.writeFileContent=format.writeFileContent,exports.Validator=validation.Validator,exports.deepMerge=validation.deepMerge,exports.BasePlugin=index.BasePlugin,exports.createPluginFactory=index.createPluginFactory,exports.Logger=logger_index.Logger,exports.copyFile=index$1.copyFile,exports.generateRouter=index$1.generateRouter,exports.generateVersion=index$1.generateVersion,exports.injectIco=index$1.injectIco;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, readDirRecursive, readFileSync, shouldUpdateFile, writeFileContent } from './common/index.cjs';
|
|
1
|
+
export { DateFormatOptions, checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, fileExists, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, runWithConcurrency, shouldUpdateFile, stripJsonComments, toCamelCase, toPascalCase, writeFileContent } from './common/index.cjs';
|
|
2
2
|
export { V as Validator } from './shared/vite-plugin.CiHfwMiN.cjs';
|
|
3
3
|
export { BasePlugin, createPluginFactory } from './factory/index.cjs';
|
|
4
4
|
export { L as Logger, P as PluginLogger } from './shared/vite-plugin.B3PARlU9.cjs';
|
|
5
|
-
export { copyFile, injectIco } from './plugins/index.cjs';
|
|
5
|
+
export { copyFile, generateRouter, generateVersion, injectIco } from './plugins/index.cjs';
|
|
6
6
|
import 'vite';
|
|
7
7
|
import './shared/vite-plugin.UkE7CdSe.cjs';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, readDirRecursive, readFileSync, shouldUpdateFile, writeFileContent } from './common/index.mjs';
|
|
1
|
+
export { DateFormatOptions, checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, fileExists, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, runWithConcurrency, shouldUpdateFile, stripJsonComments, toCamelCase, toPascalCase, writeFileContent } from './common/index.mjs';
|
|
2
2
|
export { V as Validator } from './shared/vite-plugin.CiHfwMiN.mjs';
|
|
3
3
|
export { BasePlugin, createPluginFactory } from './factory/index.mjs';
|
|
4
4
|
export { L as Logger, P as PluginLogger } from './shared/vite-plugin.B3PARlU9.mjs';
|
|
5
|
-
export { copyFile, injectIco } from './plugins/index.mjs';
|
|
5
|
+
export { copyFile, generateRouter, generateVersion, injectIco } from './plugins/index.mjs';
|
|
6
6
|
import 'vite';
|
|
7
7
|
import './shared/vite-plugin.UkE7CdSe.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, readDirRecursive, readFileSync, shouldUpdateFile, writeFileContent } from './common/index.js';
|
|
1
|
+
export { DateFormatOptions, checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, fileExists, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, runWithConcurrency, shouldUpdateFile, stripJsonComments, toCamelCase, toPascalCase, writeFileContent } from './common/index.js';
|
|
2
2
|
export { V as Validator } from './shared/vite-plugin.CiHfwMiN.js';
|
|
3
3
|
export { BasePlugin, createPluginFactory } from './factory/index.js';
|
|
4
4
|
export { L as Logger, P as PluginLogger } from './shared/vite-plugin.B3PARlU9.js';
|
|
5
|
-
export { copyFile, injectIco } from './plugins/index.js';
|
|
5
|
+
export { copyFile, generateRouter, generateVersion, injectIco } from './plugins/index.js';
|
|
6
6
|
import 'vite';
|
|
7
7
|
import './shared/vite-plugin.UkE7CdSe.js';
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{c as checkSourceExists,a as copySourceToTarget,e as ensureTargetDir,r as readDirRecursive,
|
|
1
|
+
export{c as checkSourceExists,a as copySourceToTarget,e as ensureTargetDir,f as fileExists,b as formatDate,g as generateRandomHash,d as getDateFormatParams,p as padNumber,h as parseTemplate,r as readDirRecursive,i as readFileSync,j as runWithConcurrency,s as shouldUpdateFile,k as stripJsonComments,t as toCamelCase,l as toPascalCase,w as writeFileContent}from"./shared/vite-plugin.YvjM8LxW.mjs";export{V as Validator,d as deepMerge}from"./shared/vite-plugin.B88RyRN8.mjs";export{B as BasePlugin,c as createPluginFactory}from"./shared/vite-plugin.C7isVPKg.mjs";export{Logger}from"./logger/index.mjs";export{c as copyFile,g as generateRouter,a as generateVersion,i as injectIco}from"./shared/vite-plugin.CS9a5kjK.mjs";import"fs";import"path";import"crypto";
|
package/dist/logger/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";class Logger{static instance=null;libName="@meng-xi/vite-plugin";pluginConfigs=new Map;logTypes={info:{method:console.log,icon:"",color:"",reset:""},success:{method:console.log,icon:"\u2705",color:"\x1B[32m",reset:"\x1B[0m"},warn:{method:console.warn,icon:"\u26A0\uFE0F",color:"\x1B[33m",reset:"\x1B[0m"},error:{method:console.error,icon:"\u274C",color:"\x1B[31m",reset:"\x1B[0m"}};constructor(){}static getInstance(){return Logger.instance||(Logger.instance=new Logger),Logger.instance}static create(
|
|
1
|
+
"use strict";class Logger{static instance=null;libName="@meng-xi/vite-plugin";pluginConfigs=new Map;logTypes={info:{method:console.log,icon:"\u2139\uFE0F",color:"\x1B[36m",reset:"\x1B[0m"},success:{method:console.log,icon:"\u2705",color:"\x1B[32m",reset:"\x1B[0m"},warn:{method:console.warn,icon:"\u26A0\uFE0F",color:"\x1B[33m",reset:"\x1B[0m"},error:{method:console.error,icon:"\u274C",color:"\x1B[31m",reset:"\x1B[0m"}};constructor(){}static getInstance(){return Logger.instance||(Logger.instance=new Logger),Logger.instance}static create(e){const n=Logger.getInstance();return n.registerPlugin(e.name,e.enabled??!0),n}registerPlugin(e,n){this.pluginConfigs.set(e,n)}formatPrefix(e){return`[${this.libName}:${e}]`}isPluginEnabled(e){return this.pluginConfigs.get(e)??!0}log(e,n,t,r){if(!this.isPluginEnabled(e))return;const l=this.formatPrefix(e),u=this.logTypes[n],{method:i,icon:a,color:s,reset:o}=u,c=`${a} ${l}`;r!=null?i(s+c+o,s+t+o,r):i(s+c+o,s+t+o)}createPluginLogger(e){return{success:(n,t)=>this.log(e,"success",n,t),info:(n,t)=>this.log(e,"info",n,t),warn:(n,t)=>this.log(e,"warn",n,t),error:(n,t)=>this.log(e,"error",n,t)}}}exports.Logger=Logger;
|
package/dist/logger/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
class o{static instance=null;libName="@meng-xi/vite-plugin";pluginConfigs=new Map;logTypes={info:{method:console.log,icon:"\u2139\uFE0F",color:"\x1B[36m",reset:"\x1B[0m"},success:{method:console.log,icon:"\u2705",color:"\x1B[32m",reset:"\x1B[0m"},warn:{method:console.warn,icon:"\u26A0\uFE0F",color:"\x1B[33m",reset:"\x1B[0m"},error:{method:console.error,icon:"\u274C",color:"\x1B[31m",reset:"\x1B[0m"}};constructor(){}static getInstance(){return o.instance||(o.instance=new o),o.instance}static create(e){const n=o.getInstance();return n.registerPlugin(e.name,e.enabled??!0),n}registerPlugin(e,n){this.pluginConfigs.set(e,n)}formatPrefix(e){return`[${this.libName}:${e}]`}isPluginEnabled(e){return this.pluginConfigs.get(e)??!0}log(e,n,t,i){if(!this.isPluginEnabled(e))return;const u=this.formatPrefix(e),a=this.logTypes[n],{method:l,icon:g,color:r,reset:s}=a,c=`${g} ${u}`;i!=null?l(r+c+s,r+t+s,i):l(r+c+s,r+t+s)}createPluginLogger(e){return{success:(n,t)=>this.log(e,"success",n,t),info:(n,t)=>this.log(e,"info",n,t),warn:(n,t)=>this.log(e,"warn",n,t),error:(n,t)=>this.log(e,"error",n,t)}}}export{o as Logger};
|
package/dist/plugins/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const index=require("../shared/vite-plugin.
|
|
1
|
+
"use strict";const index=require("../shared/vite-plugin.CgnG5_UX.cjs");require("../shared/vite-plugin.DqWt65U-.cjs"),require("../logger/index.cjs"),require("fs"),require("path"),require("crypto"),require("../shared/vite-plugin.IGZeStMa.cjs"),require("../shared/vite-plugin.BZsetDCm.cjs"),exports.copyFile=index.copyFile,exports.generateRouter=index.generateRouter,exports.generateVersion=index.generateVersion,exports.injectIco=index.injectIco;
|
package/dist/plugins/index.d.cts
CHANGED
|
@@ -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 };
|