@meng-xi/vite-plugin 0.1.4 → 0.1.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 +8 -8
- package/README.md +7 -7
- package/dist/common/format/index.cjs +1 -1
- package/dist/common/format/index.d.cts +1 -130
- package/dist/common/format/index.d.mts +1 -130
- package/dist/common/format/index.d.ts +1 -130
- package/dist/common/format/index.mjs +1 -1
- package/dist/common/fs/index.cjs +1 -1
- package/dist/common/fs/index.d.cts +1 -89
- package/dist/common/fs/index.d.mts +1 -89
- package/dist/common/fs/index.d.ts +1 -89
- package/dist/common/fs/index.mjs +1 -1
- package/dist/common/html/index.cjs +2 -2
- package/dist/common/html/index.d.cts +4 -315
- package/dist/common/html/index.d.mts +4 -315
- package/dist/common/html/index.d.ts +4 -315
- 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 +17 -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 +17 -0
- package/dist/plugins/buildProgress/index.cjs +2 -2
- 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 +11 -11
- 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 +8 -8
- 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 +4 -4
- package/dist/plugins/generateRouter/index.d.cts +1 -1
- package/dist/plugins/generateRouter/index.d.mts +1 -1
- package/dist/plugins/generateRouter/index.d.ts +1 -1
- package/dist/plugins/generateRouter/index.mjs +4 -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 +11 -11
- package/dist/plugins/versionUpdateChecker/index.cjs +2 -2
- 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 +3 -3
- 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.BPFqtmWa.mjs +1 -0
- package/dist/shared/vite-plugin.CnOy46d3.cjs +1 -0
- package/package.json +6 -16
- 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
package/README-en.md
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
## Features
|
|
17
17
|
|
|
18
|
-
- **Ready to Use** -
|
|
19
|
-
global Loading, and more
|
|
18
|
+
- **Ready to Use** - 12 practical plugins covering auto-import, build progress, bundle analysis & compression, file copying, environment variable validation, route generation, version management, HTML injection, favicon
|
|
19
|
+
management, global Loading, and more
|
|
20
20
|
- **Plugin Development Framework** - Exports core components like BasePlugin, Logger, and Validator to quickly build custom Vite plugins
|
|
21
21
|
- **Common Utility Library** - Built-in Common utility modules supporting on-demand sub-path imports
|
|
22
22
|
- **Type Safe** - Complete TypeScript type definitions with configuration validators
|
|
@@ -41,10 +41,11 @@ pnpm add @meng-xi/vite-plugin -D
|
|
|
41
41
|
|
|
42
42
|
```typescript
|
|
43
43
|
import { defineConfig } from 'vite'
|
|
44
|
-
import { buildProgress, bundleAnalyzer, compressAssets, copyFile, envGuard, generateRouter, generateVersion, versionUpdateChecker, htmlInject, faviconManager, loadingManager } from '@meng-xi/vite-plugin'
|
|
44
|
+
import { buildProgress, bundleAnalyzer, compressAssets, copyFile, envGuard, generateRouter, generateVersion, versionUpdateChecker, htmlInject, faviconManager, loadingManager, autoImport } from '@meng-xi/vite-plugin'
|
|
45
45
|
|
|
46
46
|
export default defineConfig({
|
|
47
47
|
plugins: [
|
|
48
|
+
autoImport({ imports: { vue: ['ref', 'reactive', 'computed'] }, dts: 'src/auto-imports.d.ts' }),
|
|
48
49
|
buildProgress(),
|
|
49
50
|
bundleAnalyzer({ outputFormat: 'both' }),
|
|
50
51
|
compressAssets({ algorithm: 'gzip' }),
|
|
@@ -64,6 +65,7 @@ export default defineConfig({
|
|
|
64
65
|
|
|
65
66
|
| Plugin | Description |
|
|
66
67
|
| ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
|
68
|
+
| [autoImport](https://mengxi-studio.github.io/vite-plugin/en/plugins/auto-import.html) | Auto-inject import statements with preset mappings, directory scanning, and Vue template auto-import |
|
|
67
69
|
| [buildProgress](https://mengxi-studio.github.io/vite-plugin/en/plugins/build-progress.html) | Real-time terminal build progress bar, supports bar / spinner / minimal |
|
|
68
70
|
| [bundleAnalyzer](https://mengxi-studio.github.io/vite-plugin/en/plugins/bundle-analyzer.html) | Bundle volume analysis with JSON/HTML reports, gzip calculation, threshold alerts, and build diff |
|
|
69
71
|
| [compressAssets](https://mengxi-studio.github.io/vite-plugin/en/plugins/compress-assets.html) | Asset compression with gzip / brotli / both, concurrent compression and statistics report |
|
|
@@ -132,19 +134,16 @@ Built-in general-purpose utility function library, organized by functional modul
|
|
|
132
134
|
```typescript
|
|
133
135
|
import { formatFileSize } from '@meng-xi/vite-plugin/common/format'
|
|
134
136
|
import { scanDirectory } from '@meng-xi/vite-plugin/common/fs'
|
|
135
|
-
import {
|
|
137
|
+
import { injectBeforeTag } from '@meng-xi/vite-plugin/common/html'
|
|
136
138
|
```
|
|
137
139
|
|
|
138
140
|
| Sub-path | Description |
|
|
139
141
|
| -------------------------------------------------------------------------------------------- | ----------------------- |
|
|
140
|
-
| [`common/compress`](https://mengxi-studio.github.io/vite-plugin/en/common/compress.html) | Compression utilities |
|
|
141
142
|
| [`common/format`](https://mengxi-studio.github.io/vite-plugin/en/common/format.html) | Formatting utilities |
|
|
142
143
|
| [`common/fs`](https://mengxi-studio.github.io/vite-plugin/en/common/fs.html) | File system utilities |
|
|
143
144
|
| [`common/html`](https://mengxi-studio.github.io/vite-plugin/en/common/html.html) | HTML injection utils |
|
|
144
|
-
| [`common/object`](https://mengxi-studio.github.io/vite-plugin/en/common/object.html) | Object operation utils |
|
|
145
|
-
| [`common/path`](https://mengxi-studio.github.io/vite-plugin/en/common/path.html) | Path handling utils |
|
|
146
145
|
| [`common/script`](https://mengxi-studio.github.io/vite-plugin/en/common/script.html) | Script generation utils |
|
|
147
|
-
| [`common/ui`](https://mengxi-studio.github.io/vite-plugin/en/common/)
|
|
146
|
+
| [`common/ui`](https://mengxi-studio.github.io/vite-plugin/en/common/ui.html) | Terminal UI utils |
|
|
148
147
|
| [`common/validation`](https://mengxi-studio.github.io/vite-plugin/en/common/validation.html) | Validation utilities |
|
|
149
148
|
|
|
150
149
|
## Sub-path Exports
|
|
@@ -157,6 +156,7 @@ import { calculateGzipSize } from '@meng-xi/vite-plugin/common/compress'
|
|
|
157
156
|
| `@meng-xi/vite-plugin/plugins` | All plugins |
|
|
158
157
|
| `@meng-xi/vite-plugin/common` | All utility functions |
|
|
159
158
|
| `@meng-xi/vite-plugin/common/*` | Utility sub-modules |
|
|
159
|
+
| `@meng-xi/vite-plugin/plugins/auto-import` | autoImport plugin |
|
|
160
160
|
| `@meng-xi/vite-plugin/plugins/build-progress` | buildProgress plugin |
|
|
161
161
|
| `@meng-xi/vite-plugin/plugins/bundle-analyzer` | bundleAnalyzer plugin |
|
|
162
162
|
| `@meng-xi/vite-plugin/plugins/compress-assets` | compressAssets plugin |
|
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
## 特性
|
|
17
17
|
|
|
18
|
-
- **开箱即用** -
|
|
18
|
+
- **开箱即用** - 12 个实用插件,覆盖自动导入、构建进度、产物分析与压缩、文件复制、环境变量校验、路由生成、版本管理、HTML 注入、图标管理、全局 Loading 等场景
|
|
19
19
|
- **插件开发框架** - 导出 BasePlugin、Logger、Validator 等核心组件,快速构建自定义 Vite 插件
|
|
20
20
|
- **通用工具库** - 内置 Common 工具模块,支持按需子路径导入
|
|
21
21
|
- **类型安全** - 完整 TypeScript 类型定义与配置验证器
|
|
@@ -40,10 +40,11 @@ pnpm add @meng-xi/vite-plugin -D
|
|
|
40
40
|
|
|
41
41
|
```typescript
|
|
42
42
|
import { defineConfig } from 'vite'
|
|
43
|
-
import { buildProgress, bundleAnalyzer, compressAssets, copyFile, envGuard, generateRouter, generateVersion, versionUpdateChecker, htmlInject, faviconManager, loadingManager } from '@meng-xi/vite-plugin'
|
|
43
|
+
import { buildProgress, bundleAnalyzer, compressAssets, copyFile, envGuard, generateRouter, generateVersion, versionUpdateChecker, htmlInject, faviconManager, loadingManager, autoImport } from '@meng-xi/vite-plugin'
|
|
44
44
|
|
|
45
45
|
export default defineConfig({
|
|
46
46
|
plugins: [
|
|
47
|
+
autoImport({ imports: { vue: ['ref', 'reactive', 'computed'] }, dts: 'src/auto-imports.d.ts' }),
|
|
47
48
|
buildProgress(),
|
|
48
49
|
bundleAnalyzer({ outputFormat: 'both' }),
|
|
49
50
|
compressAssets({ algorithm: 'gzip' }),
|
|
@@ -63,6 +64,7 @@ export default defineConfig({
|
|
|
63
64
|
|
|
64
65
|
| 插件 | 说明 |
|
|
65
66
|
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
|
|
67
|
+
| [autoImport](https://mengxi-studio.github.io/vite-plugin/plugins/auto-import.html) | 自动注入 import 语句,支持预设映射、目录扫描和 Vue 模板自动导入 |
|
|
66
68
|
| [buildProgress](https://mengxi-studio.github.io/vite-plugin/plugins/build-progress.html) | 终端实时构建进度条,支持 bar / spinner / minimal |
|
|
67
69
|
| [bundleAnalyzer](https://mengxi-studio.github.io/vite-plugin/plugins/bundle-analyzer.html) | 构建产物体积分析,支持 JSON/HTML 报告、gzip 计算、阈值告警和构建对比 |
|
|
68
70
|
| [compressAssets](https://mengxi-studio.github.io/vite-plugin/plugins/compress-assets.html) | 构建产物压缩,支持 gzip / brotli / both,并发压缩和统计报告 |
|
|
@@ -131,19 +133,16 @@ export const myPlugin = createPluginFactory(MyPlugin)
|
|
|
131
133
|
```typescript
|
|
132
134
|
import { formatFileSize } from '@meng-xi/vite-plugin/common/format'
|
|
133
135
|
import { scanDirectory } from '@meng-xi/vite-plugin/common/fs'
|
|
134
|
-
import {
|
|
136
|
+
import { injectBeforeTag } from '@meng-xi/vite-plugin/common/html'
|
|
135
137
|
```
|
|
136
138
|
|
|
137
139
|
| 子路径 | 描述 |
|
|
138
140
|
| ----------------------------------------------------------------------------------------- | ------------- |
|
|
139
|
-
| [`common/compress`](https://mengxi-studio.github.io/vite-plugin/common/compress.html) | 压缩算法工具 |
|
|
140
141
|
| [`common/format`](https://mengxi-studio.github.io/vite-plugin/common/format.html) | 格式化工具 |
|
|
141
142
|
| [`common/fs`](https://mengxi-studio.github.io/vite-plugin/common/fs.html) | 文件系统工具 |
|
|
142
143
|
| [`common/html`](https://mengxi-studio.github.io/vite-plugin/common/html.html) | HTML 注入工具 |
|
|
143
|
-
| [`common/object`](https://mengxi-studio.github.io/vite-plugin/common/object.html) | 对象操作工具 |
|
|
144
|
-
| [`common/path`](https://mengxi-studio.github.io/vite-plugin/common/path.html) | 路径处理工具 |
|
|
145
144
|
| [`common/script`](https://mengxi-studio.github.io/vite-plugin/common/script.html) | 脚本生成工具 |
|
|
146
|
-
| [`common/ui`](https://mengxi-studio.github.io/vite-plugin/common/)
|
|
145
|
+
| [`common/ui`](https://mengxi-studio.github.io/vite-plugin/common/ui.html) | 终端 UI 工具 |
|
|
147
146
|
| [`common/validation`](https://mengxi-studio.github.io/vite-plugin/common/validation.html) | 参数验证工具 |
|
|
148
147
|
|
|
149
148
|
## 子路径导出
|
|
@@ -156,6 +155,7 @@ import { calculateGzipSize } from '@meng-xi/vite-plugin/common/compress'
|
|
|
156
155
|
| `@meng-xi/vite-plugin/plugins` | 所有插件 |
|
|
157
156
|
| `@meng-xi/vite-plugin/common` | 所有工具函数 |
|
|
158
157
|
| `@meng-xi/vite-plugin/common/*` | 各工具子模块 |
|
|
158
|
+
| `@meng-xi/vite-plugin/plugins/auto-import` | autoImport 插件 |
|
|
159
159
|
| `@meng-xi/vite-plugin/plugins/build-progress` | buildProgress 插件 |
|
|
160
160
|
| `@meng-xi/vite-plugin/plugins/bundle-analyzer` | bundleAnalyzer 插件 |
|
|
161
161
|
| `@meng-xi/vite-plugin/plugins/compress-assets` | compressAssets 插件 |
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";function r(e,t=2){return e.toString().padStart(t,"0")}function getDateFormatParams(e=new Date){return{YYYY:e.getFullYear().toString(),YY:e.getFullYear().toString().slice(-2),MM:r(e.getMonth()+1),DD:r(e.getDate()),HH:r(e.getHours()),mm:r(e.getMinutes()),ss:r(e.getSeconds()),SSS:r(e.getMilliseconds(),3),timestamp:e.getTime().toString()}}function formatFileSize(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(2)}MB`}exports.formatFileSize=formatFileSize,exports.getDateFormatParams=getDateFormatParams;
|
|
@@ -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
|
*
|
|
@@ -63,94 +35,6 @@ declare function generateRandomHash(length?: number): string;
|
|
|
63
35
|
* ```
|
|
64
36
|
*/
|
|
65
37
|
declare function getDateFormatParams(date?: Date): DateFormatOptions;
|
|
66
|
-
/**
|
|
67
|
-
* 格式化日期
|
|
68
|
-
*
|
|
69
|
-
* @param date 日期对象
|
|
70
|
-
* @param format 格式模板
|
|
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
|
-
* 解析模板字符串,替换占位符
|
|
83
|
-
*
|
|
84
|
-
* @param template 模板字符串
|
|
85
|
-
* @param values 占位符值映射
|
|
86
|
-
* @returns 替换后的字符串
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* parseTemplate('{name}-{version}', { name: 'app', version: '1.0.0' })
|
|
91
|
-
* // 'app-1.0.0'
|
|
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 驼峰命名字符串
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
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'
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
declare function toPascalCase(str: string, separators?: RegExp): string;
|
|
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;
|
|
138
|
-
/**
|
|
139
|
-
* 转义 HTML 属性值中的特殊字符,防止 XSS 注入
|
|
140
|
-
*
|
|
141
|
-
* @param str - 需要转义的字符串
|
|
142
|
-
* @returns 转义后的安全字符串
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```typescript
|
|
146
|
-
* escapeHtmlAttr('hello "world"')
|
|
147
|
-
* // 'hello "world"'
|
|
148
|
-
*
|
|
149
|
-
* escapeHtmlAttr('<script>alert(1)</script>')
|
|
150
|
-
* // '<script>alert(1)</script>'
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
declare function escapeHtmlAttr(str: string): string;
|
|
154
38
|
/**
|
|
155
39
|
* 将字节数格式化为人类可读的文件大小字符串
|
|
156
40
|
*
|
|
@@ -170,19 +54,6 @@ declare function escapeHtmlAttr(str: string): string;
|
|
|
170
54
|
* ```
|
|
171
55
|
*/
|
|
172
56
|
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
57
|
|
|
187
|
-
export {
|
|
58
|
+
export { formatFileSize, getDateFormatParams };
|
|
188
59
|
export type { DateFormatOptions };
|
|
@@ -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
|
*
|
|
@@ -63,94 +35,6 @@ declare function generateRandomHash(length?: number): string;
|
|
|
63
35
|
* ```
|
|
64
36
|
*/
|
|
65
37
|
declare function getDateFormatParams(date?: Date): DateFormatOptions;
|
|
66
|
-
/**
|
|
67
|
-
* 格式化日期
|
|
68
|
-
*
|
|
69
|
-
* @param date 日期对象
|
|
70
|
-
* @param format 格式模板
|
|
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
|
-
* 解析模板字符串,替换占位符
|
|
83
|
-
*
|
|
84
|
-
* @param template 模板字符串
|
|
85
|
-
* @param values 占位符值映射
|
|
86
|
-
* @returns 替换后的字符串
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* parseTemplate('{name}-{version}', { name: 'app', version: '1.0.0' })
|
|
91
|
-
* // 'app-1.0.0'
|
|
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 驼峰命名字符串
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
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'
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
declare function toPascalCase(str: string, separators?: RegExp): string;
|
|
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;
|
|
138
|
-
/**
|
|
139
|
-
* 转义 HTML 属性值中的特殊字符,防止 XSS 注入
|
|
140
|
-
*
|
|
141
|
-
* @param str - 需要转义的字符串
|
|
142
|
-
* @returns 转义后的安全字符串
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```typescript
|
|
146
|
-
* escapeHtmlAttr('hello "world"')
|
|
147
|
-
* // 'hello "world"'
|
|
148
|
-
*
|
|
149
|
-
* escapeHtmlAttr('<script>alert(1)</script>')
|
|
150
|
-
* // '<script>alert(1)</script>'
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
declare function escapeHtmlAttr(str: string): string;
|
|
154
38
|
/**
|
|
155
39
|
* 将字节数格式化为人类可读的文件大小字符串
|
|
156
40
|
*
|
|
@@ -170,19 +54,6 @@ declare function escapeHtmlAttr(str: string): string;
|
|
|
170
54
|
* ```
|
|
171
55
|
*/
|
|
172
56
|
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
57
|
|
|
187
|
-
export {
|
|
58
|
+
export { formatFileSize, getDateFormatParams };
|
|
188
59
|
export type { DateFormatOptions };
|
|
@@ -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
|
*
|
|
@@ -63,94 +35,6 @@ declare function generateRandomHash(length?: number): string;
|
|
|
63
35
|
* ```
|
|
64
36
|
*/
|
|
65
37
|
declare function getDateFormatParams(date?: Date): DateFormatOptions;
|
|
66
|
-
/**
|
|
67
|
-
* 格式化日期
|
|
68
|
-
*
|
|
69
|
-
* @param date 日期对象
|
|
70
|
-
* @param format 格式模板
|
|
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
|
-
* 解析模板字符串,替换占位符
|
|
83
|
-
*
|
|
84
|
-
* @param template 模板字符串
|
|
85
|
-
* @param values 占位符值映射
|
|
86
|
-
* @returns 替换后的字符串
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* parseTemplate('{name}-{version}', { name: 'app', version: '1.0.0' })
|
|
91
|
-
* // 'app-1.0.0'
|
|
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 驼峰命名字符串
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
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'
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
declare function toPascalCase(str: string, separators?: RegExp): string;
|
|
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;
|
|
138
|
-
/**
|
|
139
|
-
* 转义 HTML 属性值中的特殊字符,防止 XSS 注入
|
|
140
|
-
*
|
|
141
|
-
* @param str - 需要转义的字符串
|
|
142
|
-
* @returns 转义后的安全字符串
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```typescript
|
|
146
|
-
* escapeHtmlAttr('hello "world"')
|
|
147
|
-
* // 'hello "world"'
|
|
148
|
-
*
|
|
149
|
-
* escapeHtmlAttr('<script>alert(1)</script>')
|
|
150
|
-
* // '<script>alert(1)</script>'
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
declare function escapeHtmlAttr(str: string): string;
|
|
154
38
|
/**
|
|
155
39
|
* 将字节数格式化为人类可读的文件大小字符串
|
|
156
40
|
*
|
|
@@ -170,19 +54,6 @@ declare function escapeHtmlAttr(str: string): string;
|
|
|
170
54
|
* ```
|
|
171
55
|
*/
|
|
172
56
|
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
57
|
|
|
187
|
-
export {
|
|
58
|
+
export { formatFileSize, getDateFormatParams };
|
|
188
59
|
export type { DateFormatOptions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function t(e,r=2){return e.toString().padStart(r,"0")}function n(e=new Date){return{YYYY:e.getFullYear().toString(),YY:e.getFullYear().toString().slice(-2),MM:t(e.getMonth()+1),DD:t(e.getDate()),HH:t(e.getHours()),mm:t(e.getMinutes()),ss:t(e.getSeconds()),SSS:t(e.getMilliseconds(),3),timestamp:e.getTime().toString()}}function i(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(2)}MB`}export{i as formatFileSize,n as getDateFormatParams};
|
package/dist/common/fs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const n=require("fs"),m=require("path");function _interopDefaultCompat(t){return t&&typeof t=="object"&&"default"in t?t.default:t}const n__default=_interopDefaultCompat(n),m__default=_interopDefaultCompat(m),R=10;async function checkSourceExists(t){try{await n__default.promises.access(t,n__default.constants.F_OK)}catch(u){const e=u;throw e.code==="ENOENT"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${t}`):e.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${e.message}`)}}async function h(t){try{await n__default.promises.mkdir(t,{recursive:!0})}catch(u){const e=u;throw e.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${e.message}`)}}async function C(t,u){const e=await n__default.promises.readdir(t,{withFileTypes:!0}),s=[];for(const o of e){const a=m__default.join(t,o.name),F=o.isFile(),c=o.isDirectory();if(s.push({path:a,isFile:F,isDirectory:c}),c&&u){const l=await C(a,u);s.push(...l)}}return s}async function S(t,u){try{const[e,s]=await Promise.all([n__default.promises.stat(t),n__default.promises.stat(u)]);return e.mtimeMs>s.mtimeMs||e.size!==s.size}catch{return!0}}async function D(t){try{return await n__default.promises.access(t,n__default.constants.F_OK),!0}catch{return!1}}async function T(t,u,e){const s=[];let o=0;async function a(){for(;o<t.length;){const c=o++,l=await u(t[c]);s[c]=l}}const F=Array(Math.min(e,t.length)).fill(null).map(()=>a());return await Promise.all(F),s}async function copySourceToTarget(t,u,e){const s=Date.now(),{recursive:o,overwrite:a,incremental:F=!1,parallelLimit:c=R}=e;let l=0,E=0,p=0;if((await n__default.promises.stat(t)).isDirectory()){await h(u);const r=await C(t,o),w=r.filter(i=>i.isFile);p=r.filter(i=>i.isDirectory).length;const x=new Set;for(const i of w){const A=m__default.relative(t,i.path),d=m__default.dirname(m__default.join(u,A));x.add(d)}await Promise.all([...x].map(i=>h(i)));const g=await T(w,async i=>{const A=m__default.relative(t,i.path),d=m__default.join(u,A);let y=a;return y||(y=!await D(d)),F&&y&&(y=await S(i.path,d)),y?(await n__default.promises.copyFile(i.path,d),{copied:!0,skipped:!1}):{copied:!1,skipped:!0}},c);for(const i of g)i.copied&&l++,i.skipped&&E++}else{await h(m__default.dirname(u));let r=a;r||(r=!await D(u)),F&&r&&(r=await S(t,u)),r?(await n__default.promises.copyFile(t,u),l++):E++}const f=Date.now()-s;return{copiedFiles:l,skippedFiles:E,copiedDirs:p,executionTime:f}}async function writeFileContent(t,u){try{await n__default.promises.writeFile(t,u,"utf-8")}catch(e){const s=e;throw s.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${s.message}`)}}async function scanDirectory(t,u={}){const{includeExtensions:e=[],excludePatterns:s=[],filter:o}=u,a=[];async function F(c){const l=await n__default.promises.readdir(c,{withFileTypes:!0});for(const E of l){const p=m__default.join(c,E.name);if(E.isDirectory()){await F(p);continue}if(!E.isFile()||s.some(w=>w.startsWith("*")?p.endsWith(w.slice(1)):p.includes(w)))continue;const f=m__default.extname(E.name).toLowerCase();if(e.length>0&&!e.includes(f))continue;const r=await n__default.promises.stat(p);o&&!o(p,f,r.size)||a.push({filePath:p,size:r.size,extension:f})}}return await F(t),a}async function writeJsonReport(t,u,e=2){await writeFileContent(t,JSON.stringify(u,null,e))}exports.checkSourceExists=checkSourceExists,exports.copySourceToTarget=copySourceToTarget,exports.scanDirectory=scanDirectory,exports.writeFileContent=writeFileContent,exports.writeJsonReport=writeJsonReport;
|