@meng-xi/vite-plugin 0.1.4 → 0.1.6
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 +34 -20
- package/README.md +33 -19
- package/dist/common/format/index.cjs +1 -1
- package/dist/common/format/index.d.cts +19 -114
- package/dist/common/format/index.d.mts +19 -114
- package/dist/common/format/index.d.ts +19 -114
- package/dist/common/format/index.mjs +1 -1
- package/dist/common/fs/index.cjs +1 -1
- package/dist/common/fs/index.d.cts +36 -89
- package/dist/common/fs/index.d.mts +36 -89
- package/dist/common/fs/index.d.ts +36 -89
- package/dist/common/fs/index.mjs +1 -1
- package/dist/common/html/index.cjs +2 -2
- package/dist/common/html/index.d.cts +12 -307
- package/dist/common/html/index.d.mts +12 -307
- package/dist/common/html/index.d.ts +12 -307
- package/dist/common/html/index.mjs +2 -2
- package/dist/common/index.cjs +1 -1
- package/dist/common/index.d.cts +7 -11
- package/dist/common/index.d.mts +7 -11
- package/dist/common/index.d.ts +7 -11
- package/dist/common/index.mjs +1 -1
- package/dist/common/script/index.cjs +1 -1
- package/dist/common/script/index.d.cts +1 -44
- package/dist/common/script/index.d.mts +1 -44
- package/dist/common/script/index.d.ts +1 -44
- package/dist/common/script/index.mjs +1 -1
- package/dist/common/ui/index.cjs +1 -1
- package/dist/common/ui/index.d.cts +1 -111
- package/dist/common/ui/index.d.mts +1 -111
- package/dist/common/ui/index.d.ts +1 -111
- package/dist/common/ui/index.mjs +1 -1
- package/dist/common/validation/index.cjs +1 -1
- package/dist/common/validation/index.d.cts +2 -80
- package/dist/common/validation/index.d.mts +2 -80
- package/dist/common/validation/index.d.ts +2 -80
- package/dist/common/validation/index.mjs +1 -1
- package/dist/factory/index.cjs +1 -1
- package/dist/factory/index.d.cts +1 -1
- package/dist/factory/index.d.mts +1 -1
- package/dist/factory/index.d.ts +1 -1
- package/dist/factory/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -12
- package/dist/index.d.mts +10 -12
- package/dist/index.d.ts +10 -12
- package/dist/index.mjs +1 -1
- package/dist/logger/index.d.cts +92 -1
- package/dist/logger/index.d.mts +92 -1
- package/dist/logger/index.d.ts +92 -1
- package/dist/plugins/autoImport/index.cjs +19 -0
- package/dist/plugins/autoImport/index.d.cts +291 -0
- package/dist/plugins/autoImport/index.d.mts +291 -0
- package/dist/plugins/autoImport/index.d.ts +291 -0
- package/dist/plugins/autoImport/index.mjs +19 -0
- package/dist/plugins/buildProgress/index.cjs +1 -1
- package/dist/plugins/buildProgress/index.d.cts +1 -1
- package/dist/plugins/buildProgress/index.d.mts +1 -1
- package/dist/plugins/buildProgress/index.d.ts +1 -1
- package/dist/plugins/buildProgress/index.mjs +2 -2
- package/dist/plugins/bundleAnalyzer/index.cjs +21 -21
- package/dist/plugins/bundleAnalyzer/index.d.cts +1 -1
- package/dist/plugins/bundleAnalyzer/index.d.mts +1 -1
- package/dist/plugins/bundleAnalyzer/index.d.ts +1 -1
- package/dist/plugins/bundleAnalyzer/index.mjs +18 -18
- package/dist/plugins/compressAssets/index.cjs +1 -1
- package/dist/plugins/compressAssets/index.d.cts +1 -1
- package/dist/plugins/compressAssets/index.d.mts +1 -1
- package/dist/plugins/compressAssets/index.d.ts +1 -1
- package/dist/plugins/compressAssets/index.mjs +1 -1
- package/dist/plugins/copyFile/index.cjs +1 -1
- package/dist/plugins/copyFile/index.d.cts +1 -1
- package/dist/plugins/copyFile/index.d.mts +1 -1
- package/dist/plugins/copyFile/index.d.ts +1 -1
- package/dist/plugins/copyFile/index.mjs +1 -1
- package/dist/plugins/envGuard/index.cjs +11 -11
- package/dist/plugins/envGuard/index.d.cts +101 -2
- package/dist/plugins/envGuard/index.d.mts +101 -2
- package/dist/plugins/envGuard/index.d.ts +101 -2
- package/dist/plugins/envGuard/index.mjs +9 -9
- package/dist/plugins/faviconManager/index.cjs +1 -1
- package/dist/plugins/faviconManager/index.d.cts +1 -1
- package/dist/plugins/faviconManager/index.d.mts +1 -1
- package/dist/plugins/faviconManager/index.d.ts +1 -1
- package/dist/plugins/faviconManager/index.mjs +1 -1
- package/dist/plugins/generateRouter/index.cjs +5 -4
- package/dist/plugins/generateRouter/index.d.cts +34 -1
- package/dist/plugins/generateRouter/index.d.mts +34 -1
- package/dist/plugins/generateRouter/index.d.ts +34 -1
- package/dist/plugins/generateRouter/index.mjs +5 -4
- package/dist/plugins/generateVersion/index.cjs +1 -1
- package/dist/plugins/generateVersion/index.d.cts +1 -1
- package/dist/plugins/generateVersion/index.d.mts +1 -1
- package/dist/plugins/generateVersion/index.d.ts +1 -1
- package/dist/plugins/generateVersion/index.mjs +1 -1
- package/dist/plugins/htmlInject/index.cjs +7 -1
- package/dist/plugins/htmlInject/index.d.cts +2 -2
- package/dist/plugins/htmlInject/index.d.mts +2 -2
- package/dist/plugins/htmlInject/index.d.ts +2 -2
- package/dist/plugins/htmlInject/index.mjs +7 -1
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +3 -3
- package/dist/plugins/index.d.mts +3 -3
- package/dist/plugins/index.d.ts +3 -3
- package/dist/plugins/index.mjs +1 -1
- package/dist/plugins/loadingManager/index.cjs +26 -26
- package/dist/plugins/loadingManager/index.d.cts +1 -1
- package/dist/plugins/loadingManager/index.d.mts +1 -1
- package/dist/plugins/loadingManager/index.d.ts +1 -1
- package/dist/plugins/loadingManager/index.mjs +10 -10
- package/dist/plugins/versionUpdateChecker/index.cjs +5 -5
- package/dist/plugins/versionUpdateChecker/index.d.cts +1 -1
- package/dist/plugins/versionUpdateChecker/index.d.mts +1 -1
- package/dist/plugins/versionUpdateChecker/index.d.ts +1 -1
- package/dist/plugins/versionUpdateChecker/index.mjs +6 -6
- package/dist/shared/vite-plugin.B8FuZce1.d.cts +45 -0
- package/dist/shared/vite-plugin.B8FuZce1.d.mts +45 -0
- package/dist/shared/vite-plugin.B8FuZce1.d.ts +45 -0
- package/dist/shared/{vite-plugin.FfJ-Wwfu.d.cts → vite-plugin.BI9taN75.d.cts} +1 -22
- package/dist/shared/{vite-plugin.FfJ-Wwfu.d.mts → vite-plugin.BI9taN75.d.mts} +1 -22
- package/dist/shared/{vite-plugin.FfJ-Wwfu.d.ts → vite-plugin.BI9taN75.d.ts} +1 -22
- package/dist/shared/vite-plugin.CcvHfrL8.cjs +1 -0
- package/dist/shared/vite-plugin.CuXEJAWX.mjs +1 -0
- package/package.json +7 -17
- package/dist/common/compress/index.cjs +0 -1
- package/dist/common/compress/index.d.cts +0 -23
- package/dist/common/compress/index.d.mts +0 -23
- package/dist/common/compress/index.d.ts +0 -23
- package/dist/common/compress/index.mjs +0 -1
- package/dist/common/object/index.cjs +0 -1
- package/dist/common/object/index.d.cts +0 -30
- package/dist/common/object/index.d.mts +0 -30
- package/dist/common/object/index.d.ts +0 -30
- package/dist/common/object/index.mjs +0 -1
- package/dist/common/path/index.cjs +0 -1
- package/dist/common/path/index.d.cts +0 -22
- package/dist/common/path/index.d.mts +0 -22
- package/dist/common/path/index.d.ts +0 -22
- package/dist/common/path/index.mjs +0 -1
- package/dist/shared/vite-plugin.BCuhU1au.mjs +0 -7
- package/dist/shared/vite-plugin.BrI73DHA.cjs +0 -7
- package/dist/shared/vite-plugin.CLr0ttuO.d.cts +0 -135
- package/dist/shared/vite-plugin.CLr0ttuO.d.mts +0 -135
- package/dist/shared/vite-plugin.CLr0ttuO.d.ts +0 -135
- package/dist/shared/vite-plugin.CmtcnItg.d.cts +0 -261
- package/dist/shared/vite-plugin.CmtcnItg.d.mts +0 -261
- package/dist/shared/vite-plugin.CmtcnItg.d.ts +0 -261
- package/dist/shared/vite-plugin.DnFDPjNf.mjs +0 -1
- package/dist/shared/vite-plugin.Dumot0up.mjs +0 -1
- package/dist/shared/vite-plugin.soT9a-KD.cjs +0 -1
- package/dist/shared/vite-plugin.vwox4bU0.cjs +0 -1
|
@@ -22,34 +22,6 @@ interface DateFormatOptions {
|
|
|
22
22
|
timestamp: string;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* 数字补零格式化
|
|
27
|
-
*
|
|
28
|
-
* @param num 要格式化的数字
|
|
29
|
-
* @param length 目标长度
|
|
30
|
-
* @returns 补零后的字符串
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* padNumber(5, 2) // '05'
|
|
35
|
-
* padNumber(12, 3) // '012'
|
|
36
|
-
* padNumber(123, 2) // '123'
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
declare function padNumber(num: number, length?: number): string;
|
|
40
|
-
/**
|
|
41
|
-
* 生成随机哈希字符串
|
|
42
|
-
*
|
|
43
|
-
* @param length 哈希长度,范围 1-64
|
|
44
|
-
* @returns 随机哈希字符串
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* generateRandomHash(8) // 'a1b2c3d4'
|
|
49
|
-
* generateRandomHash(16) // 'a1b2c3d4e5f6g7h8'
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
declare function generateRandomHash(length?: number): string;
|
|
53
25
|
/**
|
|
54
26
|
* 获取日期格式化参数
|
|
55
27
|
*
|
|
@@ -64,93 +36,39 @@ declare function generateRandomHash(length?: number): string;
|
|
|
64
36
|
*/
|
|
65
37
|
declare function getDateFormatParams(date?: Date): DateFormatOptions;
|
|
66
38
|
/**
|
|
67
|
-
*
|
|
39
|
+
* 替换模板字符串中的变量占位符
|
|
68
40
|
*
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @returns
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```typescript
|
|
75
|
-
* formatDate(new Date(), '{YYYY}-{MM}-{DD}') // '2026-02-03'
|
|
76
|
-
* formatDate(new Date(), '{YYYY}{MM}{DD}{HH}{mm}{ss}') // '20260203153000'
|
|
77
|
-
* formatDate(new Date(), '{YYYY}.{MM}.{DD}') // '2026.02.03'
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
declare function formatDate(date: Date, format: string): string;
|
|
81
|
-
/**
|
|
82
|
-
* 解析模板字符串,替换占位符
|
|
41
|
+
* @param template - 包含 `{{key}}` 占位符的模板字符串
|
|
42
|
+
* @param values - 占位符键值映射,支持合并多组变量(后者覆盖前者)
|
|
43
|
+
* @returns 替换占位符后的字符串
|
|
83
44
|
*
|
|
84
|
-
* @
|
|
85
|
-
*
|
|
86
|
-
* @returns 替换后的字符串
|
|
45
|
+
* @description 将模板中的 `{{key}}` 占位符替换为对应的值。
|
|
46
|
+
* 键名中的正则特殊字符会被自动转义,值中的 `$` 也会被安全处理。
|
|
87
47
|
*
|
|
88
48
|
* @example
|
|
89
49
|
* ```typescript
|
|
90
|
-
* parseTemplate('{name}
|
|
91
|
-
* // '
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
declare function parseTemplate(template: string, values: Record<string, string>): string;
|
|
95
|
-
/**
|
|
96
|
-
* 将字符串转换为驼峰命名(camelCase)
|
|
97
|
-
*
|
|
98
|
-
* @param str 输入字符串
|
|
99
|
-
* @param separators 分隔符正则,默认为斜杠和横线
|
|
100
|
-
* @returns 驼峰命名字符串
|
|
50
|
+
* parseTemplate('Hello {{name}}!', { name: 'World' })
|
|
51
|
+
* // 'Hello World!'
|
|
101
52
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* toCamelCase('pages/user/profile') // 'pagesUserProfile'
|
|
105
|
-
* toCamelCase('user-profile-page') // 'userProfilePage'
|
|
106
|
-
* toCamelCase('/pages/index') // 'pagesIndex'
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
declare function toCamelCase(str: string, separators?: RegExp): string;
|
|
110
|
-
/**
|
|
111
|
-
* 将字符串转换为帕斯卡命名(PascalCase)
|
|
112
|
-
*
|
|
113
|
-
* @param str 输入字符串
|
|
114
|
-
* @param separators 分隔符正则,默认为斜杠和横线
|
|
115
|
-
* @returns 帕斯卡命名字符串
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```typescript
|
|
119
|
-
* toPascalCase('pages/user/profile') // 'PagesUserProfile'
|
|
120
|
-
* toPascalCase('user-profile-page') // 'UserProfilePage'
|
|
121
|
-
* toPascalCase('/pages/index') // 'PagesIndex'
|
|
53
|
+
* parseTemplate('{{YYYY}}-{{MM}}-{{DD}}', getDateFormatParams())
|
|
54
|
+
* // '2026-06-06'
|
|
122
55
|
* ```
|
|
123
56
|
*/
|
|
124
|
-
declare function
|
|
125
|
-
/**
|
|
126
|
-
* 移除 JSON 字符串中的注释
|
|
127
|
-
*
|
|
128
|
-
* @param jsonString 包含注释的 JSON 字符串
|
|
129
|
-
* @returns 移除注释后的 JSON 字符串
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```typescript
|
|
133
|
-
* stripJsonComments('{\n // comment\n "name": "test"\n}')
|
|
134
|
-
* // '{\n "name": "test"\n}'
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
declare function stripJsonComments(jsonString: string): string;
|
|
57
|
+
declare function parseTemplate(template: string, values: Record<string, string>): string;
|
|
138
58
|
/**
|
|
139
|
-
*
|
|
59
|
+
* 格式化日期字符串
|
|
140
60
|
*
|
|
141
|
-
* @param
|
|
142
|
-
* @
|
|
61
|
+
* @param date - 日期对象
|
|
62
|
+
* @param format - 格式字符串,支持 `{YYYY}`、`{MM}`、`{DD}`、`{HH}`、`{mm}`、`{ss}` 等占位符
|
|
63
|
+
* @returns 格式化后的日期字符串
|
|
143
64
|
*
|
|
144
65
|
* @example
|
|
145
66
|
* ```typescript
|
|
146
|
-
*
|
|
147
|
-
* // '
|
|
148
|
-
*
|
|
149
|
-
* escapeHtmlAttr('<script>alert(1)</script>')
|
|
150
|
-
* // '<script>alert(1)</script>'
|
|
67
|
+
* formatDate(new Date(), '{YYYY}-{MM}-{DD}T{HH}:{mm}:{ss}')
|
|
68
|
+
* // '2026-06-06T15:30:00'
|
|
151
69
|
* ```
|
|
152
70
|
*/
|
|
153
|
-
declare function
|
|
71
|
+
declare function formatDate(date: Date, format: string): string;
|
|
154
72
|
/**
|
|
155
73
|
* 将字节数格式化为人类可读的文件大小字符串
|
|
156
74
|
*
|
|
@@ -170,19 +88,6 @@ declare function escapeHtmlAttr(str: string): string;
|
|
|
170
88
|
* ```
|
|
171
89
|
*/
|
|
172
90
|
declare function formatFileSize(bytes: number): string;
|
|
173
|
-
/**
|
|
174
|
-
* 获取文件扩展名
|
|
175
|
-
*
|
|
176
|
-
* @param {string} filePath - 文件路径
|
|
177
|
-
* @returns {string} 小写的文件扩展名(如 '.js')
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```typescript
|
|
181
|
-
* getExtension('dist/app.js') // '.js'
|
|
182
|
-
* getExtension('dist/style.CSS') // '.css'
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
declare function getExtension(filePath: string): string;
|
|
186
91
|
|
|
187
|
-
export {
|
|
92
|
+
export { formatDate, formatFileSize, getDateFormatParams, parseTemplate };
|
|
188
93
|
export type { DateFormatOptions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function e(t,n=2){return t.toString().padStart(n,"0")}function g(t=new Date){return{YYYY:t.getFullYear().toString(),YY:t.getFullYear().toString().slice(-2),MM:e(t.getMonth()+1),DD:e(t.getDate()),HH:e(t.getHours()),mm:e(t.getMinutes()),ss:e(t.getSeconds()),SSS:e(t.getMilliseconds(),3),timestamp:t.getTime().toString()}}function c(t,n){let r=t;for(const[o,i]of Object.entries(n)){const a=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=i.replace(/\$/g,"$$$$");r=r.replace(new RegExp(`\\{\\{${a}\\}\\}`,"g"),s)}return r}function l(t,n){const r=g(t);let o=n;for(const[i,a]of Object.entries(r))o=o.replace(new RegExp(`\\{${i}\\}`,"g"),a);return o}function u(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/(1024*1024)).toFixed(2)}MB`}export{l as formatDate,u as formatFileSize,g as getDateFormatParams,c as parseTemplate};
|
package/dist/common/fs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const s=require("fs"),
|
|
1
|
+
"use strict";const s=require("fs"),u=require("path");function _interopDefaultCompat(t){return t&&typeof t=="object"&&"default"in t?t.default:t}const s__default=_interopDefaultCompat(s),u__default=_interopDefaultCompat(u),R=10;async function checkSourceExists(t){try{await s__default.promises.access(t,s__default.constants.F_OK)}catch(e){const i=e;throw i.code==="ENOENT"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${t}`):i.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6E90\u6587\u4EF6 - ${t}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u68C0\u67E5\u6E90\u6587\u4EF6\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${i.message}`)}}async function g(t){try{await s__default.promises.mkdir(t,{recursive:!0})}catch(e){const i=e;throw i.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u521B\u5EFA\u76EE\u6807\u76EE\u5F55 - ${t}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u521B\u5EFA\u76EE\u6807\u76EE\u5F55\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${i.message}`)}}async function h(t,e){const i=await s__default.promises.readdir(t,{withFileTypes:!0}),r=[];for(const o of i){const c=u__default.join(t,o.name),l=o.isFile(),F=o.isDirectory();if(r.push({path:c,isFile:l,isDirectory:F}),F&&e){const p=await h(c,e);r.push(...p)}}return r}async function C(t,e){try{const[i,r]=await Promise.all([s__default.promises.stat(t),s__default.promises.stat(e)]);return i.mtimeMs>r.mtimeMs||i.size!==r.size}catch{return!0}}async function D(t){try{return await s__default.promises.access(t,s__default.constants.F_OK),!0}catch{return!1}}async function T(t,e,i){const r=[];let o=0;async function c(){for(;o<t.length;){const F=o++,p=await e(t[F]);r[F]=p}}const l=Array(Math.min(i,t.length)).fill(null).map(()=>c());return await Promise.all(l),r}async function copySourceToTarget(t,e,i){const r=Date.now(),{recursive:o,overwrite:c,incremental:l=!1,parallelLimit:F=R}=i;let p=0,w=0,f=0;if((await s__default.promises.stat(t)).isDirectory()){await g(e);const a=await h(t,o),E=a.filter(n=>n.isFile);f=a.filter(n=>n.isDirectory).length;const S=new Set;for(const n of E){const A=u__default.relative(t,n.path),d=u__default.dirname(u__default.join(e,A));S.add(d)}await Promise.all([...S].map(n=>g(n)));const x=await T(E,async n=>{const A=u__default.relative(t,n.path),d=u__default.join(e,A);let m=c;return m||(m=!await D(d)),l&&m&&(m=await C(n.path,d)),m?(await s__default.promises.copyFile(n.path,d),{copied:!0,skipped:!1}):{copied:!1,skipped:!0}},F);for(const n of x)n.copied&&p++,n.skipped&&w++}else{await g(u__default.dirname(e));let a=c;a||(a=!await D(e)),l&&a&&(a=await C(t,e)),a?(await s__default.promises.copyFile(t,e),p++):w++}const y=Date.now()-r;return{copiedFiles:p,skippedFiles:w,copiedDirs:f,executionTime:y}}async function writeFileContent(t,e){try{await s__default.promises.writeFile(t,e,"utf-8")}catch(i){const r=i;throw r.code==="EACCES"?new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u5199\u5165\u6587\u4EF6 - ${t}`):new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u5199\u5165\u6587\u4EF6\u65F6\u51FA\u9519 - ${t}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}async function scanDirectory(t,e={}){const{includeExtensions:i=[],excludePatterns:r=[],filter:o}=e,c=[];async function l(F){const p=await s__default.promises.readdir(F,{withFileTypes:!0});for(const w of p){const f=u__default.join(F,w.name);if(w.isDirectory()){await l(f);continue}if(!w.isFile()||r.some(E=>E.startsWith("*")?f.endsWith(E.slice(1)):f.includes(E)))continue;const y=u__default.extname(w.name).toLowerCase();if(i.length>0&&!i.includes(y))continue;const a=await s__default.promises.stat(f);o&&!o(f,y,a.size)||c.push({filePath:f,size:a.size,extension:y})}}return await l(t),c}async function writeJsonReport(t,e,i=2){await writeFileContent(t,JSON.stringify(e,null,i))}function writeFileSyncSafely(t,e){const i=u__default.dirname(t);s__default.existsSync(i)||s__default.mkdirSync(i,{recursive:!0}),s__default.writeFileSync(t,e,"utf-8")}function shouldUpdateFileContent(t,e){if(!s__default.existsSync(t))return!0;try{return s__default.readFileSync(t,"utf-8")!==e}catch{return!0}}exports.checkSourceExists=checkSourceExists,exports.copySourceToTarget=copySourceToTarget,exports.scanDirectory=scanDirectory,exports.shouldUpdateFileContent=shouldUpdateFileContent,exports.writeFileContent=writeFileContent,exports.writeFileSyncSafely=writeFileSyncSafely,exports.writeJsonReport=writeJsonReport;
|
|
@@ -45,75 +45,12 @@ interface CopyResult {
|
|
|
45
45
|
executionTime: number;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/**
|
|
49
|
-
* 文件/目录条目信息
|
|
50
|
-
*/
|
|
51
|
-
interface FileEntry {
|
|
52
|
-
/** 完整路径 */
|
|
53
|
-
path: string;
|
|
54
|
-
/** 是否为文件 */
|
|
55
|
-
isFile: boolean;
|
|
56
|
-
/** 是否为目录 */
|
|
57
|
-
isDirectory: boolean;
|
|
58
|
-
}
|
|
59
48
|
/**
|
|
60
49
|
* 检查源文件是否存在
|
|
61
50
|
* @param sourcePath 源文件路径
|
|
62
51
|
* @throws 当源文件不存在或无法访问时抛出异常
|
|
63
52
|
*/
|
|
64
53
|
declare function checkSourceExists(sourcePath: string): Promise<void>;
|
|
65
|
-
/**
|
|
66
|
-
* 创建目标目录
|
|
67
|
-
* @param targetPath 目标目录路径
|
|
68
|
-
* @throws 当无法创建目标目录时抛出异常
|
|
69
|
-
*/
|
|
70
|
-
declare function ensureTargetDir(targetPath: string): Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
* 读取目录内容(优化版:一次性获取文件类型信息)
|
|
73
|
-
* @param dirPath 目录路径
|
|
74
|
-
* @param recursive 是否递归读取
|
|
75
|
-
* @returns 文件和目录条目列表
|
|
76
|
-
*/
|
|
77
|
-
declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<FileEntry[]>;
|
|
78
|
-
/**
|
|
79
|
-
* 检查文件是否需要更新
|
|
80
|
-
* @param sourceFile 源文件路径
|
|
81
|
-
* @param targetFile 目标文件路径
|
|
82
|
-
* @returns 是否需要更新
|
|
83
|
-
*/
|
|
84
|
-
declare function shouldUpdateFile(sourceFile: string, targetFile: string): Promise<boolean>;
|
|
85
|
-
/**
|
|
86
|
-
* 检查文件是否存在
|
|
87
|
-
* @param filePath 文件路径
|
|
88
|
-
* @returns 是否存在
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* if (await fileExists('/path/to/file')) {
|
|
93
|
-
* console.log('文件存在')
|
|
94
|
-
* }
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
declare function fileExists(filePath: string): Promise<boolean>;
|
|
98
|
-
/**
|
|
99
|
-
* 带并发限制的批量执行
|
|
100
|
-
*
|
|
101
|
-
* @param items 待处理项
|
|
102
|
-
* @param handler 处理函数
|
|
103
|
-
* @param concurrency 并发数
|
|
104
|
-
* @returns 处理结果数组,顺序与输入项对应
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* const urls = ['url1', 'url2', 'url3', 'url4', 'url5']
|
|
109
|
-
* const results = await runWithConcurrency(
|
|
110
|
-
* urls,
|
|
111
|
-
* async (url) => fetch(url),
|
|
112
|
-
* 3 // 最多同时处理3个请求
|
|
113
|
-
* )
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
declare function runWithConcurrency<T, R>(items: T[], handler: (item: T) => Promise<R>, concurrency: number): Promise<R[]>;
|
|
117
54
|
/**
|
|
118
55
|
* 执行文件复制操作(优化版:并行IO)
|
|
119
56
|
* @param sourcePath 源文件或目录路径
|
|
@@ -130,21 +67,6 @@ declare function copySourceToTarget(sourcePath: string, targetPath: string, opti
|
|
|
130
67
|
* @throws 当写入过程中出现错误时抛出异常
|
|
131
68
|
*/
|
|
132
69
|
declare function writeFileContent(filePath: string, content: string): Promise<void>;
|
|
133
|
-
/**
|
|
134
|
-
* 读取文件内容
|
|
135
|
-
* @param filePath 文件路径
|
|
136
|
-
* @returns 文件内容字符串
|
|
137
|
-
* @throws 当读取过程中出现错误时抛出异常
|
|
138
|
-
*/
|
|
139
|
-
declare function readFileContent(filePath: string): Promise<string>;
|
|
140
|
-
/**
|
|
141
|
-
* 同步读取文件内容
|
|
142
|
-
* @param filePath 文件路径
|
|
143
|
-
* @returns 文件内容字符串
|
|
144
|
-
* @throws 当读取过程中出现错误时抛出异常
|
|
145
|
-
* @deprecated 请使用异步版本 readFileContent
|
|
146
|
-
*/
|
|
147
|
-
declare function readFileSync(filePath: string): string;
|
|
148
70
|
/**
|
|
149
71
|
* 扫描目录中的文件信息
|
|
150
72
|
*/
|
|
@@ -177,20 +99,11 @@ interface ScanDirectoryOptions {
|
|
|
177
99
|
*
|
|
178
100
|
* @description 递归遍历指定目录下的所有文件,收集每个文件的大小和扩展名信息,
|
|
179
101
|
* 支持按扩展名、路径模式和自定义过滤函数进行过滤。
|
|
180
|
-
* 这是通用的目录扫描函数,可被不同插件复用。
|
|
181
102
|
*
|
|
182
103
|
* @example
|
|
183
104
|
* ```typescript
|
|
184
|
-
* // 扫描所有 .js 文件
|
|
185
105
|
* const jsFiles = await scanDirectory('dist', { includeExtensions: ['.js'] })
|
|
186
|
-
*
|
|
187
|
-
* // 排除 node_modules
|
|
188
106
|
* const files = await scanDirectory('dist', { excludePatterns: ['node_modules'] })
|
|
189
|
-
*
|
|
190
|
-
* // 使用自定义过滤
|
|
191
|
-
* const largeFiles = await scanDirectory('dist', {
|
|
192
|
-
* filter: (filePath, ext, size) => size > 1024
|
|
193
|
-
* })
|
|
194
107
|
* ```
|
|
195
108
|
*/
|
|
196
109
|
declare function scanDirectory(dirPath: string, options?: ScanDirectoryOptions): Promise<ScannedFile[]>;
|
|
@@ -209,10 +122,44 @@ declare function scanDirectory(dirPath: string, options?: ScanDirectoryOptions):
|
|
|
209
122
|
* @example
|
|
210
123
|
* ```typescript
|
|
211
124
|
* await writeJsonReport('dist/report.json', { timestamp: Date.now(), stats: [] })
|
|
212
|
-
* await writeJsonReport('dist/report.json', data, 4)
|
|
213
125
|
* ```
|
|
214
126
|
*/
|
|
215
127
|
declare function writeJsonReport(filePath: string, data: object, indent?: number): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* 同步写入文件内容,自动创建不存在的目录
|
|
130
|
+
*
|
|
131
|
+
* @param filePath 文件路径
|
|
132
|
+
* @param content 文件内容
|
|
133
|
+
*
|
|
134
|
+
* @description 同步写入文件,如果目标目录不存在会自动递归创建。
|
|
135
|
+
* 适用于构建钩子中需要同步写入的场景(如 `transform` 钩子)。
|
|
136
|
+
*
|
|
137
|
+
* @throws 当文件写入失败时(如权限不足),抛出 `NodeJS.ErrnoException`
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* writeFileSyncSafely('/project/src/auto-imports.d.ts', 'declare global { ... }')
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
declare function writeFileSyncSafely(filePath: string, content: string): void;
|
|
145
|
+
/**
|
|
146
|
+
* 检查文件内容是否需要更新(同步版本)
|
|
147
|
+
*
|
|
148
|
+
* @param filePath 文件路径
|
|
149
|
+
* @param newContent 新生成的文件内容
|
|
150
|
+
* @returns 如果需要更新返回 `true`,否则返回 `false`
|
|
151
|
+
*
|
|
152
|
+
* @description 对比现有文件内容与新生成的内容,
|
|
153
|
+
* 仅在内容发生变化时才需要写入,减少不必要的文件 IO 操作。
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* if (shouldUpdateFileContent('/project/src/auto-imports.d.ts', newContent)) {
|
|
158
|
+
* writeFileSyncSafely('/project/src/auto-imports.d.ts', newContent)
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
declare function shouldUpdateFileContent(filePath: string, newContent: string): boolean;
|
|
216
163
|
|
|
217
|
-
export { checkSourceExists, copySourceToTarget,
|
|
164
|
+
export { checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport };
|
|
218
165
|
export type { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile };
|
|
@@ -45,75 +45,12 @@ interface CopyResult {
|
|
|
45
45
|
executionTime: number;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/**
|
|
49
|
-
* 文件/目录条目信息
|
|
50
|
-
*/
|
|
51
|
-
interface FileEntry {
|
|
52
|
-
/** 完整路径 */
|
|
53
|
-
path: string;
|
|
54
|
-
/** 是否为文件 */
|
|
55
|
-
isFile: boolean;
|
|
56
|
-
/** 是否为目录 */
|
|
57
|
-
isDirectory: boolean;
|
|
58
|
-
}
|
|
59
48
|
/**
|
|
60
49
|
* 检查源文件是否存在
|
|
61
50
|
* @param sourcePath 源文件路径
|
|
62
51
|
* @throws 当源文件不存在或无法访问时抛出异常
|
|
63
52
|
*/
|
|
64
53
|
declare function checkSourceExists(sourcePath: string): Promise<void>;
|
|
65
|
-
/**
|
|
66
|
-
* 创建目标目录
|
|
67
|
-
* @param targetPath 目标目录路径
|
|
68
|
-
* @throws 当无法创建目标目录时抛出异常
|
|
69
|
-
*/
|
|
70
|
-
declare function ensureTargetDir(targetPath: string): Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
* 读取目录内容(优化版:一次性获取文件类型信息)
|
|
73
|
-
* @param dirPath 目录路径
|
|
74
|
-
* @param recursive 是否递归读取
|
|
75
|
-
* @returns 文件和目录条目列表
|
|
76
|
-
*/
|
|
77
|
-
declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<FileEntry[]>;
|
|
78
|
-
/**
|
|
79
|
-
* 检查文件是否需要更新
|
|
80
|
-
* @param sourceFile 源文件路径
|
|
81
|
-
* @param targetFile 目标文件路径
|
|
82
|
-
* @returns 是否需要更新
|
|
83
|
-
*/
|
|
84
|
-
declare function shouldUpdateFile(sourceFile: string, targetFile: string): Promise<boolean>;
|
|
85
|
-
/**
|
|
86
|
-
* 检查文件是否存在
|
|
87
|
-
* @param filePath 文件路径
|
|
88
|
-
* @returns 是否存在
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* if (await fileExists('/path/to/file')) {
|
|
93
|
-
* console.log('文件存在')
|
|
94
|
-
* }
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
declare function fileExists(filePath: string): Promise<boolean>;
|
|
98
|
-
/**
|
|
99
|
-
* 带并发限制的批量执行
|
|
100
|
-
*
|
|
101
|
-
* @param items 待处理项
|
|
102
|
-
* @param handler 处理函数
|
|
103
|
-
* @param concurrency 并发数
|
|
104
|
-
* @returns 处理结果数组,顺序与输入项对应
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* const urls = ['url1', 'url2', 'url3', 'url4', 'url5']
|
|
109
|
-
* const results = await runWithConcurrency(
|
|
110
|
-
* urls,
|
|
111
|
-
* async (url) => fetch(url),
|
|
112
|
-
* 3 // 最多同时处理3个请求
|
|
113
|
-
* )
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
declare function runWithConcurrency<T, R>(items: T[], handler: (item: T) => Promise<R>, concurrency: number): Promise<R[]>;
|
|
117
54
|
/**
|
|
118
55
|
* 执行文件复制操作(优化版:并行IO)
|
|
119
56
|
* @param sourcePath 源文件或目录路径
|
|
@@ -130,21 +67,6 @@ declare function copySourceToTarget(sourcePath: string, targetPath: string, opti
|
|
|
130
67
|
* @throws 当写入过程中出现错误时抛出异常
|
|
131
68
|
*/
|
|
132
69
|
declare function writeFileContent(filePath: string, content: string): Promise<void>;
|
|
133
|
-
/**
|
|
134
|
-
* 读取文件内容
|
|
135
|
-
* @param filePath 文件路径
|
|
136
|
-
* @returns 文件内容字符串
|
|
137
|
-
* @throws 当读取过程中出现错误时抛出异常
|
|
138
|
-
*/
|
|
139
|
-
declare function readFileContent(filePath: string): Promise<string>;
|
|
140
|
-
/**
|
|
141
|
-
* 同步读取文件内容
|
|
142
|
-
* @param filePath 文件路径
|
|
143
|
-
* @returns 文件内容字符串
|
|
144
|
-
* @throws 当读取过程中出现错误时抛出异常
|
|
145
|
-
* @deprecated 请使用异步版本 readFileContent
|
|
146
|
-
*/
|
|
147
|
-
declare function readFileSync(filePath: string): string;
|
|
148
70
|
/**
|
|
149
71
|
* 扫描目录中的文件信息
|
|
150
72
|
*/
|
|
@@ -177,20 +99,11 @@ interface ScanDirectoryOptions {
|
|
|
177
99
|
*
|
|
178
100
|
* @description 递归遍历指定目录下的所有文件,收集每个文件的大小和扩展名信息,
|
|
179
101
|
* 支持按扩展名、路径模式和自定义过滤函数进行过滤。
|
|
180
|
-
* 这是通用的目录扫描函数,可被不同插件复用。
|
|
181
102
|
*
|
|
182
103
|
* @example
|
|
183
104
|
* ```typescript
|
|
184
|
-
* // 扫描所有 .js 文件
|
|
185
105
|
* const jsFiles = await scanDirectory('dist', { includeExtensions: ['.js'] })
|
|
186
|
-
*
|
|
187
|
-
* // 排除 node_modules
|
|
188
106
|
* const files = await scanDirectory('dist', { excludePatterns: ['node_modules'] })
|
|
189
|
-
*
|
|
190
|
-
* // 使用自定义过滤
|
|
191
|
-
* const largeFiles = await scanDirectory('dist', {
|
|
192
|
-
* filter: (filePath, ext, size) => size > 1024
|
|
193
|
-
* })
|
|
194
107
|
* ```
|
|
195
108
|
*/
|
|
196
109
|
declare function scanDirectory(dirPath: string, options?: ScanDirectoryOptions): Promise<ScannedFile[]>;
|
|
@@ -209,10 +122,44 @@ declare function scanDirectory(dirPath: string, options?: ScanDirectoryOptions):
|
|
|
209
122
|
* @example
|
|
210
123
|
* ```typescript
|
|
211
124
|
* await writeJsonReport('dist/report.json', { timestamp: Date.now(), stats: [] })
|
|
212
|
-
* await writeJsonReport('dist/report.json', data, 4)
|
|
213
125
|
* ```
|
|
214
126
|
*/
|
|
215
127
|
declare function writeJsonReport(filePath: string, data: object, indent?: number): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* 同步写入文件内容,自动创建不存在的目录
|
|
130
|
+
*
|
|
131
|
+
* @param filePath 文件路径
|
|
132
|
+
* @param content 文件内容
|
|
133
|
+
*
|
|
134
|
+
* @description 同步写入文件,如果目标目录不存在会自动递归创建。
|
|
135
|
+
* 适用于构建钩子中需要同步写入的场景(如 `transform` 钩子)。
|
|
136
|
+
*
|
|
137
|
+
* @throws 当文件写入失败时(如权限不足),抛出 `NodeJS.ErrnoException`
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* writeFileSyncSafely('/project/src/auto-imports.d.ts', 'declare global { ... }')
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
declare function writeFileSyncSafely(filePath: string, content: string): void;
|
|
145
|
+
/**
|
|
146
|
+
* 检查文件内容是否需要更新(同步版本)
|
|
147
|
+
*
|
|
148
|
+
* @param filePath 文件路径
|
|
149
|
+
* @param newContent 新生成的文件内容
|
|
150
|
+
* @returns 如果需要更新返回 `true`,否则返回 `false`
|
|
151
|
+
*
|
|
152
|
+
* @description 对比现有文件内容与新生成的内容,
|
|
153
|
+
* 仅在内容发生变化时才需要写入,减少不必要的文件 IO 操作。
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* if (shouldUpdateFileContent('/project/src/auto-imports.d.ts', newContent)) {
|
|
158
|
+
* writeFileSyncSafely('/project/src/auto-imports.d.ts', newContent)
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
declare function shouldUpdateFileContent(filePath: string, newContent: string): boolean;
|
|
216
163
|
|
|
217
|
-
export { checkSourceExists, copySourceToTarget,
|
|
164
|
+
export { checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport };
|
|
218
165
|
export type { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile };
|