@meng-xi/vite-plugin 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README-en.md CHANGED
@@ -2,60 +2,70 @@
2
2
 
3
3
  <div align="center">
4
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">
5
+ <img alt="MengXi Studio Logo" width="215" src="https://github.com/MengXi-Studio/vite-plugin/blob/master/packages/docs/src/public/logo.svg">
6
6
  </a>
7
7
  <br>
8
8
  <h1>@meng-xi/vite-plugin</h1>
9
+ <p>A toolkit providing practical plugins for Vite, also a complete plugin development framework</p>
9
10
 
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)
11
12
  ![npm](https://img.shields.io/npm/dt/@meng-xi/vite-plugin?color=green)
12
13
 
13
14
  </div>
14
15
 
15
- > - This is a toolkit that provides practical plugins for Vite, and also serves as a complete **Vite Plugin Development Framework**.
16
- > - Extends Vite build process functionality, providing automated processing solutions for common build tasks.
17
- > - All plugins support detailed configuration options, allowing customization based on project needs to meet different usage scenarios.
18
- > - Plugins provide error handling mechanisms to ensure build processes can catch errors, improving build reliability.
19
- > - Export core components like BasePlugin, Logger, Validator, allowing developers to build custom plugins based on the same infrastructure.
16
+ ## Features
20
17
 
21
- ---
18
+ - **Ready to Use** - Provides practical plugins for file copying, router generation, version management, icon injection
19
+ - **Plugin Development Framework** - Exports core components like BasePlugin, Logger, Validator for building custom plugins
20
+ - **Type Safe** - Complete TypeScript type definitions with configuration validators ensuring parameter correctness
21
+ - **Flexible Configuration** - All plugins support detailed configuration to meet diverse scenario requirements
22
22
 
23
- Start reading the [documentation](https://mengxi-studio.github.io/vite-plugin/).
23
+ ## Documentation
24
24
 
25
- ## Quick Start
26
-
27
- ### Installation
25
+ View full documentation: [https://mengxi-studio.github.io/vite-plugin/](https://mengxi-studio.github.io/vite-plugin/)
28
26
 
29
- Install `@meng-xi/vite-plugin` using a package manager:
27
+ ## Installation
30
28
 
31
29
  ```bash
32
- # Using npm
33
- npm install @meng-xi/vite-plugin --save-dev
30
+ # npm
31
+ npm install @meng-xi/vite-plugin -D
34
32
 
35
- # Using yarn
36
- yarn add @meng-xi/vite-plugin --save-dev
33
+ # yarn
34
+ yarn add @meng-xi/vite-plugin -D
37
35
 
38
- # Using pnpm
39
- pnpm add @meng-xi/vite-plugin --save-dev
36
+ # pnpm
37
+ pnpm add @meng-xi/vite-plugin -D
40
38
  ```
41
39
 
42
- ### Basic Usage
40
+ ## Quick Start
43
41
 
44
- #### Using Built-in Plugins
42
+ ### Using Built-in Plugins
45
43
 
46
44
  ```typescript
47
45
  import { defineConfig } from 'vite'
48
- import { copyFile, injectIco } from '@meng-xi/vite-plugin'
46
+ import { copyFile, generateRouter, generateVersion, injectIco } from '@meng-xi/vite-plugin'
49
47
 
50
48
  export default defineConfig({
51
49
  plugins: [
52
- // Copy file plugin
50
+ // Copy files
53
51
  copyFile({
54
52
  sourceDir: 'src/assets',
55
53
  targetDir: 'dist/assets'
56
54
  }),
57
55
 
58
- // Inject icon plugin
56
+ // Generate router config (uni-app)
57
+ generateRouter({
58
+ pagesJsonPath: 'src/pages.json',
59
+ outputPath: 'src/router.config.ts'
60
+ }),
61
+
62
+ // Generate version
63
+ generateVersion({
64
+ format: 'datetime',
65
+ outputType: 'both'
66
+ }),
67
+
68
+ // Inject website icon
59
69
  injectIco({
60
70
  base: '/assets'
61
71
  })
@@ -63,10 +73,10 @@ export default defineConfig({
63
73
  })
64
74
  ```
65
75
 
66
- #### Developing Custom Plugins
76
+ ### Developing Custom Plugins
67
77
 
68
78
  ```typescript
69
- import { BasePlugin, createPluginFactory, Validator } from '@meng-xi/vite-plugin'
79
+ import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin'
70
80
  import type { Plugin } from 'vite'
71
81
 
72
82
  interface MyPluginOptions {
@@ -78,9 +88,7 @@ interface MyPluginOptions {
78
88
 
79
89
  class MyPlugin extends BasePlugin<MyPluginOptions> {
80
90
  protected getDefaultOptions() {
81
- return {
82
- path: './default'
83
- }
91
+ return { path: './default' }
84
92
  }
85
93
 
86
94
  protected validateOptions(): void {
@@ -101,64 +109,74 @@ class MyPlugin extends BasePlugin<MyPluginOptions> {
101
109
  export const myPlugin = createPluginFactory(MyPlugin)
102
110
  ```
103
111
 
104
- ## Plugin Details
112
+ ## Built-in Plugins
105
113
 
106
- ### copyFile Plugin
114
+ ### copyFile
107
115
 
108
- Used to copy files or directories to specified locations after Vite build is completed.
116
+ Copy files or directories to specified locations after Vite build is completed.
109
117
 
110
- **Configuration Options**:
118
+ | Option | Type | Default | Description |
119
+ | ----------- | ------- | ------- | ------------------------------------------ |
120
+ | sourceDir | string | - | Source directory path (required) |
121
+ | targetDir | string | - | Target directory path (required) |
122
+ | overwrite | boolean | true | Whether to overwrite existing files |
123
+ | recursive | boolean | true | Whether to recursively copy subdirectories |
124
+ | incremental | boolean | true | Whether to enable incremental copying |
111
125
 
112
- - `sourceDir`: Source directory path (required)
113
- - `targetDir`: Target directory path (required)
114
- - `overwrite`: Whether to overwrite existing files, default is `true`
115
- - `recursive`: Whether to recursively copy subdirectories, default is `true`
116
- - `verbose`: Whether to output detailed logs, default is `true`
117
- - `enabled`: Whether to enable the plugin, default is `true`
126
+ ### generateRouter
118
127
 
119
- ### injectIco Plugin
128
+ Automatically generate router configuration files based on uni-app project's `pages.json`.
120
129
 
121
- Used to inject website icon links into the head of HTML files during the Vite build process.
130
+ | Option | Type | Default | Description |
131
+ | -------------------- | ------------ | ---------------------- | ------------------------------------------------ |
132
+ | pagesJsonPath | string | 'src/pages.json' | Path to pages.json file |
133
+ | outputPath | string | 'src/router.config.ts' | Output file path |
134
+ | outputFormat | 'ts' \| 'js' | 'ts' | Output file format |
135
+ | nameStrategy | string | 'camelCase' | Route name strategy |
136
+ | includeSubPackages | boolean | true | Whether to include sub-package routes |
137
+ | watch | boolean | true | Whether to watch changes and auto-regenerate |
138
+ | metaMapping | object | - | Mapping from page style fields to meta |
139
+ | preserveRouteChanges | boolean | true | Whether to preserve user modifications to routes |
122
140
 
123
- **Configuration Options**:
141
+ ### generateVersion
124
142
 
125
- - `base`: Base path for icon files
126
- - `url`: Complete URL for the icon
127
- - `link`: Custom complete link tag HTML
128
- - `icons`: Custom icon array
129
- - `verbose`: Whether to output detailed logs, default is `true`
130
- - `enabled`: Whether to enable the plugin, default is `true`
131
- - `copyOptions`: Icon file copying configuration
143
+ Automatically generate version numbers during the Vite build process.
132
144
 
133
- ## Contribution
145
+ | Option | Type | Default | Description |
146
+ | ---------- | ------ | --------------------- | ------------------------------ |
147
+ | format | string | 'timestamp' | Version format |
148
+ | outputType | string | 'file' | Output type |
149
+ | outputFile | string | 'version.json' | Output file path |
150
+ | defineName | string | '\_\_APP_VERSION\_\_' | Global variable name to inject |
151
+ | prefix | string | - | Version number prefix |
152
+ | suffix | string | - | Version number suffix |
134
153
 
135
- Welcome to contribute to `@meng-xi/vite-plugin`. Here are the steps to contribute code:
154
+ ### injectIco
136
155
 
137
- 1. Fork the project: Fork this project on GitHub.
138
- 2. Clone the code: Clone the forked project to your local machine.
156
+ Inject website icon links into the head of HTML files during the Vite build process.
139
157
 
140
- ```bash
141
- git clone https://github.com/your-username/vite-plugin.git
142
- cd vite-plugin
143
- ```
158
+ | Option | Type | Default | Description |
159
+ | ----------- | ------ | ------- | ------------------------------- |
160
+ | base | string | - | Base path for icon files |
161
+ | url | string | - | Complete URL for the icon |
162
+ | link | string | - | Custom complete link tag HTML |
163
+ | icons | array | - | Custom icon array |
164
+ | copyOptions | object | - | Icon file copying configuration |
144
165
 
145
- 3. Create a new branch: Create a new feature branch based on the `master` branch.
166
+ ## Changelog
146
167
 
147
- ```bash
148
- git checkout -b feature/your-feature
149
- ```
168
+ See [GitHub Releases](https://github.com/MengXi-Studio/vite-plugin/releases)
150
169
 
151
- 4. Commit changes: Ensure your code passes tests and commit your changes with clear commit messages.
170
+ ## Contributing
152
171
 
153
- ```bash
154
- git add .
155
- git commit -m "feat: add your feature description"
156
- ```
172
+ Contributions are welcome! Please follow these steps:
157
173
 
158
- 5. Push changes: Push your local branch to GitHub.
174
+ 1. Fork the repository
175
+ 2. Create a feature branch: `git checkout -b feature/your-feature`
176
+ 3. Commit changes: `git commit -m "feat: your feature description"`
177
+ 4. Push to branch: `git push origin feature/your-feature`
178
+ 5. Create a Pull Request
159
179
 
160
- ```bash
161
- git push origin feature/your-feature
162
- ```
180
+ ## License
163
181
 
164
- 6. Create a PR: Create a Pull Request on GitHub and wait for review.
182
+ [MIT](LICENSE)
package/README.md CHANGED
@@ -6,60 +6,66 @@
6
6
  </a>
7
7
  <br>
8
8
  <h1>@meng-xi/vite-plugin</h1>
9
+ <p>一个为 Vite 提供实用插件的工具包,同时也是一个完整的插件开发框架</p>
9
10
 
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)
11
12
  ![npm](https://img.shields.io/npm/dt/@meng-xi/vite-plugin?color=green)
12
13
 
13
14
  </div>
14
15
 
15
- ## 简介
16
-
17
- `@meng-xi/vite-plugin` 是一个为 Vite 提供实用插件的工具包,也是一个**完整的插件开发框架**。该框架提供了常用功能的核心工具方法供扩展支持其他拓展工作开展快速开发。
18
-
19
16
  ## 特性
20
17
 
21
- - **增强 Vite 构建流程**:提供实用插件集合,扩展 Vite 功能,简化构建过程中的常见任务,提高开发效率
22
- - **插件开发框架**:导出核心组件如 BasePlugin、Logger、Validator,允许开发者基于相同基础设施构建自定义插件
23
- - **高度可配置**:所有功能支持详细配置选项,可根据项目需求自定义行为,满足多样化场景
24
- - **单例日志系统**:统一的日志管理器,支持插件级别的日志控制,便于调试和问题排查
25
- - **类型安全验证**:强类型配置验证器,确保插件配置正确性,提供完整的 TypeScript 类型定义
26
- - **插件工厂模式**:支持选项标准化器,轻松处理异构输入,简化插件开发工作流
27
- - **无缝集成**:与 Vite 构建流程无缝集成,无需复杂配置即可快速启用
28
- - **优化开发体验**:简化常见构建任务,减少手动操作,让开发者专注于核心业务逻辑
18
+ - **开箱即用** - 提供文件复制、路由生成、版本管理、图标注入等实用插件
19
+ - **插件开发框架** - 导出 BasePlugin、Logger、Validator 等核心组件,快速构建自定义插件
20
+ - **类型安全** - 完整的 TypeScript 类型定义,配置验证器确保参数正确性
21
+ - **灵活配置** - 所有插件支持详细配置,满足多样化场景需求
29
22
 
30
23
  ## 文档
31
24
 
32
- 开始阅读[文档地址](https://mengxi-studio.github.io/vite-plugin/)
25
+ 查看完整文档:[https://mengxi-studio.github.io/vite-plugin/](https://mengxi-studio.github.io/vite-plugin/)
33
26
 
34
27
  ## 安装
35
28
 
36
- 使用包管理器安装 `@meng-xi/vite-plugin`:
37
-
38
29
  ```bash
39
- # 使用 npm
40
- npm install @meng-xi/vite-plugin --save-dev
30
+ # npm
31
+ npm install @meng-xi/vite-plugin -D
41
32
 
42
- # 使用 yarn
43
- yarn add @meng-xi/vite-plugin --save-dev
33
+ # yarn
34
+ yarn add @meng-xi/vite-plugin -D
44
35
 
45
- # 使用 pnpm
46
- pnpm add @meng-xi/vite-plugin --save-dev
36
+ # pnpm
37
+ pnpm add @meng-xi/vite-plugin -D
47
38
  ```
48
39
 
49
- ## 基本使用
40
+ ## 快速开始
50
41
 
51
42
  ### 使用内置插件
52
43
 
53
44
  ```typescript
54
45
  import { defineConfig } from 'vite'
55
- import { copyFile, injectIco } from '@meng-xi/vite-plugin'
46
+ import { copyFile, generateRouter, generateVersion, injectIco } from '@meng-xi/vite-plugin'
56
47
 
57
48
  export default defineConfig({
58
49
  plugins: [
50
+ // 复制文件
59
51
  copyFile({
60
52
  sourceDir: 'src/assets',
61
53
  targetDir: 'dist/assets'
62
54
  }),
55
+
56
+ // 生成路由配置(uni-app)
57
+ generateRouter({
58
+ pagesJsonPath: 'src/pages.json',
59
+ outputPath: 'src/router.config.ts'
60
+ }),
61
+
62
+ // 生成版本号
63
+ generateVersion({
64
+ format: 'datetime',
65
+ outputType: 'both'
66
+ }),
67
+
68
+ // 注入网站图标
63
69
  injectIco({
64
70
  base: '/assets'
65
71
  })
@@ -70,7 +76,7 @@ export default defineConfig({
70
76
  ### 开发自定义插件
71
77
 
72
78
  ```typescript
73
- import { BasePlugin, createPluginFactory, Validator } from '@meng-xi/vite-plugin'
79
+ import { BasePlugin, createPluginFactory } from '@meng-xi/vite-plugin'
74
80
  import type { Plugin } from 'vite'
75
81
 
76
82
  interface MyPluginOptions {
@@ -82,9 +88,7 @@ interface MyPluginOptions {
82
88
 
83
89
  class MyPlugin extends BasePlugin<MyPluginOptions> {
84
90
  protected getDefaultOptions() {
85
- return {
86
- path: './default'
87
- }
91
+ return { path: './default' }
88
92
  }
89
93
 
90
94
  protected validateOptions(): void {
@@ -105,39 +109,74 @@ class MyPlugin extends BasePlugin<MyPluginOptions> {
105
109
  export const myPlugin = createPluginFactory(MyPlugin)
106
110
  ```
107
111
 
108
- ## 更新日志
112
+ ## 内置插件
109
113
 
110
- [CHANGELOG](https://github.com/MengXi-Studio/vite-plugin/releases)
114
+ ### copyFile
111
115
 
112
- ## 如何贡献
116
+ Vite 构建完成后复制文件或目录到指定位置。
113
117
 
114
- 欢迎为 `@meng-xi/vite-plugin` 贡献代码。以下是贡献代码的步骤:
118
+ | 选项 | 类型 | 默认值 | 描述 |
119
+ | ----------- | ------- | ------ | -------------------- |
120
+ | sourceDir | string | - | 源目录路径(必填) |
121
+ | targetDir | string | - | 目标目录路径(必填) |
122
+ | overwrite | boolean | true | 是否覆盖现有文件 |
123
+ | recursive | boolean | true | 是否递归复制子目录 |
124
+ | incremental | boolean | true | 是否启用增量复制 |
115
125
 
116
- 1. Fork 项目:在 GitHub 上 Fork 此项目。
117
- 2. 克隆代码:将 Fork 后的项目克隆到您的本地机器。
126
+ ### generateRouter
118
127
 
119
- ```bash
120
- git clone https://github.com/your-username/vite-plugin.git
121
- cd vite-plugin
122
- ```
128
+ 根据 uni-app 项目的 `pages.json` 自动生成路由配置文件。
123
129
 
124
- 3. 创建新分支:基于 `master` 分支创建一个新的功能分支。
130
+ | 选项 | 类型 | 默认值 | 描述 |
131
+ | -------------------- | ------------ | ---------------------- | ----------------------------- |
132
+ | pagesJsonPath | string | 'src/pages.json' | pages.json 文件路径 |
133
+ | outputPath | string | 'src/router.config.ts' | 输出文件路径 |
134
+ | outputFormat | 'ts' \| 'js' | 'ts' | 输出文件格式 |
135
+ | nameStrategy | string | 'camelCase' | 路由名称策略 |
136
+ | includeSubPackages | boolean | true | 是否包含子包路由 |
137
+ | watch | boolean | true | 是否监听变化自动重新生成 |
138
+ | metaMapping | object | - | 页面 style 字段到 meta 的映射 |
139
+ | preserveRouteChanges | boolean | true | 是否保留用户对 routes 的修改 |
125
140
 
126
- ```bash
127
- git checkout -b feature/your-feature
128
- ```
141
+ ### generateVersion
129
142
 
130
- 4. 提交变更:确保您的代码通过了测试,并使用清晰的提交消息提交您的变更。
143
+ Vite 构建过程中自动生成版本号。
131
144
 
132
- ```bash
133
- git add .
134
- git commit -m "feat: add your feature description"
135
- ```
145
+ | 选项 | 类型 | 默认值 | 描述 |
146
+ | ---------- | ------ | --------------------- | ---------------- |
147
+ | format | string | 'timestamp' | 版本格式 |
148
+ | outputType | string | 'file' | 输出类型 |
149
+ | outputFile | string | 'version.json' | 输出文件路径 |
150
+ | defineName | string | '\_\_APP_VERSION\_\_' | 注入的全局变量名 |
151
+ | prefix | string | - | 版本号前缀 |
152
+ | suffix | string | - | 版本号后缀 |
136
153
 
137
- 5. Push 变更:将您的本地分支推送到 GitHub。
154
+ ### injectIco
138
155
 
139
- ```bash
140
- git push origin feature/your-feature
141
- ```
156
+ 在 Vite 构建过程中将网站图标链接注入到 HTML 文件的 head 中。
157
+
158
+ | 选项 | 类型 | 默认值 | 描述 |
159
+ | ----------- | ------ | ------ | --------------------------- |
160
+ | base | string | - | 图标文件的基础路径 |
161
+ | url | string | - | 图标的完整 URL |
162
+ | link | string | - | 自定义完整的 link 标签 HTML |
163
+ | icons | array | - | 自定义图标数组 |
164
+ | copyOptions | object | - | 图标文件复制配置 |
165
+
166
+ ## 更新日志
167
+
168
+ 查看 [GitHub Releases](https://github.com/MengXi-Studio/vite-plugin/releases)
169
+
170
+ ## 贡献指南
171
+
172
+ 欢迎贡献代码!请按以下步骤操作:
173
+
174
+ 1. Fork 本项目
175
+ 2. 创建功能分支:`git checkout -b feature/your-feature`
176
+ 3. 提交变更:`git commit -m "feat: your feature description"`
177
+ 4. 推送分支:`git push origin feature/your-feature`
178
+ 5. 创建 Pull Request
179
+
180
+ ## License
142
181
 
143
- 6. 创建 PR:在 GitHub 上创建一个 Pull Request,并等待审核。
182
+ [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.BZsetDCm.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.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 源文件或目录路径
@@ -201,6 +233,49 @@ declare function formatDate(date: Date, format: string): string;
201
233
  * ```
202
234
  */
203
235
  declare function parseTemplate(template: string, values: Record<string, string>): string;
236
+ /**
237
+ * 将字符串转换为驼峰命名(camelCase)
238
+ *
239
+ * @param str 输入字符串
240
+ * @param separators 分隔符正则,默认为斜杠和横线
241
+ * @returns 驼峰命名字符串
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * toCamelCase('pages/user/profile') // 'pagesUserProfile'
246
+ * toCamelCase('user-profile-page') // 'userProfilePage'
247
+ * toCamelCase('/pages/index') // 'pagesIndex'
248
+ * ```
249
+ */
250
+ declare function toCamelCase(str: string, separators?: RegExp): string;
251
+ /**
252
+ * 将字符串转换为帕斯卡命名(PascalCase)
253
+ *
254
+ * @param str 输入字符串
255
+ * @param separators 分隔符正则,默认为斜杠和横线
256
+ * @returns 帕斯卡命名字符串
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * toPascalCase('pages/user/profile') // 'PagesUserProfile'
261
+ * toPascalCase('user-profile-page') // 'UserProfilePage'
262
+ * toPascalCase('/pages/index') // 'PagesIndex'
263
+ * ```
264
+ */
265
+ declare function toPascalCase(str: string, separators?: RegExp): string;
266
+ /**
267
+ * 移除 JSON 字符串中的注释
268
+ *
269
+ * @param jsonString 包含注释的 JSON 字符串
270
+ * @returns 移除注释后的 JSON 字符串
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * stripJsonComments('{\n // comment\n "name": "test"\n}')
275
+ * // '{\n "name": "test"\n}'
276
+ * ```
277
+ */
278
+ declare function stripJsonComments(jsonString: string): string;
204
279
 
205
280
  /**
206
281
  * 深度合并对象
@@ -231,5 +306,5 @@ declare function parseTemplate(template: string, values: Record<string, string>)
231
306
  */
232
307
  declare function deepMerge<T extends Record<string, any>>(...sources: Partial<T>[]): T;
233
308
 
234
- export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, shouldUpdateFile, writeFileContent };
309
+ export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, fileExists, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, runWithConcurrency, shouldUpdateFile, stripJsonComments, toCamelCase, toPascalCase, writeFileContent };
235
310
  export type { DateFormatOptions };
@@ -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 源文件或目录路径
@@ -201,6 +233,49 @@ declare function formatDate(date: Date, format: string): string;
201
233
  * ```
202
234
  */
203
235
  declare function parseTemplate(template: string, values: Record<string, string>): string;
236
+ /**
237
+ * 将字符串转换为驼峰命名(camelCase)
238
+ *
239
+ * @param str 输入字符串
240
+ * @param separators 分隔符正则,默认为斜杠和横线
241
+ * @returns 驼峰命名字符串
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * toCamelCase('pages/user/profile') // 'pagesUserProfile'
246
+ * toCamelCase('user-profile-page') // 'userProfilePage'
247
+ * toCamelCase('/pages/index') // 'pagesIndex'
248
+ * ```
249
+ */
250
+ declare function toCamelCase(str: string, separators?: RegExp): string;
251
+ /**
252
+ * 将字符串转换为帕斯卡命名(PascalCase)
253
+ *
254
+ * @param str 输入字符串
255
+ * @param separators 分隔符正则,默认为斜杠和横线
256
+ * @returns 帕斯卡命名字符串
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * toPascalCase('pages/user/profile') // 'PagesUserProfile'
261
+ * toPascalCase('user-profile-page') // 'UserProfilePage'
262
+ * toPascalCase('/pages/index') // 'PagesIndex'
263
+ * ```
264
+ */
265
+ declare function toPascalCase(str: string, separators?: RegExp): string;
266
+ /**
267
+ * 移除 JSON 字符串中的注释
268
+ *
269
+ * @param jsonString 包含注释的 JSON 字符串
270
+ * @returns 移除注释后的 JSON 字符串
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * stripJsonComments('{\n // comment\n "name": "test"\n}')
275
+ * // '{\n "name": "test"\n}'
276
+ * ```
277
+ */
278
+ declare function stripJsonComments(jsonString: string): string;
204
279
 
205
280
  /**
206
281
  * 深度合并对象
@@ -231,5 +306,5 @@ declare function parseTemplate(template: string, values: Record<string, string>)
231
306
  */
232
307
  declare function deepMerge<T extends Record<string, any>>(...sources: Partial<T>[]): T;
233
308
 
234
- export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, shouldUpdateFile, writeFileContent };
309
+ export { checkSourceExists, copySourceToTarget, deepMerge, ensureTargetDir, fileExists, formatDate, generateRandomHash, getDateFormatParams, padNumber, parseTemplate, readDirRecursive, readFileSync, runWithConcurrency, shouldUpdateFile, stripJsonComments, toCamelCase, toPascalCase, writeFileContent };
235
310
  export type { DateFormatOptions };