@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
@@ -1,5 +1,7 @@
1
- import { B as BasePluginOptions, P as PluginFactory } from '../shared/vite-plugin.UkE7CdSe.cjs';
1
+ import { BasePluginOptions, PluginFactory } from '../factory/index.cjs';
2
2
  import 'vite';
3
+ import '../shared/vite-plugin.CLr0ttuO.cjs';
4
+ import '../shared/vite-plugin.CiHfwMiN.cjs';
3
5
 
4
6
  /**
5
7
  * 复制文件插件的配置选项接口
@@ -72,6 +74,214 @@ interface CopyFileOptions extends BasePluginOptions {
72
74
  */
73
75
  declare const copyFile: PluginFactory<CopyFileOptions, CopyFileOptions>;
74
76
 
77
+ /**
78
+ * 路由元信息
79
+ */
80
+ interface RouteMeta {
81
+ /** 页面标题 */
82
+ title?: string;
83
+ /** 是否为TabBar页面 */
84
+ isTab?: boolean;
85
+ /** 是否需要登录 */
86
+ requireAuth?: boolean;
87
+ /** 自定义扩展字段 */
88
+ [key: string]: unknown;
89
+ }
90
+ /**
91
+ * 路由配置项
92
+ */
93
+ interface RouteConfig {
94
+ /** 路由路径 */
95
+ path: string;
96
+ /** 路由名称(用于命名路由导航) */
97
+ name?: string;
98
+ /** 路由元信息 */
99
+ meta?: RouteMeta;
100
+ }
101
+ /**
102
+ * uni-app pages.json 中的页面配置项
103
+ */
104
+ interface UniAppPageConfig {
105
+ /** 页面路径 */
106
+ path: string;
107
+ /** 页面样式 */
108
+ style?: {
109
+ /** 导航栏标题 */
110
+ navigationBarTitleText?: string;
111
+ /** 是否需要登录 */
112
+ requireAuth?: boolean;
113
+ /** 其他自定义属性 */
114
+ [key: string]: unknown;
115
+ };
116
+ /** 其他属性 */
117
+ [key: string]: unknown;
118
+ }
119
+ /**
120
+ * uni-app pages.json 中的 tabBar 配置
121
+ */
122
+ interface UniAppTabBarConfig {
123
+ /** tabBar 列表 */
124
+ list?: Array<{
125
+ /** 页面路径 */
126
+ pagePath: string;
127
+ /** 文字 */
128
+ text?: string;
129
+ /** 图标路径 */
130
+ iconPath?: string;
131
+ /** 选中图标路径 */
132
+ selectedIconPath?: string;
133
+ }>;
134
+ /** 其他属性 */
135
+ [key: string]: unknown;
136
+ }
137
+ /**
138
+ * uni-app pages.json 结构
139
+ */
140
+ interface UniAppPagesJson {
141
+ /** 页面列表 */
142
+ pages: UniAppPageConfig[];
143
+ /** 子包 */
144
+ subPackages?: Array<{
145
+ root: string;
146
+ pages: UniAppPageConfig[];
147
+ }>;
148
+ /** tabBar 配置 */
149
+ tabBar?: UniAppTabBarConfig;
150
+ /** 全局样式 */
151
+ globalStyle?: Record<string, unknown>;
152
+ /** 其他属性 */
153
+ [key: string]: unknown;
154
+ }
155
+ /**
156
+ * 输出文件格式类型
157
+ */
158
+ type OutputFormat = 'ts' | 'js';
159
+ /**
160
+ * 路由名称生成策略
161
+ */
162
+ type NameStrategy = 'path' | 'camelCase' | 'pascalCase' | 'custom';
163
+ /**
164
+ * 生成路由配置插件选项
165
+ */
166
+ interface GenerateRouterOptions extends BasePluginOptions {
167
+ /**
168
+ * pages.json 文件路径(相对于项目根目录)
169
+ *
170
+ * @default 'src/pages.json'
171
+ */
172
+ pagesJsonPath?: string;
173
+ /**
174
+ * 输出文件路径(相对于项目根目录)
175
+ *
176
+ * @default 'src/router.config.ts'
177
+ */
178
+ outputPath?: string;
179
+ /**
180
+ * 输出文件格式
181
+ *
182
+ * @default 'ts'
183
+ */
184
+ outputFormat?: OutputFormat;
185
+ /**
186
+ * 路由名称生成策略
187
+ *
188
+ * @default 'camelCase'
189
+ */
190
+ nameStrategy?: NameStrategy;
191
+ /**
192
+ * 自定义路由名称生成函数
193
+ *
194
+ * @param path - 页面路径
195
+ * @returns 路由名称
196
+ */
197
+ customNameGenerator?: (path: string) => string;
198
+ /**
199
+ * 是否包含子包路由
200
+ *
201
+ * @default true
202
+ */
203
+ includeSubPackages?: boolean;
204
+ /**
205
+ * 是否监听 pages.json 变化并自动重新生成
206
+ *
207
+ * @default true
208
+ */
209
+ watch?: boolean;
210
+ /**
211
+ * 额外的元信息字段映射
212
+ *
213
+ * @description 将 pages.json 中 style 的字段映射到 meta 中
214
+ * @example { 'navigationBarTitleText': 'title', 'requireAuth': 'requireAuth' }
215
+ */
216
+ metaMapping?: Record<string, string>;
217
+ /**
218
+ * 是否导出类型定义
219
+ *
220
+ * @default true
221
+ */
222
+ exportTypes?: boolean;
223
+ /**
224
+ * 是否保留用户对 routes 配置的修改
225
+ *
226
+ * @description 开启后,用户在 routes 数组中修改的字段将被保留
227
+ * @default true
228
+ */
229
+ preserveRouteChanges?: boolean;
230
+ }
231
+
232
+ /**
233
+ * 生成路由配置插件
234
+ *
235
+ * @param {GenerateRouterOptions} options - 插件配置选项
236
+ * @returns {Plugin} 一个 Vite 插件实例
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * // 基本使用 - 使用默认配置
241
+ * generateRouter()
242
+ *
243
+ * // 自定义 pages.json 路径
244
+ * generateRouter({
245
+ * pagesJsonPath: 'pages.json'
246
+ * })
247
+ *
248
+ * // 输出 JavaScript 文件
249
+ * generateRouter({
250
+ * outputFormat: 'js',
251
+ * outputPath: 'src/router.config.js'
252
+ * })
253
+ *
254
+ * // 使用帕斯卡命名策略
255
+ * generateRouter({
256
+ * nameStrategy: 'pascalCase'
257
+ * })
258
+ *
259
+ * // 自定义路由名称生成
260
+ * generateRouter({
261
+ * nameStrategy: 'custom',
262
+ * customNameGenerator: (path) => `route_${path.replace(/\//g, '_')}`
263
+ * })
264
+ *
265
+ * // 自定义元信息映射
266
+ * generateRouter({
267
+ * metaMapping: {
268
+ * navigationBarTitleText: 'title',
269
+ * requireAuth: 'requireAuth',
270
+ * customField: 'custom'
271
+ * }
272
+ * })
273
+ * ```
274
+ *
275
+ * @remarks
276
+ * 该插件会读取 uni-app 项目的 pages.json 文件,自动生成路由配置文件:
277
+ * - 支持主包和子包页面
278
+ * - 自动识别 tabBar 页面
279
+ * - 支持多种路由名称生成策略
280
+ * - 支持自定义元信息字段映射
281
+ * - 开发模式下自动监听 pages.json 变化并重新生成
282
+ */
283
+ declare const generateRouter: PluginFactory<GenerateRouterOptions, GenerateRouterOptions>;
284
+
75
285
  /**
76
286
  * 版本号格式类型
77
287
  *
@@ -130,12 +340,6 @@ interface GenerateVersionOptions extends BasePluginOptions {
130
340
  * @default '1.0.0'
131
341
  */
