@meng-xi/vite-plugin 0.0.4 → 0.0.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.
Files changed (46) hide show
  1. package/README-en.md +249 -70
  2. package/README.md +343 -143
  3. package/dist/common/index.cjs +1 -1
  4. package/dist/common/index.d.cts +84 -1
  5. package/dist/common/index.d.mts +84 -1
  6. package/dist/common/index.d.ts +84 -1
  7. package/dist/common/index.mjs +1 -1
  8. package/dist/factory/index.cjs +1 -1
  9. package/dist/factory/index.d.cts +71 -6
  10. package/dist/factory/index.d.mts +71 -6
  11. package/dist/factory/index.d.ts +71 -6
  12. package/dist/factory/index.mjs +1 -1
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.d.cts +4 -5
  15. package/dist/index.d.mts +4 -5
  16. package/dist/index.d.ts +4 -5
  17. package/dist/index.mjs +1 -1
  18. package/dist/logger/index.cjs +1 -1
  19. package/dist/logger/index.d.cts +1 -1
  20. package/dist/logger/index.d.mts +1 -1
  21. package/dist/logger/index.d.ts +1 -1
  22. package/dist/logger/index.mjs +1 -1
  23. package/dist/plugins/index.cjs +1 -1
  24. package/dist/plugins/index.d.cts +213 -8
  25. package/dist/plugins/index.d.mts +213 -8
  26. package/dist/plugins/index.d.ts +213 -8
  27. package/dist/plugins/index.mjs +1 -1
  28. package/dist/shared/vite-plugin.B5wW4CiL.mjs +36 -0
  29. package/dist/shared/vite-plugin.Ba9646wL.cjs +1 -0
  30. package/dist/shared/vite-plugin.C3ejdBNf.mjs +1 -0
  31. package/dist/shared/{vite-plugin.B3PARlU9.d.cts → vite-plugin.CLr0ttuO.d.cts} +16 -0
  32. package/dist/shared/{vite-plugin.B3PARlU9.d.mts → vite-plugin.CLr0ttuO.d.mts} +16 -0
  33. package/dist/shared/{vite-plugin.B3PARlU9.d.ts → vite-plugin.CLr0ttuO.d.ts} +16 -0
  34. package/dist/shared/vite-plugin.CXlzkIgT.cjs +36 -0
  35. package/dist/shared/vite-plugin.CawoITTT.cjs +1 -0
  36. package/dist/shared/vite-plugin.DSb6XzBn.mjs +1 -0
  37. package/package.json +72 -72
  38. package/dist/shared/vite-plugin.C7isVPKg.mjs +0 -1
  39. package/dist/shared/vite-plugin.D6NYITpX.cjs +0 -1
  40. package/dist/shared/vite-plugin.D8HTI0Ni.cjs +0 -2
  41. package/dist/shared/vite-plugin.Dd2ogbSe.mjs +0 -2
  42. package/dist/shared/vite-plugin.DqWt65U-.cjs +0 -1
  43. package/dist/shared/vite-plugin.HZb-1B5l.mjs +0 -1
  44. package/dist/shared/vite-plugin.UkE7CdSe.d.cts +0 -43
  45. package/dist/shared/vite-plugin.UkE7CdSe.d.mts +0 -43
  46. package/dist/shared/vite-plugin.UkE7CdSe.d.ts +0 -43
