@meng-xi/vite-plugin 0.0.2 → 0.0.4
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 +37 -23
- package/README.md +64 -5
- package/dist/common/index.cjs +1 -0
- package/dist/common/index.d.cts +235 -0
- package/dist/common/index.d.mts +235 -0
- package/dist/common/index.d.ts +235 -0
- package/dist/common/index.mjs +1 -0
- package/dist/factory/index.cjs +1 -0
- package/dist/factory/index.d.cts +260 -0
- package/dist/factory/index.d.mts +260 -0
- package/dist/factory/index.d.ts +260 -0
- package/dist/factory/index.mjs +1 -0
- package/dist/index.cjs +1 -5
- package/dist/index.d.cts +7 -241
- package/dist/index.d.mts +7 -241
- package/dist/index.d.ts +7 -241
- package/dist/index.mjs +1 -5
- package/dist/logger/index.cjs +1 -0
- package/dist/logger/index.d.cts +1 -0
- package/dist/logger/index.d.mts +1 -0
- package/dist/logger/index.d.ts +1 -0
- package/dist/logger/index.mjs +1 -0
- package/dist/plugins/index.cjs +1 -0
- package/dist/plugins/index.d.cts +375 -0
- package/dist/plugins/index.d.mts +375 -0
- package/dist/plugins/index.d.ts +375 -0
- package/dist/plugins/index.mjs +1 -0
- package/dist/shared/vite-plugin.B3PARlU9.d.cts +119 -0
- package/dist/shared/vite-plugin.B3PARlU9.d.mts +119 -0
- package/dist/shared/vite-plugin.B3PARlU9.d.ts +119 -0
- package/dist/shared/vite-plugin.B88RyRN8.mjs +3 -0
- package/dist/shared/vite-plugin.C7isVPKg.mjs +1 -0
- package/dist/shared/vite-plugin.CiHfwMiN.d.cts +91 -0
- package/dist/shared/vite-plugin.CiHfwMiN.d.mts +91 -0
- package/dist/shared/vite-plugin.CiHfwMiN.d.ts +91 -0
- package/dist/shared/vite-plugin.D6NYITpX.cjs +1 -0
- package/dist/shared/vite-plugin.D8HTI0Ni.cjs +2 -0
- package/dist/shared/vite-plugin.Dd2ogbSe.mjs +2 -0
- package/dist/shared/vite-plugin.DqWt65U-.cjs +1 -0
- package/dist/shared/vite-plugin.HZb-1B5l.mjs +1 -0
- package/dist/shared/vite-plugin.IGZeStMa.cjs +3 -0
- package/dist/shared/vite-plugin.UkE7CdSe.d.cts +43 -0
- package/dist/shared/vite-plugin.UkE7CdSe.d.mts +43 -0
- package/dist/shared/vite-plugin.UkE7CdSe.d.ts +43 -0
- package/package.json +24 -5
package/README-en.md
CHANGED
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
</div>
|
|
14
14
|
|
|
15
|
-
> - This is a toolkit that provides practical plugins for Vite,
|
|
15
|
+
> - This is a toolkit that provides practical plugins for Vite, and also serves as a complete **Vite Plugin Development Framework**.
|
|
16
16
|
> - Extends Vite build process functionality, providing automated processing solutions for common build tasks.
|
|
17
17
|
> - All plugins support detailed configuration options, allowing customization based on project needs to meet different usage scenarios.
|
|
18
18
|
> - Plugins provide error handling mechanisms to ensure build processes can catch errors, improving build reliability.
|
|
19
|
-
> -
|
|
19
|
+
> - Export core components like BasePlugin, Logger, Validator, allowing developers to build custom plugins based on the same infrastructure.
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
@@ -41,7 +41,7 @@ pnpm add @meng-xi/vite-plugin --save-dev
|
|
|
41
41
|
|
|
42
42
|
### Basic Usage
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
#### Using Built-in Plugins
|
|
45
45
|
|
|
46
46
|
```typescript
|
|
47
47
|
import { defineConfig } from 'vite'
|
|
@@ -63,28 +63,42 @@ export default defineConfig({
|
|
|
63
63
|
})
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
You can also use default import to import all plugins:
|
|
66
|
+
#### Developing Custom Plugins
|
|
69
67
|
|
|
70
68
|
```typescript
|
|
71
|
-
import {
|
|
72
|
-
import
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
69
|
+
import { BasePlugin, createPluginFactory, Validator } from '@meng-xi/vite-plugin'
|
|
70
|
+
import type { Plugin } from 'vite'
|
|
71
|
+
|
|
72
|
+
interface MyPluginOptions {
|
|
73
|
+
path: string
|
|
74
|
+
enabled?: boolean
|
|
75
|
+
verbose?: boolean
|
|
76
|
+
errorStrategy?: 'throw' | 'log' | 'ignore'
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
class MyPlugin extends BasePlugin<MyPluginOptions> {
|
|
80
|
+
protected getDefaultOptions() {
|
|
81
|
+
return {
|
|
82
|
+
path: './default'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
protected validateOptions(): void {
|
|
87
|
+
this.validator.field('path').required().string().validate()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
protected getPluginName(): string {
|
|
91
|
+
return 'my-plugin'
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected addPluginHooks(plugin: Plugin): void {
|
|
95
|
+
plugin.buildStart = () => {
|
|
96
|
+
this.logger.info(`Plugin started with path: ${this.options.path}`)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const myPlugin = createPluginFactory(MyPlugin)
|
|
88
102
|
```
|
|
89
103
|
|
|
90
104
|
## Plugin Details
|
package/README.md
CHANGED
|
@@ -14,16 +14,16 @@
|
|
|
14
14
|
|
|
15
15
|
## 简介
|
|
16
16
|
|
|
17
|
-
`@meng-xi/vite-plugin` 是一个为 Vite
|
|
17
|
+
`@meng-xi/vite-plugin` 是一个为 Vite 提供实用插件的工具包,也是一个**完整的插件开发框架**。该框架提供了常用功能的核心工具方法供扩展支持其他拓展工作开展快速开发。
|
|
18
18
|
|
|
19
19
|
## 特性
|
|
20
20
|
|
|
21
21
|
- **增强 Vite 构建流程**:提供实用插件集合,扩展 Vite 功能,简化构建过程中的常见任务,提高开发效率
|
|
22
|
-
-
|
|
22
|
+
- **插件开发框架**:导出核心组件如 BasePlugin、Logger、Validator,允许开发者基于相同基础设施构建自定义插件
|
|
23
23
|
- **高度可配置**:所有功能支持详细配置选项,可根据项目需求自定义行为,满足多样化场景
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
24
|
+
- **单例日志系统**:统一的日志管理器,支持插件级别的日志控制,便于调试和问题排查
|
|
25
|
+
- **类型安全验证**:强类型配置验证器,确保插件配置正确性,提供完整的 TypeScript 类型定义
|
|
26
|
+
- **插件工厂模式**:支持选项标准化器,轻松处理异构输入,简化插件开发工作流
|
|
27
27
|
- **无缝集成**:与 Vite 构建流程无缝集成,无需复杂配置即可快速启用
|
|
28
28
|
- **优化开发体验**:简化常见构建任务,减少手动操作,让开发者专注于核心业务逻辑
|
|
29
29
|
|
|
@@ -46,6 +46,65 @@ yarn add @meng-xi/vite-plugin --save-dev
|
|
|
46
46
|
pnpm add @meng-xi/vite-plugin --save-dev
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
## 基本使用
|
|
50
|
+
|
|
51
|
+
### 使用内置插件
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { defineConfig } from 'vite'
|
|
55
|
+
import { copyFile, injectIco } from '@meng-xi/vite-plugin'
|
|
56
|
+
|
|
57
|
+
export default defineConfig({
|
|
58
|
+
plugins: [
|
|
59
|
+
copyFile({
|
|
60
|
+
sourceDir: 'src/assets',
|
|
61
|
+
targetDir: 'dist/assets'
|
|
62
|
+
}),
|
|
63
|
+
injectIco({
|
|
64
|
+
base: '/assets'
|
|
65
|
+
})
|
|
66
|
+
]
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 开发自定义插件
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { BasePlugin, createPluginFactory, Validator } from '@meng-xi/vite-plugin'
|
|
74
|
+
import type { Plugin } from 'vite'
|
|
75
|
+
|
|
76
|
+
interface MyPluginOptions {
|
|
77
|
+
path: string
|
|
78
|
+
enabled?: boolean
|
|
79
|
+
verbose?: boolean
|
|
80
|
+
errorStrategy?: 'throw' | 'log' | 'ignore'
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
class MyPlugin extends BasePlugin<MyPluginOptions> {
|
|
84
|
+
protected getDefaultOptions() {
|
|
85
|
+
return {
|
|
86
|
+
path: './default'
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
protected validateOptions(): void {
|
|
91
|
+
this.validator.field('path').required().string().validate()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected getPluginName(): string {
|
|
95
|
+
return 'my-plugin'
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
protected addPluginHooks(plugin: Plugin): void {
|
|
99
|
+
plugin.buildStart = () => {
|
|
100
|
+
this.logger.info(`Plugin started with path: ${this.options.path}`)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const myPlugin = createPluginFactory(MyPlugin)
|
|
106
|
+
```
|
|
107
|
+
|
|
49
108
|
## 更新日志
|
|
50
109
|
|
|
51
110
|
[CHANGELOG](https://github.com/MengXi-Studio/vite-plugin/releases)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const format=require("../shared/vite-plugin.D6NYITpX.cjs"),validation=require("../shared/vite-plugin.IGZeStMa.cjs");require("fs"),require("path"),require("crypto"),exports.checkSourceExists=format.checkSourceExists,exports.copySourceToTarget=format.copySourceToTarget,exports.ensureTargetDir=format.ensureTargetDir,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.shouldUpdateFile=format.shouldUpdateFile,exports.writeFileContent=format.writeFileContent,exports.Validator=validation.Validator,exports.deepMerge=validation.deepMerge;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
export { V as Validator } from '../shared/vite-plugin.CiHfwMiN.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 复制操作的选项接口
|
|
5
|
+
*/
|
|
6
|
+
interface CopyOptions {
|
|
7
|
+
/**
|
|
8
|
+
* 是否支持递归复制
|
|
9
|
+
*/
|
|
10
|
+
recursive: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* 是否覆盖同名文件
|
|
13
|
+
*/
|
|
14
|
+
overwrite: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* 是否启用增量复制
|
|
17
|
+
*/
|
|
18
|
+
incremental?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 并行处理的最大文件数
|
|
21
|
+
*/
|
|
22
|
+
parallelLimit?: number;
|
|
23
|
+
/**
|
|
24
|
+
* 是否跳过空目录
|
|
25
|
+
*/
|
|
26
|
+
skipEmptyDirs?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 复制结果接口
|
|
30
|
+
*/
|
|
31
|
+
interface CopyResult {
|
|
32
|
+
/**
|
|
33
|
+
* 复制的文件数量
|
|
34
|
+
*/
|
|
35
|
+
copiedFiles: number;
|
|
36
|
+
/**
|
|
37
|
+
* 跳过的文件数量
|
|
38
|
+
*/
|
|
39
|
+
skippedFiles: number;
|
|
40
|
+
/**
|
|
41
|
+
* 复制的目录数量
|
|
42
|
+
*/
|
|
43
|
+
copiedDirs: number;
|
|
44
|
+
/**
|
|
45
|
+
* 总执行时间(毫秒)
|
|
46
|
+
*/
|
|
47
|
+
executionTime: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 文件/目录条目信息
|
|
52
|
+
*/
|
|
53
|
+
interface FileEntry {
|
|
54
|
+
/** 完整路径 */
|
|
55
|
+
path: string;
|
|
56
|
+
/** 是否为文件 */
|
|
57
|
+
isFile: boolean;
|
|
58
|
+
/** 是否为目录 */
|
|
59
|
+
isDirectory: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 检查源文件是否存在
|
|
63
|
+
* @param sourcePath 源文件路径
|
|
64
|
+
* @throws 当源文件不存在或无法访问时抛出异常
|
|
65
|
+
*/
|
|
66
|
+
declare function checkSourceExists(sourcePath: string): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* 创建目标目录
|
|
69
|
+
* @param targetPath 目标目录路径
|
|
70
|
+
* @throws 当无法创建目标目录时抛出异常
|
|
71
|
+
*/
|
|
72
|
+
declare function ensureTargetDir(targetPath: string): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* 读取目录内容(优化版:一次性获取文件类型信息)
|
|
75
|
+
* @param dirPath 目录路径
|
|
76
|
+
* @param recursive 是否递归读取
|
|
77
|
+
* @returns 文件和目录条目列表
|
|
78
|
+
*/
|
|
79
|
+
declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<FileEntry[]>;
|
|
80
|
+
/**
|
|
81
|
+
* 检查文件是否需要更新
|
|
82
|
+
* @param sourceFile 源文件路径
|
|
83
|
+
* @param targetFile 目标文件路径
|
|
84
|
+
* @returns 是否需要更新
|
|
85
|
+
*/
|
|
86
|
+
declare function shouldUpdateFile(sourceFile: string, targetFile: string): Promise<boolean>;
|
|
87
|
+
/**
|
|
88
|
+
* 执行文件复制操作(优化版:并行IO)
|
|
89
|
+
* @param sourcePath 源文件或目录路径
|
|
90
|
+
* @param targetPath 目标文件或目录路径
|
|
91
|
+
* @param options 复制选项
|
|
92
|
+
* @returns 复制结果
|
|
93
|
+
* @throws 当复制过程中出现错误时抛出异常
|
|
94
|
+
*/
|
|
95
|
+
declare function copySourceToTarget(sourcePath: string, targetPath: string, options: CopyOptions): Promise<CopyResult>;
|
|
96
|
+
/**
|
|
97
|
+
* 写入文件内容
|
|
98
|
+
* @param filePath 文件路径
|
|
99
|
+
* @param content 文件内容
|
|
100
|
+
* @throws 当写入过程中出现错误时抛出异常
|
|
101
|
+
*/
|
|
102
|
+
declare function writeFileContent(filePath: string, content: string): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* 同步读取文件内容
|
|
105
|
+
* @param filePath 文件路径
|
|
106
|
+
* @returns 文件内容字符串
|
|
107
|
+
* @throws 当读取过程中出现错误时抛出异常
|
|
108
|
+
*/
|
|
109
|
+
declare function readFileSync(filePath: string): string;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 数字补零格式化
|
|
113
|
+
*
|
|
114
|
+
* @param num 要格式化的数字
|
|
115
|
+
* @param length 目标长度
|
|
116
|
+
* @returns 补零后的字符串
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* padNumber(5, 2) // '05'
|
|
121
|
+
* padNumber(12, 3) // '012'
|
|
122
|
+
* padNumber(123, 2) // '123'
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function padNumber(num: number, length?: number): string;
|
|
126
|
+
/**
|
|
127
|
+
* 生成随机哈希字符串
|
|
128
|
+
*
|
|
129
|
+
* @param length 哈希长度,范围 1-64
|
|
130
|
+
* @returns 随机哈希字符串
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* generateRandomHash(8) // 'a1b2c3d4'
|
|
135
|
+
* generateRandomHash(16) // 'a1b2c3d4e5f6g7h8'
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
declare function generateRandomHash(length?: number): string;
|
|
139
|
+
/**
|
|
140
|
+
* 日期格式化选项
|
|
141
|
+
*/
|
|
142
|
+
interface DateFormatOptions {
|
|
143
|
+
/** 四位年份 */
|
|
144
|
+
YYYY: string;
|
|
145
|
+
/** 两位年份 */
|
|
146
|
+
YY: string;
|
|
147
|
+
/** 两位月份 */
|
|
148
|
+
MM: string;
|
|
149
|
+
/** 两位日期 */
|
|
150
|
+
DD: string;
|
|
151
|
+
/** 两位小时(24小时制) */
|
|
152
|
+
HH: string;
|
|
153
|
+
/** 两位分钟 */
|
|
154
|
+
mm: string;
|
|
155
|
+
/** 两位秒数 */
|
|
156
|
+
ss: string;
|
|
157
|
+
/** 三位毫秒 */
|
|
158
|
+
SSS: string;
|
|
159
|
+
/** 时间戳(毫秒) */
|
|
160
|
+
timestamp: string;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 获取日期格式化参数
|
|
164
|
+
*
|
|
165
|
+
* @param date 日期对象
|
|
166
|
+
* @returns 日期格式化参数对象
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const params = getDateFormatParams(new Date())
|
|
171
|
+
* // { YYYY: '2026', MM: '02', DD: '03', HH: '15', mm: '30', ss: '00', ... }
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
declare function getDateFormatParams(date?: Date): DateFormatOptions;
|
|
175
|
+
/**
|
|
176
|
+
* 格式化日期
|
|
177
|
+
*
|
|
178
|
+
* @param date 日期对象
|
|
179
|
+
* @param format 格式模板
|
|
180
|
+
* @returns 格式化后的日期字符串
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* formatDate(new Date(), '{YYYY}-{MM}-{DD}') // '2026-02-03'
|
|
185
|
+
* formatDate(new Date(), '{YYYY}{MM}{DD}{HH}{mm}{ss}') // '20260203153000'
|
|
186
|
+
* formatDate(new Date(), '{YYYY}.{MM}.{DD}') // '2026.02.03'
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
declare function formatDate(date: Date, format: string): string;
|
|
190
|
+
/**
|
|
191
|
+
* 解析模板字符串,替换占位符
|
|
192
|
+
*
|
|
193
|
+
* @param template 模板字符串
|
|
194
|
+
* @param values 占位符值映射
|
|
195
|
+
* @returns 替换后的字符串
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* parseTemplate('{name}-{version}', { name: 'app', version: '1.0.0' })
|
|
200
|
+
* // 'app-1.0.0'
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
declare function parseTemplate(template: string, values: Record<string, string>): string;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 深度合并对象
|
|
207
|
+
*
|
|
208
|
+
* @description 将多个源对象深度合并到一个新对象中。
|
|
209
|
+
* - undefined 值会被跳过,不会覆盖已有值
|
|
210
|
+
* - 嵌套对象会递归合并
|
|
211
|
+
* - 数组会直接覆盖,不会合并
|
|
212
|
+
* - null 值会覆盖已有值
|
|
213
|
+
*
|
|
214
|
+
* @param sources 源对象列表
|
|
215
|
+
* @returns 合并后的对象
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* // 基本合并
|
|
220
|
+
* deepMerge({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }
|
|
221
|
+
*
|
|
222
|
+
* // undefined 不覆盖
|
|
223
|
+
* deepMerge({ a: 1 }, { a: undefined }) // { a: 1 }
|
|
224
|
+
*
|
|
225
|
+
* // 嵌套对象合并
|
|
226
|
+
* deepMerge({ a: { b: 1 } }, { a: { c: 2 } }) // { a: { b: 1, c: 2 } }
|
|
227
|
+
*
|
|
228
|
+
* // 数组覆盖
|
|
229
|
+
* deepMerge({ a: [1, 2] }, { a: [3, 4] }) // { a: [3, 4] }
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
declare function deepMerge<T extends Record<string, any>>(...sources: Partial<T>[]): T;
|
|
233
|
+
|
|
234
|
+
export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, shouldUpdateFile, writeFileContent };
|
|
235
|
+
export type { DateFormatOptions };
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
export { V as Validator } from '../shared/vite-plugin.CiHfwMiN.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 复制操作的选项接口
|
|
5
|
+
*/
|
|
6
|
+
interface CopyOptions {
|
|
7
|
+
/**
|
|
8
|
+
* 是否支持递归复制
|
|
9
|
+
*/
|
|
10
|
+
recursive: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* 是否覆盖同名文件
|
|
13
|
+
*/
|
|
14
|
+
overwrite: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* 是否启用增量复制
|
|
17
|
+
*/
|
|
18
|
+
incremental?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 并行处理的最大文件数
|
|
21
|
+
*/
|
|
22
|
+
parallelLimit?: number;
|
|
23
|
+
/**
|
|
24
|
+
* 是否跳过空目录
|
|
25
|
+
*/
|
|
26
|
+
skipEmptyDirs?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 复制结果接口
|
|
30
|
+
*/
|
|
31
|
+
interface CopyResult {
|
|
32
|
+
/**
|
|
33
|
+
* 复制的文件数量
|
|
34
|
+
*/
|
|
35
|
+
copiedFiles: number;
|
|
36
|
+
/**
|
|
37
|
+
* 跳过的文件数量
|
|
38
|
+
*/
|
|
39
|
+
skippedFiles: number;
|
|
40
|
+
/**
|
|
41
|
+
* 复制的目录数量
|
|
42
|
+
*/
|
|
43
|
+
copiedDirs: number;
|
|
44
|
+
/**
|
|
45
|
+
* 总执行时间(毫秒)
|
|
46
|
+
*/
|
|
47
|
+
executionTime: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 文件/目录条目信息
|
|
52
|
+
*/
|
|
53
|
+
interface FileEntry {
|
|
54
|
+
/** 完整路径 */
|
|
55
|
+
path: string;
|
|
56
|
+
/** 是否为文件 */
|
|
57
|
+
isFile: boolean;
|
|
58
|
+
/** 是否为目录 */
|
|
59
|
+
isDirectory: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 检查源文件是否存在
|
|
63
|
+
* @param sourcePath 源文件路径
|
|
64
|
+
* @throws 当源文件不存在或无法访问时抛出异常
|
|
65
|
+
*/
|
|
66
|
+
declare function checkSourceExists(sourcePath: string): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* 创建目标目录
|
|
69
|
+
* @param targetPath 目标目录路径
|
|
70
|
+
* @throws 当无法创建目标目录时抛出异常
|
|
71
|
+
*/
|
|
72
|
+
declare function ensureTargetDir(targetPath: string): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* 读取目录内容(优化版:一次性获取文件类型信息)
|
|
75
|
+
* @param dirPath 目录路径
|
|
76
|
+
* @param recursive 是否递归读取
|
|
77
|
+
* @returns 文件和目录条目列表
|
|
78
|
+
*/
|
|
79
|
+
declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<FileEntry[]>;
|
|
80
|
+
/**
|
|
81
|
+
* 检查文件是否需要更新
|
|
82
|
+
* @param sourceFile 源文件路径
|
|
83
|
+
* @param targetFile 目标文件路径
|
|
84
|
+
* @returns 是否需要更新
|
|
85
|
+
*/
|
|
86
|
+
declare function shouldUpdateFile(sourceFile: string, targetFile: string): Promise<boolean>;
|
|
87
|
+
/**
|
|
88
|
+
* 执行文件复制操作(优化版:并行IO)
|
|
89
|
+
* @param sourcePath 源文件或目录路径
|
|
90
|
+
* @param targetPath 目标文件或目录路径
|
|
91
|
+
* @param options 复制选项
|
|
92
|
+
* @returns 复制结果
|
|
93
|
+
* @throws 当复制过程中出现错误时抛出异常
|
|
94
|
+
*/
|
|
95
|
+
declare function copySourceToTarget(sourcePath: string, targetPath: string, options: CopyOptions): Promise<CopyResult>;
|
|
96
|
+
/**
|
|
97
|
+
* 写入文件内容
|
|
98
|
+
* @param filePath 文件路径
|
|
99
|
+
* @param content 文件内容
|
|
100
|
+
* @throws 当写入过程中出现错误时抛出异常
|
|
101
|
+
*/
|
|
102
|
+
declare function writeFileContent(filePath: string, content: string): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* 同步读取文件内容
|
|
105
|
+
* @param filePath 文件路径
|
|
106
|
+
* @returns 文件内容字符串
|
|
107
|
+
* @throws 当读取过程中出现错误时抛出异常
|
|
108
|
+
*/
|
|
109
|
+
declare function readFileSync(filePath: string): string;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 数字补零格式化
|
|
113
|
+
*
|
|
114
|
+
* @param num 要格式化的数字
|
|
115
|
+
* @param length 目标长度
|
|
116
|
+
* @returns 补零后的字符串
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* padNumber(5, 2) // '05'
|
|
121
|
+
* padNumber(12, 3) // '012'
|
|
122
|
+
* padNumber(123, 2) // '123'
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function padNumber(num: number, length?: number): string;
|
|
126
|
+
/**
|
|
127
|
+
* 生成随机哈希字符串
|
|
128
|
+
*
|
|
129
|
+
* @param length 哈希长度,范围 1-64
|
|
130
|
+
* @returns 随机哈希字符串
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* generateRandomHash(8) // 'a1b2c3d4'
|
|
135
|
+
* generateRandomHash(16) // 'a1b2c3d4e5f6g7h8'
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
declare function generateRandomHash(length?: number): string;
|
|
139
|
+
/**
|
|
140
|
+
* 日期格式化选项
|
|
141
|
+
*/
|
|
142
|
+
interface DateFormatOptions {
|
|
143
|
+
/** 四位年份 */
|
|
144
|
+
YYYY: string;
|
|
145
|
+
/** 两位年份 */
|
|
146
|
+
YY: string;
|
|
147
|
+
/** 两位月份 */
|
|
148
|
+
MM: string;
|
|
149
|
+
/** 两位日期 */
|
|
150
|
+
DD: string;
|
|
151
|
+
/** 两位小时(24小时制) */
|
|
152
|
+
HH: string;
|
|
153
|
+
/** 两位分钟 */
|
|
154
|
+
mm: string;
|
|
155
|
+
/** 两位秒数 */
|
|
156
|
+
ss: string;
|
|
157
|
+
/** 三位毫秒 */
|
|
158
|
+
SSS: string;
|
|
159
|
+
/** 时间戳(毫秒) */
|
|
160
|
+
timestamp: string;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 获取日期格式化参数
|
|
164
|
+
*
|
|
165
|
+
* @param date 日期对象
|
|
166
|
+
* @returns 日期格式化参数对象
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const params = getDateFormatParams(new Date())
|
|
171
|
+
* // { YYYY: '2026', MM: '02', DD: '03', HH: '15', mm: '30', ss: '00', ... }
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
declare function getDateFormatParams(date?: Date): DateFormatOptions;
|
|
175
|
+
/**
|
|
176
|
+
* 格式化日期
|
|
177
|
+
*
|
|
178
|
+
* @param date 日期对象
|
|
179
|
+
* @param format 格式模板
|
|
180
|
+
* @returns 格式化后的日期字符串
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* formatDate(new Date(), '{YYYY}-{MM}-{DD}') // '2026-02-03'
|
|
185
|
+
* formatDate(new Date(), '{YYYY}{MM}{DD}{HH}{mm}{ss}') // '20260203153000'
|
|
186
|
+
* formatDate(new Date(), '{YYYY}.{MM}.{DD}') // '2026.02.03'
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
declare function formatDate(date: Date, format: string): string;
|
|
190
|
+
/**
|
|
191
|
+
* 解析模板字符串,替换占位符
|
|
192
|
+
*
|
|
193
|
+
* @param template 模板字符串
|
|
194
|
+
* @param values 占位符值映射
|
|
195
|
+
* @returns 替换后的字符串
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* parseTemplate('{name}-{version}', { name: 'app', version: '1.0.0' })
|
|
200
|
+
* // 'app-1.0.0'
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
declare function parseTemplate(template: string, values: Record<string, string>): string;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 深度合并对象
|
|
207
|
+
*
|
|
208
|
+
* @description 将多个源对象深度合并到一个新对象中。
|
|
209
|
+
* - undefined 值会被跳过,不会覆盖已有值
|
|
210
|
+
* - 嵌套对象会递归合并
|
|
211
|
+
* - 数组会直接覆盖,不会合并
|
|
212
|
+
* - null 值会覆盖已有值
|
|
213
|
+
*
|
|
214
|
+
* @param sources 源对象列表
|
|
215
|
+
* @returns 合并后的对象
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* // 基本合并
|
|
220
|
+
* deepMerge({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }
|
|
221
|
+
*
|
|
222
|
+
* // undefined 不覆盖
|
|
223
|
+
* deepMerge({ a: 1 }, { a: undefined }) // { a: 1 }
|
|
224
|
+
*
|
|
225
|
+
* // 嵌套对象合并
|
|
226
|
+
* deepMerge({ a: { b: 1 } }, { a: { c: 2 } }) // { a: { b: 1, c: 2 } }
|
|
227
|
+
*
|
|
228
|
+
* // 数组覆盖
|
|
229
|
+
* deepMerge({ a: [1, 2] }, { a: [3, 4] }) // { a: [3, 4] }
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
declare function deepMerge<T extends Record<string, any>>(...sources: Partial<T>[]): T;
|
|
233
|
+
|
|
234
|
+
export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, shouldUpdateFile, writeFileContent };
|
|
235
|
+
export type { DateFormatOptions };
|