132
342
  semverBase?: string;
133
- /**
134
- * 是否自动递增补丁版本号
135
- *
136
- * @default false
137
- */
138
- autoIncrement?: boolean;
139
343
  /**
140
344
  * 输出类型
141
345
  *
@@ -372,4 +576,5 @@ interface InjectIcoOptions extends BasePluginOptions {
372
576
  */
373
577
  declare const injectIco: PluginFactory<InjectIcoOptions, string | InjectIcoOptions>;
374
578
 
375
- export { copyFile, generateVersion, injectIco };
579
+ export { copyFile, generateRouter, generateVersion, injectIco };
580
+ export type { CopyFileOptions, GenerateRouterOptions, GenerateVersionOptions, Icon, InjectIcoOptions, NameStrategy, OutputFormat, OutputType, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, VersionFormat };
@@ -1,5 +1,7 @@
1
- import { B as BasePluginOptions, P as PluginFactory } from '../shared/vite-plugin.UkE7CdSe.mjs';
1
+ import { BasePluginOptions, PluginFactory } from '../factory/index.mjs';
2
2
  import 'vite';
3
+ import '../shared/vite-plugin.CLr0ttuO.mjs';
4
+ import '../shared/vite-plugin.CiHfwMiN.mjs';
3
5
 
4
6
  /**
5
7
  * 复制文件插件的配置选项接口
@@ -72,6 +74,214 @@ interface CopyFileOptions extends BasePluginOptions {
72
74
  */