package/README.md CHANGED
@@ -1,143 +1,343 @@
1
- **中文** | [English](./README-en.md)
2
-
3
- <div align="center">
4
- <a href="https://github.com/MengXi-Studio/vite-plugin">
5
- <img alt="梦曦工作室 Logo" width="215" src="https://github.com/MengXi-Studio/vite-plugin/blob/master/packages/docs/src/public/logo.svg">
6
- </a>
7
- <br>
8
- <h1>@meng-xi/vite-plugin</h1>
9
-
10
- [![license](https://img.shields.io/github/license/MengXi-Studio/vite-plugin.svg)](LICENSE) [![npm](https://img.shields.io/npm/v/@meng-xi/vite-plugin?color=blue)](https://www.npmjs.com/package/@meng-xi/vite-plugin)
11
- ![npm](https://img.shields.io/npm/dt/@meng-xi/vite-plugin?color=green)
12
-
13
- </div>
14
-
15
- ## 简介
16
-
17
- `@meng-xi/vite-plugin` 是一个为 Vite 提供实用插件的工具包,也是一个**完整的插件开发框架**。该框架提供了常用功能的核心工具方法供扩展支持其他拓展工作开展快速开发。
18
-
19
- ## 特性
20
-
21
- - **增强 Vite 构建流程**:提供实用插件集合,扩展 Vite 功能,简化构建过程中的常见任务,提高开发效率
22
- - **插件开发框架**:导出核心组件如 BasePlugin、Logger、Validator,允许开发者基于相同基础设施构建自定义插件
23
- - **高度可配置**:所有功能支持详细配置选项,可根据项目需求自定义行为,满足多样化场景
24
- - **单例日志系统**:统一的日志管理器,支持插件级别的日志控制,便于调试和问题排查
25
- - **类型安全验证**:强类型配置验证器,确保插件配置正确性,提供完整的 TypeScript 类型定义
26
- - **插件工厂模式**:支持选项标准化器,轻松处理异构输入,简化插件开发工作流
27
- - **无缝集成**:与 Vite 构建流程无缝集成,无需复杂配置即可快速启用
28
- - **优化开发体验**:简化常见构建任务,减少手动操作,让开发者专注于核心业务逻辑
29
-
30
- ## 文档
31
-
32
- 开始阅读[文档地址](https://mengxi-studio.github.io/vite-plugin/)。
33
-
34
- ## 安装
35
-
36
- 使用包管理器安装 `@meng-xi/vite-plugin`:
37
-
38
- ```bash
39
- # 使用 npm
40
- npm install @meng-xi/vite-plugin --save-dev
41
-
42
- # 使用 yarn
43
- yarn add @meng-xi/vite-plugin --save-dev
44
-
45
- # 使用 pnpm
46
- pnpm add @meng-xi/vite-plugin --save-dev
47
- ```
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
-
108
- ## 更新日志
109
-
110
- [CHANGELOG](https://github.com/MengXi-Studio/vite-plugin/releases)
111
-
112
- ## 如何贡献
113
-
114
- 欢迎为 `@meng-xi/vite-plugin` 贡献代码。以下是贡献代码的步骤:
115
-
116
- 1. Fork 项目:在 GitHub 上 Fork 此项目。
117
- 2. 克隆代码:将 Fork 后的项目克隆到您的本地机器。
118
-
119
- ```bash
120
- git clone https://github.com/your-username/vite-plugin.git
121
- cd vite-plugin
122
- ```
123
-
124
- 3. 创建新分支:基于 `master` 分支创建一个新的功能分支。
125
-
126
- ```bash
127
- git checkout -b feature/your-feature
128
- ```
129
-
130
- 4. 提交变更:确保您的代码通过了测试,并使用清晰的提交消息提交您的变更。
131
-
132
- ```bash
133
- git add .
134
- git commit -m "feat: add your feature description"
135
- ```
136
-
137
- 5. Push 变更:将您的本地分支推送到 GitHub。
138
-
139
- ```bash
140
- git push origin feature/your-feature
141
- ```
142
-
143
- 6. 创建 PR:在 GitHub 上创建一个 Pull Request,并等待审核。
1
+ **中文** | [English](./README-en.md)
2
+
3
+ <div align="center">
4
+ <a href="https://github.com/MengXi-Studio/vite-plugin">
5
+ <img alt="梦曦工作室 Logo" width="215" src="https://github.com/MengXi-Studio/vite-plugin/blob/master/packages/docs/src/public/logo.png">
6
+ </a>
7
+ <br>
8
+ <h1>@meng-xi/vite-plugin</h1>
9
+ <p>一个为 Vite 提供实用插件的工具包,同时也是一个完整的插件开发框架</p>
10
+
11
+ [![license](https://img.shields.io/github/license/MengXi-Studio/vite-plugin.svg)](LICENSE) [![npm](https://img.shields.io/npm/v/@meng-xi/vite-plugin?color=blue)](https://www.npmjs.com/package/@meng-xi/vite-plugin)
12
+ ![npm](https://img.shields.io/npm/dt/@meng-xi/vite-plugin?color=green)
13
+
14
+ </div>
15
+
16
+ ## 特性
17
+
18
+ - **开箱即用** - 提供文件复制、路由生成、版本管理、图标注入等实用插件
19
+ - **插件开发框架** - 导出 BasePlugin、Logger、Validator 等核心组件,快速构建自定义插件
20
+ - **完整生命周期** - 支持初始化、配置解析、销毁等生命周期管理,自动组合钩子逻辑
21
+ - **类型安全** - 完整的 TypeScript 类型定义,配置验证器确保参数正确性
22
+ - **灵活配置** - 所有插件支持详细配置,满足多样化场景需求
23
+ - **安全执行** - 内置错误处理策略(throw / log / ignore),统一异常管理
24
+
25
+ ## 文档
26
+
27
+ 查看完整文档:[https://mengxi-studio.github.io/vite-plugin/](https://mengxi-studio.github.io/vite-plugin/)
28
+
29
+ ## 安装
30
+
31
+ ```bash
32
+ # npm
33
+ npm install @meng-xi/vite-plugin -D
34
+
35
+ # yarn
36
+ yarn add @meng-xi/vite-plugin -D
37
+
38
+ # pnpm
39
+ pnpm add @meng-xi/vite-plugin -D
40
+ ```
41
+
42
+ ## 快速开始
43
+
44
+ ### 使用内置插件
45
+
46
+ ```typescript
47
+ import { defineConfig } from 'vite'
48
+ import { copyFile, generateRouter, generateVersion, injectIco } from '@meng-xi/vite-plugin'
49
+
50
+ export default defineConfig({
51
+ plugins: [
52
+ // 复制文件
53
+ copyFile({
54
+ sourceDir: 'src/assets',
55
+ targetDir: 'dist/assets'
56
+ }),
57
+
58
+ // 生成路由配置(uni-app)
59
+ generateRouter({
60
+ pagesJsonPath: 'src/pages.json',
61
+ outputPath: 'src/router.config.ts'
62
+ }),
63
+
64
+ // 生成版本号
65
+ generateVersion({
66
+ format: 'datetime',
67
+ outputType: 'both'
68
+ }),
69
+
70
+ // 注入网站图标
71
+ injectIco({
72
+ base: '/assets'
73
+ })
74
+ ]
75
+ })
76
+ ```
77
+
78
+ ### 访问插件实例
79
+
80
+ 所有内置插件返回的对象包含 `pluginInstance` 属性,可访问插件内部状态:
81
+
82
+ ```typescript
83
+ import type { PluginWithInstance } from '@meng-xi/vite-plugin/factory'
84
+ import type { GenerateRouterOptions } from '@meng-xi/vite-plugin'
85
+
86
+ const routerPlugin = generateRouter({ watch: true }) as PluginWithInstance<GenerateRouterOptions>
87
+
88
+ // 通过 pluginInstance 访问插件内部
89
+ console.log(routerPlugin.pluginInstance?.options)
90
+ ```
91
+
92
+ ### 开发自定义插件
93
+
94
+ ```typescript
95
+ import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin'
96
+ import type { BasePluginOptions, PluginWithInstance } from '@meng-xi/vite-plugin/factory'
97
+ import type { Plugin } from 'vite'
98
+
99
+ interface MyPluginOptions extends BasePluginOptions {
100
+ path: string
101
+ }
102
+
103
+ class MyPlugin extends BasePlugin<MyPluginOptions> {
104
+ protected getDefaultOptions() {
105
+ return { path: './default' }
106
+ }
107
+
108
+ protected validateOptions(): void {
109
+ this.validator.field('path').required().string().validate()
110
+ }
111
+
112
+ protected getPluginName(): string {
113
+ return 'my-plugin'
114
+ }
115
+
116
+ protected addPluginHooks(plugin: Plugin): void {
117
+ plugin.buildStart = () => {
118
+ this.logger.info(`Plugin started with path: ${this.options.path}`)
119
+ }
120
+ }
121
+
122
+ protected destroy(): void {
123
+ super.destroy()
124
+ // 自定义清理逻辑,如关闭连接、停止监听等
125
+ }
126
+ }
127
+
128
+ export const myPlugin = createPluginFactory(MyPlugin)
129
+ ```
130
+
131
+ ## 插件开发框架
132
+
133
+ ### BasePlugin 核心概念
134
+
135
+ `BasePlugin` 是所有插件的基类,提供了完整的生命周期管理和开发规范:
136
+
137
+ #### 生命周期
138
+
139
+ | 阶段 | 方法 | 说明 |
140
+ | -------- | ------------------ | -------------------------------------- |
141
+ | 初始化 | `constructor` | 合并配置、初始化日志和验证器 |
142
+ | 配置解析 | `onConfigResolved` | Vite 配置解析完成时调用 |
143
+ | 钩子注册 | `addPluginHooks` | 注册 Vite 插件钩子 |
144
+ | 销毁 | `destroy` | `closeBundle` 时自动调用,用于清理资源 |
145
+
146
+ #### 钩子自动组合
147
+
148
+ `toPlugin()` 方法会自动组合以下钩子:
149
+
150
+ - **configResolved** - 先执行基类的 `onConfigResolved`,再执行子类注册的钩子
151
+ - **closeBundle** - 先执行子类注册的钩子,再执行基类的 `destroy`
152
+
153
+ > 子类无需手动注册 `closeBundle` 钩子来清理资源,只需重写 `destroy()` 方法即可。
154
+
155
+ #### 必须实现的方法
156
+
157
+ | 方法 | 说明 |
158
+ | ------------------------ | ------------------ |
159
+ | `getPluginName()` | 返回插件名称 |
160
+ | `addPluginHooks(plugin)` | 添加 Vite 插件钩子 |
161
+
162
+ #### 可选重写的方法
163
+
164
+ | 方法 | 默认行为 | 说明 |
165
+ | -------------------------- | ----------- | ---------------------------------- |
166
+ | `getDefaultOptions()` | 返回 `{}` | 提供插件默认配置 |
167
+ | `validateOptions()` | 无验证 | 验证配置参数 |
168
+ | `getEnforce()` | `undefined` | 插件执行时机(`'pre'` / `'post'`) |
169
+ | `onConfigResolved(config)` | 存储配置 | 配置解析完成回调 |
170
+ | `destroy()` | 注销日志 | 插件销毁时的清理逻辑 |
171
+
172
+ #### 内置属性
173
+
174
+ | 属性 | 类型 | 说明 |
175
+ | ------------ | ------------------------ | ----------------- |
176
+ | `options` | `Required<T>` | 合并后的完整配置 |
177
+ | `logger` | `PluginLogger` | 插件日志记录器 |
178
+ | `validator` | `Validator<T>` | 配置验证器 |
179
+ | `viteConfig` | `ResolvedConfig \| null` | Vite 解析后的配置 |
180
+
181
+ #### 错误处理策略
182
+
183
+ 通过 `errorStrategy` 配置项控制错误行为:
184
+
185
+ - `'throw'`(默认)- 记录错误并抛出异常,中断构建
186
+ - `'log'` - 记录错误但不抛出,继续执行
187
+ - `'ignore'` - 记录错误但不抛出,继续执行
188
+
189
+ 使用 `safeExecute` / `safeExecuteSync` 包裹可能出错的操作:
190
+
191
+ ```typescript
192
+ const result = await this.safeExecute(async () => {
193
+ return await someAsyncOperation()
194
+ }, '执行异步操作')
195
+ ```
196
+
197
+ ### createPluginFactory
198
+
199
+ 创建插件工厂函数,支持选项标准化:
200
+
201
+ ```typescript
202
+ // 基本使用
203
+ const myPlugin = createPluginFactory(MyPlugin)
204
+
205
+ // 带标准化器(支持字符串简写配置)
206
+ const myPlugin = createPluginFactory(MyPlugin, opt => (typeof opt === 'string' ? { path: opt } : opt))
207
+
208
+ // 使用时支持简写
209
+ myPlugin('./custom-path')
210
+ ```
211
+
212
+ ### Logger
213
+
214
+ 全局单例日志管理器,为每个插件提供独立的日志控制:
215
+
216
+ ```typescript
217
+ import { Logger } from '@meng-xi/vite-plugin/logger'
218
+
219
+ // 创建日志记录器(通常由 BasePlugin 自动调用)
220
+ Logger.create({ name: 'my-plugin', enabled: true })
221
+
222
+ // 注销插件日志配置(插件销毁时自动调用)
223
+ Logger.unregister('my-plugin')
224
+
225
+ // 销毁单例(测试场景使用)
226
+ Logger.destroy()
227
+ ```
228
+
229
+ 日志输出格式:
230
+
231
+ ```
232
+ ℹ️ [@meng-xi/vite-plugin:my-plugin] Info message
233
+ ✅ [@meng-xi/vite-plugin:my-plugin] Success message
234
+ ⚠️ [@meng-xi/vite-plugin:my-plugin] Warning message
235
+ ❌ [@meng-xi/vite-plugin:my-plugin] Error message
236
+ ```
237
+
238
+ ## 内置插件
239
+
240
+ ### copyFile
241
+
242
+ 在 Vite 构建完成后复制文件或目录到指定位置。
243
+
244
+ | 选项 | 类型 | 默认值 | 描述 |
245
+ | ----------- | ------- | ------ | -------------------- |
246
+ | sourceDir | string | - | 源目录路径(必填) |
247
+ | targetDir | string | - | 目标目录路径(必填) |
248
+ | overwrite | boolean | true | 是否覆盖现有文件 |
249
+ | recursive | boolean | true | 是否递归复制子目录 |
250
+ | incremental | boolean | true | 是否启用增量复制 |
251
+
252
+ ### generateRouter
253
+
254
+ 根据 uni-app 项目的 `pages.json` 自动生成路由配置文件。
255
+
256
+ | 选项 | 类型 | 默认值 | 描述 |
257
+ | -------------------- | ------------------------------------------------- | ---------------------- | ----------------------------- |
258
+ | pagesJsonPath | string | 'src/pages.json' | pages.json 文件路径 |
259
+ | outputPath | string | 'src/router.config.ts' | 输出文件路径 |
260
+ | outputFormat | 'ts' \| 'js' | 'ts' | 输出文件格式 |
261
+ | nameStrategy | 'path' \| 'camelCase' \| 'pascalCase' \| 'custom' | 'camelCase' | 路由名称策略 |
262
+ | customNameGenerator | (path: string) => string | - | 自定义路由名称生成函数 |
263
+ | includeSubPackages | boolean | true | 是否包含子包路由 |
264
+ | watch | boolean | true | 是否监听变化自动重新生成 |
265
+ | metaMapping | Record\<string, string\> | - | 页面 style 字段到 meta 的映射 |
266
+ | exportTypes | boolean | true | 是否导出类型定义 |
267
+ | preserveRouteChanges | boolean | true | 是否保留用户对 routes 的修改 |
268
+
269
+ ### generateVersion
270
+
271
+ 在 Vite 构建过程中自动生成版本号。
272
+
273
+ | 选项 | 类型 | 默认值 | 描述 |
274
+ | ------------ | --------------------------------------------------------------------- | ----------------- | ------------------------ |
275
+ | format | 'timestamp' \| 'date' \| 'datetime' \| 'semver' \| 'hash' \| 'custom' | 'timestamp' | 版本号格式 |
276
+ | customFormat | string | - | 自定义格式模板 |
277
+ | semverBase | string | '1.0.0' | 语义化版本基础值 |
278
+ | outputType | 'file' \| 'define' \| 'both' | 'file' | 输出类型 |
279
+ | outputFile | string | 'version.json' | 输出文件路径 |
280
+ | defineName | string | '**APP_VERSION**' | 注入的全局变量名 |
281
+ | hashLength | number | 8 | 哈希长度(1-32) |
282
+ | prefix | string | - | 版本号前缀 |
283
+ | suffix | string | - | 版本号后缀 |
284
+ | extra | Record\<string, unknown\> | - | 附加信息(仅 JSON 文件) |
285
+
286
+ ### injectIco
287
+
288
+ 在 Vite 构建过程中将网站图标链接注入到 HTML 文件的 head 中。
289
+
290
+ | 选项 | 类型 | 默认值 | 描述 |
291
+ | ----------- | ------ | ------ | --------------------------- |
292
+ | base | string | '/' | 图标文件的基础路径 |
293
+ | url | string | - | 图标的完整 URL |
294
+ | link | string | - | 自定义完整的 link 标签 HTML |
295
+ | icons | Icon[] | - | 自定义图标数组 |
296
+ | copyOptions | object | - | 图标文件复制配置 |
297
+
298
+ `Icon` 接口定义:
299
+
300
+ | 属性 | 类型 | 必填 | 描述 |
301
+ | ----- | ------ | ---- | -------------- |
302
+ | rel | string | 是 | 图标关系类型 |
303
+ | href | string | 是 | 图标 URL |
304
+ | sizes | string | 否 | 图标尺寸 |
305
+ | type | string | 否 | 图标 MIME 类型 |
306
+
307
+ ## 子路径导出
308
+
309
+ 支持按需导入模块,减少打包体积:
310
+
311
+ ```typescript
312
+ // 完整导入
313
+ import { copyFile, BasePlugin, Logger } from '@meng-xi/vite-plugin'
314
+
315
+ // 按模块导入
316
+ import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin/factory'
317
+ import { Logger } from '@meng-xi/vite-plugin/logger'
318
+ import { copyFile, generateRouter } from '@meng-xi/vite-plugin/plugins'
319
+ import { Validator, readFileContent, writeFileContent } from '@meng-xi/vite-plugin/common'
320
+
321
+ // 类型导入(从子路径按需导入类型定义)
322
+ import type { PluginWithInstance, PluginFactory, BasePluginOptions } from '@meng-xi/vite-plugin/factory'
323
+ import type { GenerateVersionOptions, InjectIcoOptions, Icon } from '@meng-xi/vite-plugin/plugins'
324
+ import type { DateFormatOptions } from '@meng-xi/vite-plugin/common'
325
+ ```
326
+
327
+ ## 更新日志
328
+
329
+ 查看 [GitHub Releases](https://github.com/MengXi-Studio/vite-plugin/releases)
330
+
331
+ ## 贡献指南
332
+
333
+ 欢迎贡献代码!请按以下步骤操作:
334
+
335
+ 1. Fork 本项目
336
+ 2. 创建功能分支:`git checkout -b feature/your-feature`
337
+ 3. 提交变更:`git commit -m "feat: your feature description"`
338
+ 4. 推送分支:`git push origin feature/your-feature`
339
+ 5. 创建 Pull Request
340
+
341
+ ## License
342
+
343
+ [MIT](LICENSE)
@@ -1 +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;
1
+ "use strict";const format=require("../shared/vite-plugin.Ba9646wL.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.fileExists=format.fileExists,exports.formatDate=format.formatDate,exports.generateRandomHash=format.generateRandomHash,exports.getDateFormatParams=format.getDateFormatParams,exports.padNumber=format.padNumber,exports.parseTemplate=format.parseTemplate,exports.readDirRecursive=format.readDirRecursive,exports.readFileContent=format.readFileContent,exports.readFileSync=format.readFileSync,exports.runWithConcurrency=format.runWithConcurrency,exports.shouldUpdateFile=format.shouldUpdateFile,exports.stripJsonComments=format.stripJsonComments,exports.toCamelCase=format.toCamelCase,exports.toPascalCase=format.toPascalCase,exports.writeFileContent=format.writeFileContent,exports.Validator=validation.Validator,exports.deepMerge=validation.deepMerge;
@@ -84,6 +84,38 @@ declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<
84
84
  * @returns 是否需要更新
85
85
  */
86
86
  declare function shouldUpdateFile(sourceFile: string, targetFile: string): Promise<boolean>;
87
+ /**
88
+ * 检查文件是否存在
89
+ * @param filePath 文件路径
90
+ * @returns 是否存在
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * if (await fileExists('/path/to/file')) {
95
+ * console.log('文件存在')
96
+ * }
97
+ * ```
98
+ */
99
+ declare function fileExists(filePath: string): Promise<boolean>;
100
+ /**
101
+ * 带并发限制的批量执行
102
+ *
103
+ * @param items 待处理项
104
+ * @param handler 处理函数
105
+ * @param concurrency 并发数
106
+ * @returns 处理结果数组,顺序与输入项对应
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const urls = ['url1', 'url2', 'url3', 'url4', 'url5']
111
+ * const results = await runWithConcurrency(
112
+ * urls,
113
+ * async (url) => fetch(url),
114
+ * 3 // 最多同时处理3个请求
115
+ * )
116
+ * ```
117
+ */
118
+ declare function runWithConcurrency<T, R>(items: T[], handler: (item: T) => Promise<R>, concurrency: number): Promise<R[]>;
87
119
  /**
88
120
  * 执行文件复制操作(优化版:并行IO)
89
121
  * @param sourcePath 源文件或目录路径
@@ -100,11 +132,19 @@ declare function copySourceToTarget(sourcePath: string, targetPath: string, opti
100
132
  * @throws 当写入过程中出现错误时抛出异常
101
133
  */
102
134
  declare function writeFileContent(filePath: string, content: string): Promise<void>;
135
+ /**
136
+ * 读取文件内容
137
+ * @param filePath 文件路径
138
+ * @returns 文件内容字符串
139
+ * @throws 当读取过程中出现错误时抛出异常
140
+ */
141
+ declare function readFileContent(filePath: string): Promise<string>;
103
142
  /**
104
143
  * 同步读取文件内容
105
144
  * @param filePath 文件路径
106
145
  * @returns 文件内容字符串
107
146
  * @throws 当读取过程中出现错误时抛出异常
147
+ * @deprecated 请使用异步版本 readFileContent
108
148
  */
109
149
  declare function readFileSync(filePath: string): string;
110
150
 
@@ -201,6 +241,49 @@ declare function formatDate(date: Date, format: string): string;
201
241
  * ```
202
242
  */
203
243
  declare function parseTemplate(template: string, values: Record<string, string>): string;
244
+ /**
245
+ * 将字符串转换为驼峰命名(camelCase)
246
+ *
247
+ * @param str 输入字符串
248
+ * @param separators 分隔符正则,默认为斜杠和横线
249
+ * @returns 驼峰命名字符串
250
+ *
251
+ * @example
252
+ * ```typescript
253
+ * toCamelCase('pages/user/profile') // 'pagesUserProfile'
254
+ * toCamelCase('user-profile-page') // 'userProfilePage'
255
+ * toCamelCase('/pages/index') // 'pagesIndex'
256
+ * ```
257
+ */
258
+ declare function toCamelCase(str: string, separators?: RegExp): string;
259
+ /**
260
+ * 将字符串转换为帕斯卡命名(PascalCase)
261
+ *
262
+ * @param str 输入字符串
263
+ * @param separators 分隔符正则,默认为斜杠和横线
264
+ * @returns 帕斯卡命名字符串
265
+ *
266
+ * @example
267
+ * ```typescript
268
+ * toPascalCase('pages/user/profile') // 'PagesUserProfile'
269
+ * toPascalCase('user-profile-page') // 'UserProfilePage'
270
+ * toPascalCase('/pages/index') // 'PagesIndex'
271
+ * ```
272
+ */
273
+ declare function toPascalCase(str: string, separators?: RegExp): string;
274
+ /**
275
+ * 移除 JSON 字符串中的注释
276
+ *
277
+ * @param jsonString 包含注释的 JSON 字符串
278
+ * @returns 移除注释后的 JSON 字符串
279
+ *
280
+ * @example
281
+ * ```typescript
282
+ * stripJsonComments('{\n // comment\n "name": "test"\n}')
283
+ * // '{\n "name": "test"\n}'
284
+ * ```
285
+ */
286
+ declare function stripJsonComments(jsonString: string): string;
204
287
 
205
288
  /**
206
289
  * 深度合并对象
@@ -231,5 +314,5 @@ declare function parseTemplate(template: string, values: Record<string, string>)
231
314
  */
232
315
  declare function deepMerge<T extends Record<string, any>>(...sources: Partial<T>[]): T;
233
316
 
234
- export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, shouldUpdateFile, writeFileContent };
317
+ export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, fileExists, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, shouldUpdateFile, stripJsonComments, toCamelCase, toPascalCase, writeFileContent };
235
318
  export type { DateFormatOptions };