73
75
  declare const copyFile: PluginFactory<CopyFileOptions, CopyFileOptions>;
74
76
 
77
+ /**
78
+ * 路由元信息
79
+ */
80
+ interface RouteMeta {
81
+ /** 页面标题 */
82
+ title?: string;
83
+ /** 是否为TabBar页面 */
84
+ isTab?: boolean;
85
+ /** 是否需要登录 */
86
+ requireAuth?: boolean;
87
+ /** 自定义扩展字段 */
88
+ [key: string]: unknown;
89
+ }
90
+ /**
91
+ * 路由配置项
92
+ */
93
+ interface RouteConfig {
94
+ /** 路由路径 */
95
+ path: string;
96
+ /** 路由名称(用于命名路由导航) */
97
+ name?: string;
98
+ /** 路由元信息 */
99
+ meta?: RouteMeta;
100
+ }
101
+ /**
102
+ * uni-app pages.json 中的页面配置项
103
+ */
104
+ interface UniAppPageConfig {
105
+ /** 页面路径 */
106
+ path: string;
107
+ /** 页面样式 */
108
+ style?: {
109
+ /** 导航栏标题 */
110
+ navigationBarTitleText?: string;
111
+ /** 是否需要登录 */
112
+ requireAuth?: boolean;
113
+ /** 其他自定义属性 */
114
+ [key: string]: unknown;
115
+ };
116
+ /** 其他属性 */
117
+ [key: string]: unknown;
118
+ }
119
+ /**
120
+ * uni-app pages.json 中的 tabBar 配置
121
+ */
122
+ interface UniAppTabBarConfig {
123
+ /** tabBar 列表 */
124
+ list?: Array<{
125
+ /** 页面路径 */
126
+ pagePath: string;
127
+ /** 文字 */
128
+ text?: string;
129
+ /** 图标路径 */
130
+ iconPath?: string;
131
+ /** 选中图标路径 */
132
+ selectedIconPath?: string;
133
+ }>;
134
+ /** 其他属性 */
135
+ [key: string]: unknown;
136
+ }
137
+ /**
138
+ * uni-app pages.json 结构
139
+ */
140
+ interface UniAppPagesJson {
141
+ /** 页面列表 */
142
+ pages: UniAppPageConfig[];
143
+ /** 子包 */
144
+ subPackages?: Array<{
145
+ root: string;
146
+ pages: UniAppPageConfig[];
147
+ }>;
148
+ /** tabBar 配置 */
149
+ tabBar?: UniAppTabBarConfig;
150
+ /** 全局样式 */
151
+ globalStyle?: Record<string, unknown>;
152
+ /** 其他属性 */
153
+ [key: string]: unknown;
154
+ }
155
+ /**
156
+ * 输出文件格式类型
157
+ */
158
+ type OutputFormat = 'ts' | 'js';
159
+ /**
160
+ * 路由名称生成策略
161
+ */
162
+ type NameStrategy = 'path' | 'camelCase' | 'pascalCase' | 'custom';
163
+ /**
164
+ * 生成路由配置插件选项
165
+ */
166
+ interface GenerateRouterOptions extends BasePluginOptions {
167
+ /**
168
+ * pages.json 文件路径(相对于项目根目录)
169
+ *
170
+ * @default 'src/pages.json'
171
+ */
172
+ pagesJsonPath?: string;
173
+ /**
174
+ * 输出文件路径(相对于项目根目录)
175
+ *
176
+ * @default 'src/router.config.ts'
177
+ */
178
+ outputPath?: string;
179
+ /**
180
+ * 输出文件格式
181
+ *
182
+ * @default 'ts'
183
+ */
184
+ outputFormat?: OutputFormat;
185
+ /**
186
+ * 路由名称生成策略
187
+ *
188
+ * @default 'camelCase'
189
+ */
190
+ nameStrategy?: NameStrategy;
191
+ /**
192
+ * 自定义路由名称生成函数
193
+ *
194
+ * @param path - 页面路径
195
+ * @returns 路由名称
196
+ */
197
+ customNameGenerator?: (path: string) => string;
198
+ /**
199
+ * 是否包含子包路由
200
+ *
201
+ * @default true
202
+ */
203
+ includeSubPackages?: boolean;
204
+ /**
205
+ * 是否监听 pages.json 变化并自动重新生成
206
+ *
207
+ * @default true
208
+ */
209
+ watch?: boolean;
210
+ /**
211
+ * 额外的元信息字段映射
212
+ *
213
+ * @description 将 pages.json 中 style 的字段映射到 meta 中
214
+ * @example { 'navigationBarTitleText': 'title', 'requireAuth': 'requireAuth' }
215
+ */
216
+ metaMapping?: Record<string, string>;
217
+ /**
218
+ * 是否导出类型定义
219
+ *
220
+ * @default true
221
+ */
222
+ exportTypes?: boolean;
223
+ /**
224
+ * 是否保留用户对 routes 配置的修改
225
+ *
226
+ * @description 开启后,用户在 routes 数组中修改的字段将被保留
227
+ * @default true
228
+ */
229
+ preserveRouteChanges?: boolean;
230
+ }
231
+
232
+ /**
233
+ * 生成路由配置插件
234
+ *
235
+ * @param {GenerateRouterOptions} options - 插件配置选项
236
+ * @returns {Plugin} 一个 Vite 插件实例
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * // 基本使用 - 使用默认配置
241
+ * generateRouter()
242
+ *
243
+ * // 自定义 pages.json 路径
244
+ * generateRouter({
245
+ * pagesJsonPath: 'pages.json'
246
+ * })
247
+ *
248
+ * // 输出 JavaScript 文件
249
+ * generateRouter({
250
+ * outputFormat: 'js',
251
+ * outputPath: 'src/router.config.js'
252
+ * })
253
+ *
254
+ * // 使用帕斯卡命名策略
255
+ * generateRouter({
256
+ * nameStrategy: 'pascalCase'
257
+ * })
258
+ *
259
+ * // 自定义路由名称生成
260
+ * generateRouter({
261
+ * nameStrategy: 'custom',
262
+ * customNameGenerator: (path) => `route_${path.replace(/\//g, '_')}`
263
+ * })
264
+ *
265
+ * // 自定义元信息映射
266
+ * generateRouter({
267
+ * metaMapping: {
268
+ * navigationBarTitleText: 'title',
269
+ * requireAuth: 'requireAuth',
270
+ * customField: 'custom'
271
+ * }
272
+ * })
273
+ * ```
274
+ *
275
+ * @remarks
276
+ * 该插件会读取 uni-app 项目的 pages.json 文件,自动生成路由配置文件:
277
+ * - 支持主包和子包页面
278
+ * - 自动识别 tabBar 页面
279
+ * - 支持多种路由名称生成策略
280
+ * - 支持自定义元信息字段映射
281
+ * - 开发模式下自动监听 pages.json 变化并重新生成
282
+ */
283
+ declare const generateRouter: PluginFactory<GenerateRouterOptions, GenerateRouterOptions>;
284
+
75
285
  /**
76
286
  * 版本号格式类型
77
287
  *
@@ -130,12 +340,6 @@ interface GenerateVersionOptions extends BasePluginOptions {
130
340
  * @default '1.0.0'
131
341
  */
132
342
  semverBase?: string;
133
- /**
134
- * 是否自动递增补丁版本号
135
- *
136
- * @default false
137
- */
138
- autoIncrement?: boolean;
139
343
  /**
140
344
  * 输出类型
141
345
  *
@@ -372,4 +576,5 @@ interface InjectIcoOptions extends BasePluginOptions {
372
576
  */
373
577
  declare const injectIco: PluginFactory<InjectIcoOptions, string | InjectIcoOptions>;
374
578
 
375
- export { copyFile, generateVersion, injectIco };
579
+ export { copyFile, generateRouter, generateVersion, injectIco };
580
+ export type { CopyFileOptions, GenerateRouterOptions, GenerateVersionOptions, Icon, InjectIcoOptions, NameStrategy, OutputFormat, OutputType, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, VersionFormat };