@onoxm/vite-plugin-auto-router 0.2.0 → 0.3.0

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.
@@ -0,0 +1,431 @@
1
+ # @onoxm/vite-plugin-auto-router
2
+
3
+ 一个用于自动生成 React 或 Vue 路由文件的 Vite 插件。
4
+
5
+ [English](./README.md) | 中文
6
+
7
+ ## ✨ 特性
8
+
9
+ - 自动生成路由配置,无需手动维护
10
+ - 支持 React 和 Vue 双框架
11
+ - 约定式路由,按目录结构自动映射
12
+ - 支持动态路由 `[id]` 语法
13
+ - 可配置懒加载和热更新
14
+ - 支持页面级配置文件
15
+ - TypeScript 类型安全
16
+
17
+ ## 🚀 安装
18
+
19
+ ```bash
20
+ npm install -D @onoxm/vite-plugin-auto-router
21
+ ```
22
+
23
+ ## 📖 使用指南
24
+
25
+ ### React 项目
26
+
27
+ #### 安装依赖
28
+
29
+ ```bash
30
+ npm install react-router
31
+ ```
32
+
33
+ #### 配置 Vite
34
+
35
+ ```typescript
36
+ // vite.config.ts
37
+ import { defineConfig } from 'vite'
38
+ import react from '@vitejs/plugin-react'
39
+ import autoRouter from '@onoxm/vite-plugin-auto-router'
40
+
41
+ export default defineConfig({
42
+ plugins: [react(), autoRouter()]
43
+ })
44
+ ```
45
+
46
+ #### 目录结构
47
+
48
+ ```
49
+ src/
50
+ ├── pages/
51
+ │ ├── index.tsx
52
+ │ ├── root.tsx
53
+ │ ├── 404.tsx
54
+ │ └── user/
55
+ │ ├── index.tsx
56
+ │ ├── index.config.ts
57
+ │ ├── [id].tsx
58
+ │ └── [id].config.ts
59
+ ```
60
+
61
+ #### 特殊页面
62
+
63
+ - **`home` 页面**:路径会自动转换为 `/`,作为首页路由
64
+ - **`root` 页面**:作为根路由容器,包裹所有其他路由
65
+ - **`404` 或 `notfound` 页面**:路径会自动转换为 `/*`,作为 404 路由
66
+
67
+ #### 页面配置
68
+
69
+ 继承自 [React Router RouteObject](https://reactrouter.com/start/data/route-object),并进行以下修改:
70
+
71
+ - **移除**: `path`, `Component`, `element`, `children`
72
+ - **新增**: `type?: 'single' | 'wrap'`
73
+
74
+ ##### type: 'single'
75
+
76
+ 当 `type` 配置为 `single` 时,该页面组件会作为独立路由生成:
77
+
78
+ ```typescript
79
+ // src/pages/user/index.config.ts
80
+ import { defineConfig } from '../../router/autoRouter'
81
+
82
+ export default defineConfig({
83
+ type: 'single'
84
+ })
85
+ ```
86
+
87
+ 生成的路由结构:
88
+
89
+ ```typescript
90
+ // src/router/autoRouter.tsx
91
+ import type { RouteObject } from 'react-router'
92
+ import Pages404 from './../pages/404.tsx'
93
+ import Pages from './../pages/index.tsx'
94
+ import PagesRoot from './../pages/root.tsx'
95
+ import PagesUser from './../pages/user/index.tsx'
96
+ import PagesUserId from './../pages/user/[id]/index.tsx'
97
+
98
+ type PageConfig = Partial<
99
+ Omit<RouteObject, 'path' | 'Component' | 'element' | 'children'> & {
100
+ type?: 'single' | 'wrap'
101
+ }
102
+ >
103
+
104
+ export const defineConfig = (config: PageConfig) => config
105
+
106
+ export const routes: RouteObject[] = [
107
+ {
108
+ path: '/',
109
+ element: <PagesRoot />,
110
+ children: [
111
+ {
112
+ path: '/',
113
+ element: <Pages />
114
+ },
115
+ {
116
+ path: '/user',
117
+ children: [
118
+ {
119
+ path: '',
120
+ index: true,
121
+ element: <PagesUser />
122
+ },
123
+ {
124
+ path: ':id',
125
+ children: [
126
+ {
127
+ path: '',
128
+ index: true,
129
+ action: async () => {},
130
+ loader: async ({ params }) => await { params },
131
+ element: <PagesUserId />
132
+ }
133
+ ]
134
+ }
135
+ ]
136
+ }
137
+ ]
138
+ },
139
+ {
140
+ path: '/*',
141
+ element: <Pages404 />
142
+ }
143
+ ]
144
+ ```
145
+
146
+ ##### type: 'wrap'
147
+
148
+ 当 `type` 配置为 `wrap` 时,该页面组件会作为父路由容器包裹其下的子路由:
149
+
150
+ ```typescript
151
+ // src/pages/user/index.config.ts
152
+ import { defineConfig } from '../../router/autoRouter'
153
+
154
+ export default defineConfig({
155
+ type: 'wrap'
156
+ })
157
+ ```
158
+
159
+ 生成的路由结构:
160
+
161
+ ```typescript
162
+ // src/router/autoRouter.tsx
163
+ import type { RouteObject } from 'react-router'
164
+ import Pages404 from './../pages/404.tsx'
165
+ import Pages from './../pages/index.tsx'
166
+ import PagesRoot from './../pages/root.tsx'
167
+ import PagesUser from './../pages/user/index.tsx'
168
+ import PagesUserId from './../pages/user/[id]/index.tsx'
169
+
170
+ type PageConfig = Partial<
171
+ Omit<RouteObject, 'path' | 'Component' | 'element' | 'children'> & {
172
+ type?: 'single' | 'wrap'
173
+ }
174
+ >
175
+
176
+ export const defineConfig = (config: PageConfig) => config
177
+
178
+ export const routes: RouteObject[] = [
179
+ {
180
+ path: '/',
181
+ element: <PagesRoot />,
182
+ children: [
183
+ {
184
+ path: '/',
185
+ element: <Pages />
186
+ },
187
+ {
188
+ path: '/user',
189
+ element: <PagesUser />,
190
+ children: [
191
+ {
192
+ path: ':id',
193
+ children: [
194
+ {
195
+ path: '',
196
+ index: true,
197
+ action: async () => {},
198
+ loader: async ({ params }) => await { params },
199
+ element: <PagesUserId />
200
+ }
201
+ ]
202
+ }
203
+ ]
204
+ }
205
+ ]
206
+ },
207
+ {
208
+ path: '/*',
209
+ element: <Pages404 />
210
+ }
211
+ ]
212
+ ```
213
+
214
+ ### Vue 项目
215
+
216
+ #### 安装依赖
217
+
218
+ ```bash
219
+ npm install vue-router
220
+ ```
221
+
222
+ #### 配置 Vite
223
+
224
+ ```typescript
225
+ // vite.config.ts
226
+ import { defineConfig } from 'vite'
227
+ import vue from '@vitejs/plugin-vue'
228
+ import autoRouter from '@onoxm/vite-plugin-auto-router'
229
+
230
+ export default defineConfig({
231
+ plugins: [
232
+ vue(),
233
+ autoRouter({
234
+ framework: 'vue',
235
+ pagesDir: './src/views'
236
+ })
237
+ ]
238
+ })
239
+ ```
240
+
241
+ #### 目录结构
242
+
243
+ ```
244
+ src/
245
+ ├── views/
246
+ │ ├── 404.vue
247
+ │ ├── home/
248
+ │ │ ├── index.vue
249
+ │ │ └── index.config.ts
250
+ │ └── user/
251
+ │ ├── index.vue
252
+ │ ├── index.config.ts
253
+ │ ├── [id].vue
254
+ │ └── [id].config.ts
255
+ ```
256
+
257
+ #### 特殊页面
258
+
259
+ - **`home` 页面**:路径会自动转换为 `/`,作为首页路由
260
+ - **`root` 页面**:作为根路由容器,包裹所有其他路由
261
+ - **`404` 或 `notfound` 页面**:路径会自动转换为 `/:pathMatch(.*)*`,作为 404 路由
262
+
263
+ #### 页面配置
264
+
265
+ 继承自 [Vue Router RouteRecordRaw](https://router.vuejs.org/api/#routerecordraw),并进行以下修改:
266
+
267
+ - **移除**: `path`, `component`, `children`
268
+ - **新增**: `type?: 'single' | 'wrap'`
269
+
270
+ ##### type: 'single'
271
+
272
+ 当 `type` 配置为 `single` 时,该页面组件会作为独立路由生成:
273
+
274
+ ```typescript
275
+ // src/views/user/index.config.ts
276
+ import { defineConfig } from '../../router/autoRouter'
277
+
278
+ export default defineConfig({
279
+ type: 'single'
280
+ })
281
+ ```
282
+
283
+ 生成的路由结构:
284
+
285
+ ```typescript
286
+ // src/router/autoRouter.ts
287
+ import type { RouteRecordRaw } from 'vue-router'
288
+ import Views404 from './../views/404.vue'
289
+ import ViewsHome from './../views/home/index.vue'
290
+ import ViewsUser from './../views/user/index.vue'
291
+ import ViewsUserId from './../views/user/[id]/index.vue'
292
+
293
+ type PageConfig = Partial<
294
+ Omit<RouteRecordRaw, 'path' | 'component' | 'children'> & {
295
+ type?: 'single' | 'wrap'
296
+ }
297
+ >
298
+
299
+ export const defineConfig = (config: PageConfig) => config
300
+
301
+ export const routes: RouteRecordRaw[] = [
302
+ {
303
+ path: '/',
304
+ children: [
305
+ {
306
+ path: '',
307
+ name: 'home',
308
+ component: ViewsHome
309
+ }
310
+ ]
311
+ },
312
+ {
313
+ path: '/user',
314
+ children: [
315
+ {
316
+ path: '',
317
+ component: ViewsUser
318
+ },
319
+ {
320
+ path: ':id',
321
+ children: [
322
+ {
323
+ path: '',
324
+ component: ViewsUserId
325
+ }
326
+ ]
327
+ }
328
+ ]
329
+ },
330
+ {
331
+ path: '/:pathMatch(.*)*',
332
+ children: [
333
+ {
334
+ path: '',
335
+ component: Views404
336
+ }
337
+ ]
338
+ }
339
+ ]
340
+ ```
341
+
342
+ ##### type: 'wrap'
343
+
344
+ 当 `type` 配置为 `wrap` 时,该页面组件会作为父路由容器包裹其下的子路由:
345
+
346
+ ```typescript
347
+ // src/views/user/index.config.ts
348
+ import { defineConfig } from '../../router/autoRouter'
349
+
350
+ export default defineConfig({
351
+ type: 'wrap'
352
+ })
353
+ ```
354
+
355
+ 生成的路由结构:
356
+
357
+ ```typescript
358
+ // src/router/autoRouter.ts
359
+ import type { RouteRecordRaw } from 'vue-router'
360
+ import ViewsHome from './../views/home/index.vue'
361
+ import ViewsUser from './../views/user/index.vue'
362
+ import ViewsUserId from './../views/user/[id]/index.vue'
363
+
364
+ type PageConfig = Partial<
365
+ Omit<RouteRecordRaw, 'path' | 'component' | 'children'> & {
366
+ type?: 'single' | 'wrap'
367
+ }
368
+ >
369
+
370
+ export const defineConfig = (config: PageConfig) => config
371
+
372
+ export const routes: RouteRecordRaw[] = [
373
+ {
374
+ path: '/',
375
+ children: [
376
+ {
377
+ path: '',
378
+ name: 'home',
379
+ component: ViewsHome
380
+ }
381
+ ]
382
+ },
383
+ {
384
+ path: '/user',
385
+ component: ViewsUser,
386
+ children: [
387
+ {
388
+ path: ':id',
389
+ children: [
390
+ {
391
+ path: '',
392
+ component: ViewsUserId
393
+ }
394
+ ]
395
+ }
396
+ ]
397
+ },
398
+ {
399
+ path: '/:pathMatch(.*)*',
400
+ children: [
401
+ {
402
+ path: '',
403
+ component: Views404
404
+ }
405
+ ]
406
+ }
407
+ ]
408
+ ```
409
+
410
+ ## ⚙️ 配置选项
411
+
412
+ ### 插件配置
413
+
414
+ | 选项 | 类型 | 默认值 | 说明 |
415
+ | ------------ | ------------------ | --------------- | ------------------ |
416
+ | `framework` | `'react' \| 'vue'` | `'react'` | 框架类型 |
417
+ | `pagesDir` | `string` | `'./src/pages'` | 页面目录 |
418
+ | `routesFile` | `string` | `undefined` | 生成的路由文件路径 |
419
+ | `lazy` | `boolean` | `true` | 是否启用懒加载 |
420
+ | `hmr` | `boolean` | `false` | 是否启用热更新 |
421
+
422
+ ### 页面配置
423
+
424
+ | 选项 | 类型 | 默认值 | 说明 |
425
+ | ------ | -------------------- | ---------- | -------------- |
426
+ | `type` | `'single' \| 'wrap'` | `'single'` | 路由类型 |
427
+ | `*` | `any` | `any` | 继承自路由配置 |
428
+
429
+ ## 📄 License
430
+
431
+ MIT
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,a=(a,i,u)=>(u=null!=a?e(r(a)):{},((e,r,a,i)=>{if(r&&"object"==typeof r||"function"==typeof r)for(var u,c=o(r),p=0,l=c.length;p<l;p++)u=c[p],s.call(e,u)||u===a||t(e,u,{get:(e=>r[e]).bind(null,u),enumerable:!(i=n(r,u))||i.enumerable});return e})(!i&&a&&a.__esModule?u:t(u,"default",{value:a,enumerable:!0}),a));let i=require("node:fs");i=a(i);let u=require("node:path");u=a(u);let c=require("fast-glob");function p(e){let t=l(e,0),n=!1;if(t+5<=e.length&&"async"===e.slice(t,t+5).toLowerCase()&&(n=!0,t=l(e,t+5)),t<e.length&&"("===e[t]){const n=h(e,t);if(-1!==n){let t=l(e,n+1);if(t+1<e.length&&"="===e[t]&&">"===e[t+1])return e}}const o=e.indexOf("(");if(-1===o)return e;const r=h(e,o);if(-1===r)return e;return(n?"async ":"")+e.slice(o,r+1)+" => "+e.slice(r+1)}function l(e,t){for(;t<e.length&&/\s/.test(e[t]);)t++;return t}function h(e,t){let n=0,o=!1,r="";for(let s=t;s<e.length;s++){const t=e[s];if('"'!==t&&"'"!==t&&"`"!==t){if(!o)if("("===t)n++;else if(")"===t&&(n--,0===n))return s}else o?t===r&&(o=!1):(o=!0,r=t)}return-1}c=a(c);var f=e=>{try{if(!i.default.existsSync(e))return;i.default.unlinkSync(e)}catch(t){console.error("删除文件失败:",t)}},d=e=>{try{if(!i.default.existsSync(e))return;i.default.rmSync(e,{recursive:!0})}catch(t){console.error("删除目录失败:",t)}},g=(e,t,n)=>{const o={};for(const[r,s]of Object.entries(t))if("function"==typeof s){const t=`${e}-${r}`;o[r]=t,n.set(t,`<start>${p(s.toString())}</end>`)}else o[r]=s;return o},m=e=>e.startsWith("/")?e.slice(1):e.endsWith("/")?e.slice(0,-1):e.startsWith("./")?e.slice(2):e,P=e=>i.default.existsSync(u.default.resolve(e,"tsconfig.json")),R={react:{ts:"src/router/autoRouter.tsx",js:"src/router/autoRouter.jsx"},vue:{ts:"src/router/autoRouter.ts",js:"src/router/autoRouter.js"}},y=(e,t,n)=>{let o=n;return o=o?u.default.resolve(t,o):u.default.resolve(t,R[e][P(t)?"ts":"js"]),o},$=/[/\\]/,j=/[^a-zA-Z0-9]/g,b=/^(\d)/,x=e=>e?e.charAt(0).toUpperCase()+e.slice(1).toLowerCase():"";function C(e){const t=u.default.extname(e),n=u.default.basename(e,t),o=u.default.dirname(e).split($).filter(Boolean);return"index"!==n&&"Index"!==n&&o.push(n),o.map(e=>(e=>e.replace(j,"_").replace(b,"_$1"))(e).split("_").map(x).join("")).join("")||"Component"}var O={"/home":"/","/root":"/"},w=(e,t)=>{const n=e.split("/"),o=n[n.length-1];return t&&o.endsWith(t)?o.slice(0,-t.length):o},M=e=>{const t=O[e];return t||("/notfound"===e.toLowerCase()||"/404"===e?"/*":e)},v=(e,t)=>e.endsWith(".config."+(t?"ts":"js"))?"index"===w(e,".config."+(t?"ts":"js"))?e.replace("index.config."+(t?"ts":"js"),"index."+(t?"ts":"js")):e.slice(0,-10)+"."+(t?"tsx":"jsx"):e.replace("index.config."+(t?"ts":"js"),"index."+(t?"ts":"js")),S=(e,t,n)=>{if(e.endsWith(".config."+(n?"ts":"js"))){const o=w(e,".config."+(n?"ts":"js")),r=(e=>{const t=e.split("/");return t.pop(),t.join("/")})(e).replace(t,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(t,"").replace("/index.config."+(n?"ts":"js"),"")||"/"},T=async(e,t,n,o)=>{const r=[];for(const[s,a]of((e,t,n)=>Object.keys(e).map(e=>{const o=((e,t)=>e.endsWith(t?".tsx":".jsx")?e.slice(0,-4)+".config."+(t?"ts":"js"):e.replace("index."+(t?"ts":"js"),"index.config."+(t?"ts":"js")))(e,n);return[o,t[o]||{}]}))(e,t,o)){const t=v(s,o);if(!e[t])continue;const i=xe(S(s,`/${n}`,o)||"/",o,"react"),u=M(i);r.push({...a,path:u,type:a?.type,isRoot:"/root"===i,element:e[t]})}return r},E=e=>{if(e.index)return e;if("wrap"!==e.type){const{path:t,children:n,...o}=e;if(Object.keys(o).length>0)return{path:t,children:[{path:"",index:!0,...o},...(n||[]).map(E)]}}return e.children?{...e,children:e.children.map(E)}:e},k=e=>(e=>e.map(E))((e=>{const t=new Map,n=[],o=new Map,r=e=>{let t=o.get(e);return void 0===t&&(t="/"===e?[]:e.split("/").filter(Boolean),o.set(e,t)),t},s=e.slice().sort((e,t)=>e.path.length-t.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(t.set(e,s),o.length<=1){n.push(s);continue}const i="/"+o.slice(0,-1).join("/"),u=t.get(i);u?(s.path=o[o.length-1],u.children.push(s)):n.push(s)}return n})(e)),N=e=>{const{isRoot:t,type:n,children:o,...r}=e;return o?.length?{...r,children:o.map(N)}:r},F=e=>{const{children:t}=e;if(!t?.length){const{children:t,...n}=e;return n}const n=t.map(F);if("wrap"===e.type)return{...e,children:n};const{path:o,element:r,type:s,children:a,...i}=e;return r?{path:o,children:[{index:!0,element:r,...i},...n]}:{path:o,...i,children:n}},W=e=>N(F(e)),B=e=>k(e).map(W),L=e=>{if(e.some(e=>e.isRoot))return(e=>{let t,n,o;const r=[];for(const i of e)if(i.isRoot){if(t)throw new Error("There cannot be multiple root routes in a route");t=i}else"/"===i.path?n=i:"/*"===i.path?o=i:r.push(i);if($e(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[n&&{...n,index:!0},...B(r)].filter(e=>Boolean(e)),a=[];return t&&a.push(N({...t,children:s})),o&&a.push(N(o)),a})(e);if($e(e,"path"))throw new Error("There cannot be duplicate paths in a route");return B(e)},z=(e,t)=>({import:`import ${e} from './${t}'`,component:`<start><${e} /></end>`,lazy:`const ${e} = lazy(() => import('${t}'))`,lazyComponent:`<start><Suspense><${e} /></Suspense></end>`});var D="index.tsx",A="index.jsx",I=(e,t,n,o,r,s,a)=>{const i=((e,t)=>e.includes(t?D:A)?e.replace(t?D:A,t?Me:ve):e)(Pe(e,t),a),u=me(de(n,e)),c=he(C(u),s),p=`element(${u})`;o[`/${i}`]=p,r.set(p,{path:u,componentName:c})},_=(e,t,n,o)=>{const r=Pe(e,t);n[`/${r}`]=g(r,fe(e),o)};function K(e,t,n,o,r,s,a,i,u){const p={},l=e.replace(/^\/+/,""),h=c.default.sync(l,{cwd:t,absolute:!0,onlyFiles:!0}).filter(ye);for(const c of h)if("component"===r){if(c.includes(".config."))continue;I(c,n,o,p,s,a,u)}else _(c,n,p,i);return p}var H=async(e,t,n,o,r,s)=>{const a=new Map,i=new Set,u=new Map;we(o,((e,t,n,o)=>{let r=e;for(const[s,a]of t){const e=z(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of n)r=r.replace(s,a);return be(r)})(function(e,t,n,o){const r=n.length>0?`\n${n.join("\n")}\n`:"";return`// Auto-generated by ono-auto-router\n${o?"import type { RouteObject } from 'react-router'\n":""}${t.join("\n")}${o?"\n\ntype PageConfig = Partial<\n Omit<RouteObject, 'path' | 'Component' | 'element' | 'children'> & {\n type?: 'single' | 'wrap'\n }\n>\n":""}${o?"\nexport const defineConfig = (config: PageConfig) => config":""}\n${r}\nexport const routes${o?": RouteObject[]":""} = ${JSON.stringify(e,null,2)}\n`}(L(await T(K("/**/*.{jsx,tsx}",t,n,o,"component",a,i,u,s),K("/**/*.config.{js,ts,jsx,tsx}",t,n,o,"config",a,i,u,s),e,s)),((e,t)=>{if(e)return["import { lazy, Suspense } from 'react'"];const n=[];for(const o of t.values())n.push(z(o.componentName,o.path).import);return n})(r,a),((e,t)=>{if(!e)return[];const n=[];for(const o of t.values())n.push(z(o.componentName,o.path).lazy);return n})(r,a),s),a,u,r))},U=(e,t,n,o)=>{const r=t.split(".")[0],s=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(o),a=n?((e,t)=>`\nconst PATH_REPLACEMENTS${t?": Record<string, string>":""} = {\n '/home': '/',\n '/root': '/'\n}\n\nconst cachedLazyComponents${t?": Record<\n string,\n LazyExoticComponent<ComponentType<unknown>>\n>":""} = {}\n\nconst getConfigFileName = ${t?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${t?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${t?"ts":"js"}'\n }\n return pagePath.replace('index.${t?"ts":"js"}', 'index.config.${t?"ts":"js"}')\n}\n\nconst formatPageModule = (${t?"\n pagesComponent: Record<string, ComponentType<unknown>>,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${t?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${t?"(pathStr: string): string":"(pathStr)"} => {\n if (PATH_REPLACEMENTS[pathStr]) {\n return PATH_REPLACEMENTS[pathStr]\n }\n\n const lowerPath = pathStr.toLowerCase()\n if (lowerPath === '/notfound' || pathStr === '/404') {\n return '/*'\n }\n\n return pathStr\n}\n\nconst getBasename = ${t?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1]\n if (ext && lastPart.endsWith(ext)) {\n return lastPart.slice(0, -ext.length)\n }\n return lastPart\n}\n\nconst getDirname = ${t?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${t?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${t?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${t?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n if (fileName === 'index') {\n return dirPath || '/'\n }\n return dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n return (\n configPath.replace('/${e}', '').replace('/index.config.${t?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${t?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${t?": Record<string, unknown>":""} = {}\n\n for (const [path, module] of Object.entries(modules)) {\n if ('default' in module) {\n result[path] = module.default\n }\n }\n\n return result\n}\n\nconst filterUnComponent = ${t?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${t?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${t?"tsx":"jsx"}')) {\n result[key] = pagesComponent[key]\n }\n }\n\n return result\n}\n\nconst LazyComponent = ({\n Element\n}${t?": {\n Element: LazyExoticComponent<ComponentType<unknown>>\n}":""}) => {\n return (\n <Suspense>\n <Element />\n </Suspense>\n )\n}\n\nconst createBaseRoutes = () => {\n const pagesComponent = filterUnComponent({\n ...import.meta.glob('/${e}/**/*.${t?"tsx":"jsx"}')${t?" as PagesComponentType":""}\n })\n\n const pagesString = getFileDefault({\n ...import.meta.glob('/${e}/**/*.${t?"tsx":"jsx"}', {\n eager: true\n })\n })${t?" as Record<string, ComponentType<unknown>>":""}\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${t?"ts":"js"}', {\n eager: true\n })\n })${t?" as Record<string, PageConfig>":""}\n\n const result${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const [pagePath, page] of formatPageModule(pagesString, pagesModule)) {\n const compPath = getCompPathFromConfig(pagePath)\n\n if (!pagesComponent[compPath]) continue\n\n const rawPath = getRawPathFromConfig(pagePath) || '/'\n const processedPath = replaceBracketsWithColon(rawPath)\n const routePath = normalizePath(processedPath)\n\n let Component${t?": MyRouteObject['element']":""}\n if (!cachedLazyComponents[compPath]) {\n cachedLazyComponents[compPath] = lazy(pagesComponent[compPath])\n }\n Component = <LazyComponent Element={cachedLazyComponents[compPath]} />\n\n result.push({\n ...page,\n path: routePath,\n type: page?.type,\n isRoot: processedPath === '/root',\n element: Component\n })\n }\n\n return result\n}`)(e,o):((e,t)=>`\nconst PATH_REPLACEMENTS${t?": Record<string, string>":""} = {\n '/home': '/',\n '/root': '/'\n}\n\nconst getConfigFileName = ${t?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${t?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${t?"ts":"js"}'\n }\n return pagePath.replace('index.${t?"ts":"js"}', 'index.config.${t?"ts":"js"}')\n}\n\nconst formatPageModule = (${t?"\n pagesComponent: PagesComponentType,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${t?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${t?"(pathStr: string): string":"(pathStr)"} => {\n if (PATH_REPLACEMENTS[pathStr]) {\n return PATH_REPLACEMENTS[pathStr]\n }\n\n const lowerPath = pathStr.toLowerCase()\n if (lowerPath === '/notfound' || pathStr === '/404') {\n return '/*'\n }\n\n return pathStr\n}\n\nconst getBasename = ${t?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1]\n if (ext && lastPart.endsWith(ext)) {\n return lastPart.slice(0, -ext.length)\n }\n return lastPart\n}\n\nconst getDirname = ${t?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${t?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${t?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${t?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n if (fileName === 'index') {\n return dirPath || '/'\n }\n return dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n return (\n configPath.replace('/${e}', '').replace('/index.config.${t?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${t?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${t?": PagesComponentType | Record<string, PageConfig>":""} = {}\n\n for (const [path, module] of Object.entries(modules)) {\n if ('default' in module) {\n result[path] = module.default${t?" as ComponentType<unknown> | PageConfig":""}\n }\n }\n\n return result\n}\n\nconst filterUnComponent = ${t?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${t?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${t?"tsx":"jsx"}')) {\n result[key] = pagesComponent[key]\n }\n }\n\n return result\n}\n\nconst createBaseRoutes = () => {\n const pagesComponent = filterUnComponent(\n getFileDefault({\n ...import.meta.glob('/${e}/**/*.${t?"tsx":"jsx"}', { eager: true })\n })${t?" as PagesComponentType":""}\n )\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${t?"ts":"js"}', {\n eager: true\n })\n })${t?" as Record<string, PageConfig>":""}\n\n const result${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const [pagePath, page] of formatPageModule(pagesComponent, pagesModule)) {\n const compPath = getCompPathFromConfig(pagePath)\n\n if (!pagesComponent[compPath]) continue\n\n const rawPath = getRawPathFromConfig(pagePath) || '/'\n const processedPath = replaceBracketsWithColon(rawPath)\n const routePath = normalizePath(processedPath)\n\n const Component = pagesComponent[compPath]\n result.push({\n ...page,\n path: routePath,\n type: page?.type,\n isRoot: processedPath === '/root',\n element: <Component />\n })\n }\n\n return result\n}`)(e,o),i=(e=>`\nconst processRoute = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} =>\n cleanIsRoot(removeEmptyChildren(route))\n\nconst processRoutes = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} =>\n buildRouteTree(routes).map(processRoute)\n\nconst handleRootRoute = ${e?"(routes: (MyRouteObject & { isRoot?: boolean })[])":"(routes)"} => {\n let rootRoute${e?": MyRouteObject | undefined":" = undefined"}\n let homeRoute${e?": MyRouteObject | undefined":" = undefined"}\n let notFoundRoute${e?": MyRouteObject | undefined":" = undefined"}\n const filteredRoutes${e?": MyRouteObject[]":""} = []\n\n for (const route of routes) {\n if (route.isRoot) {\n if (rootRoute)\n throw new Error('There cannot be multiple root routes in a route')\n rootRoute = route\n } else if (route.path === '/') {\n homeRoute = route\n } else if (route.path === '/*') {\n notFoundRoute = route\n } else {\n filteredRoutes.push(route)\n }\n }\n\n if (hasDuplicateProperty(filteredRoutes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n const children = [\n homeRoute && { ...homeRoute, index: true },\n ...processRoutes(filteredRoutes)\n ].filter(${e?"(route): route is NonNullable<typeof route> => Boolean(route)":"Boolean"})\n\n const result${e?": MyRouteObject[]":""} = []\n\n if (rootRoute) {\n result.push(cleanIsRoot({ ...rootRoute, children }))\n }\n\n if (notFoundRoute) {\n result.push(cleanIsRoot(notFoundRoute))\n }\n\n return result\n}\n\nconst formatRoutes = (\n routes${e?": (MyRouteObject & { isRoot?: boolean })[]":""}\n) => {\n if (routes.some(r => r.isRoot)) return handleRootRoute(routes)\n\n if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return processRoutes(routes)\n}`)(o),c=(e=>`\nconst processSingleRoute = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n if (route.index) {\n return route\n }\n\n if (route.type !== 'wrap') {\n const { path: routePath, children, ...extraProps } = route\n const hasExtraProps = Object.keys(extraProps).length > 0\n\n if (hasExtraProps) {\n const indexRoute${e?": MyRouteObject":""} = {\n path: '',\n index: true,\n ...extraProps\n }\n\n return {\n path: routePath,\n children: [indexRoute, ...(children || []).map(processSingleRoute)]\n }\n }\n }\n\n if (route.children) {\n return {\n ...route,\n children: route.children.map(processSingleRoute)\n }\n }\n\n return route\n}\n\nconst formatRouteTree = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n return routes.map(processSingleRoute)\n}\n\nconst buildTreeStructure = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n const routeMap = new Map${e?"<string, MyRouteObject>":""}()\n const rootRoutes${e?": MyRouteObject[]":""} = []\n const pathPartsCache = new Map${e?"<string, string[]>":""}()\n\n const getPathParts = ${e?"(pathStr: string): string[]":"(pathStr)"} => {\n let parts = pathPartsCache.get(pathStr)\n if (parts === undefined) {\n parts = pathStr === '/' ? [] : pathStr.split('/').filter(Boolean)\n pathPartsCache.set(pathStr, parts)\n }\n return parts\n }\n\n const sortedRoutes = routes\n .slice()\n .sort((a, b) => a.path.length - b.path.length)\n\n for (const route of sortedRoutes) {\n const routePath = route.path\n const pathParts = getPathParts(routePath)\n const currentRoute = { ...route, children: [] }\n routeMap.set(routePath, currentRoute)\n\n if (pathParts.length <= 1) {\n rootRoutes.push(currentRoute)\n continue\n }\n\n const parentPath = '/' + pathParts.slice(0, -1).join('/')\n const parentRoute = routeMap.get(parentPath)\n\n if (parentRoute) {\n currentRoute.path = pathParts[pathParts.length - 1]\n parentRoute.children${e?"!":""}.push(currentRoute)\n } else {\n rootRoutes.push(currentRoute)\n }\n }\n\n return rootRoutes\n}\n\nconst buildRouteTree = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n const treeStructure = buildTreeStructure(routes)\n return formatRouteTree(treeStructure)\n}`)(o),p=(e=>`\nconst cleanIsRoot = ${e?"(route: RouteWithIsRoot): MyRouteObject":"(route)"} => {\n const { isRoot, type, children, ...rest } = route${e?" as RouteWithIsRoot & {\n type?: unknown\n }":""}\n\n if (!children?.length) {\n return rest\n }\n\n return {\n ...rest,\n children: children.map(cleanIsRoot)\n }\n}`)(o),l=(e=>`\nconst removeEmptyChildren = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n const { children } = route\n\n if (!children?.length) {\n const { children: _, ...rest } = route\n return rest\n }\n\n const processedChildren = children.map(removeEmptyChildren)\n\n if (route.type === 'wrap') {\n return { ...route, children: processedChildren }\n }\n\n const { path, element, type, children: _, ...rest } = route\n\n if (!element) {\n return { path, ...rest, children: processedChildren }\n }\n\n return {\n path,\n children: [\n { index: true, element, ...rest }${e?" as MyRouteObject":""},\n ...processedChildren\n ]\n }\n}`)(o),h=o?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",f=(e=>`\nconst getRoutes = () => {\n const baseRoutes = createBaseRoutes()\n const formattedRoutes = formatRoutes(baseRoutes)${e?" as RouteObject[]":""}\n return formattedRoutes\n}\n\nexport const routes = getRoutes()`)(o),d=((e,t,n,o,r,s,a,i)=>`// Auto-generated by ono-auto-router${e}${t}${n}${o}${r}${s}${a}${i}\n`)(((e,t)=>e?`\n${t?"import {\n lazy,\n Suspense,\n type ComponentType,\n type LazyExoticComponent\n} from 'react'":"import type { ComponentType } from 'react'"}\nimport type { RouteObject } from 'react-router'\n\n${t?"type PagesComponentType = Record<\n string,\n () => Promise<{ default: ComponentType<unknown> }>\n>":"type PagesComponentType = Record<string, ComponentType<unknown>>"}\n\ninterface MyRouteObject extends Omit<RouteObject, 'path' | 'children'> {\n path: string\n type?: 'single' | 'wrap'\n children?: MyRouteObject[]\n}\n\ntype RouteWithIsRoot = MyRouteObject & { isRoot?: boolean }\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'Component' | 'element' | 'children' | 'path'>\n>`:t?"\nimport { lazy, Suspense } from 'react'\n":"")(o,n),(e=>`\nconst hasDuplicateProperty = ${e?"<T, K extends keyof T>(items: T[], propName: K)":"(items, propName)"} => {\n const seenValues = new Set()\n return items.some(item => {\n if (seenValues.has(item[propName])) {\n return true\n }\n seenValues.add(item[propName])\n return false\n })\n}\n\nconst replaceBracketsWithColon = ${e?"(str: string)":"(str)"} => {\n return str.replace(/\\[([^\\]]+)\\]/g, ':$1').replace('.tsx', '')\n}`)(o),l,p,c,i,a,f);o?(we(u.default.resolve(r,"./index.ts"),s),we(u.default.resolve(r,"./autoRouter.tsx"),d),we(u.default.resolve(r,"./defineConfig.ts"),h)):we(t,d)},V={"/home":"/","/root":"/"},X=(e,t)=>{const n=e.split("/"),o=n[n.length-1];return t&&o.endsWith(t)?o.slice(0,-t.length):o},q=e=>{const t=V[e];return t||("/notfound"===e.toLowerCase()||"/404"===e?"/:pathMatch(.*)*":e)},J=(e,t)=>e.endsWith(".config."+(t?"ts":"js"))?"index"===X(e,".config."+(t?"ts":"js"))?e.replace("index.config."+(t?"ts":"js"),"index."+(t?"ts":"js")):e.slice(0,-10)+".vue":e.replace("index.config."+(t?"ts":"js"),"index."+(t?"ts":"js")),Z=(e,t,n)=>{if(e.endsWith(".config."+(n?"ts":"js"))){const o=X(e,".config."+(n?"ts":"js")),r=(e=>{const t=e.split("/");return t.pop(),t.join("/")})(e).replace(t,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(t,"").replace("/index.config."+(n?"ts":"js"),"")||"/"},G=async(e,t,n,o)=>{const r=[];for(const[s,a]of((e,t,n)=>Object.keys(e).map(e=>{const o=((e,t)=>e.replace("index."+(t?"ts":"js"),"index.config."+(t?"ts":"js")))(e,n);return[o,t[o]||{}]}))(e,t,o)){const t=J(s,o),i=xe(Z(s,`/${n}`,o)||"/",o,"vue"),u=q(i);r.push({...a,path:u,type:a?.type,isRoot:"/root"===i,component:e[t]})}return r},Q=e=>{if(!e.path)return e;if("wrap"!==e.type){const{path:t,children:n,...o}=e;if(Object.keys(o).length>0)return{path:t,children:[{path:"",...o},...(n||[]).map(Q)]}}return e.children?{...e,children:e.children.map(Q)}:e},Y=e=>(e=>e.map(Q))((e=>{const t=new Map,n=[],o=new Map,r=e=>{let t=o.get(e);return void 0===t&&(t="/"===e?[]:e.split("/").filter(Boolean),o.set(e,t)),t},s=e.slice().sort((e,t)=>e.path.length-t.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(t.set(e,s),o.length<=1){n.push(s);continue}const i="/"+o.slice(0,-1).join("/"),u=t.get(i);u?(s.path=o[o.length-1],u.children.push(s)):n.push(s)}return n})(e)),ee=e=>{const{isRoot:t,type:n,children:o,...r}=e;return o?.length?{...r,children:o.map(ee)}:r},te=e=>{const{children:t}=e;if(!t?.length){const{children:t,...n}=e;return n}const n=t.map(te);if("wrap"===e.type)return{...e,children:n};const{path:o,component:r,type:s,children:a,...i}=e;return r?{path:o,children:[{path:"",component:r,...i},...n]}:{path:o,...i,children:n}},ne=e=>ee(te(e)),oe=e=>Y(e).map(ne),re=e=>{if(e.some(e=>e.isRoot))return(e=>{let t,n,o;const r=[];for(const i of e)if(i.isRoot){if(t)throw new Error("There cannot be multiple root routes in a route");t=i}else"/"===i.path?n=i:"/:pathMatch(.*)*"===i.path?o=i:r.push(i);if($e(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[n&&{...n,index:!0},...oe(r)].filter(e=>Boolean(e)),a=[];return t&&a.push(ee({...t,children:s})),o&&a.push(ee(o)),a})(e);if($e(e,"path"))throw new Error("There cannot be duplicate paths in a route");return oe(e)},se=(e,t)=>({import:`import ${e} from './${t}'`,component:`<start>${e}</end>`,lazyComponent:`<start>() => import('${t}')</end>`});var ae=(e,t,n,o,r,s,a)=>{const i=((e,t)=>e.replace("index.vue",t?Me:ve))(Pe(e,t),a),u=me(de(n,e)),c=he(C(u),s),p=`component(${u})`;o[`/${i}`]=p,r.set(p,{path:u,componentName:c})},ie=(e,t,n,o)=>{const r=Pe(e,t);n[`/${r}`]=g(r,fe(e),o)};function ue(e,t,n,o,r,s,a,i,u){const p={},l=e.replace(/^\/+/,""),h=c.default.sync(l,{cwd:t,absolute:!0,onlyFiles:!0}),f="component"===r?((e,t)=>t.map(t=>t.includes("index.vue")||2===t.replace(e.replaceAll("\\","/"),"").split("/").length?t:void 0).filter(Boolean))(t,h):h.filter(ye);for(const c of f)if("component"===r){if(c.includes(".config."))continue;ae(c,n,o,p,s,a,u)}else ie(c,n,p,i);return p}var ce=async(e,t,n,o,r,s)=>{const a=new Map,i=new Set,u=new Map;we(o,((e,t,n,o)=>{let r=e;for(const[s,a]of t){const e=se(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of n)r=r.replace(s,a);return be(r)})(function(e,t,n,o){return`// Auto-generated by ono-auto-router${n?"\nimport type { RouteRecordRaw } from 'vue-router'":""}${o?"":`\n${t.join("\n")}${n?"":"\n"}`}${n?"\n\ntype PageConfig = Partial<\n Omit<RouteRecordRaw, 'path' | 'component' | 'children'> & {\n type?: 'single' | 'wrap'\n }\n>\n":""}${n?"\nexport const defineConfig = (config: PageConfig) => config\n":""}\nexport const routes${n?": RouteRecordRaw[]":""} = ${JSON.stringify(e,null,2)}\n`}(re(await G(ue("/**/*.vue",t,n,o,"component",a,i,u,s),ue("/**/*.config.{js,ts}",t,n,o,"config",a,i,u,s),e,s)),((e,t)=>{if(e)return[];const n=[];for(const o of t.values())n.push(se(o.componentName,o.path).import);return n})(r,a),s,r),a,u,r))},pe=(e,t,n,o)=>{const r=t.split(".")[0],s=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(n),a=((e,t,n)=>`\nconst pathCache = new Map${t?"<string, { compPath: string; basePath: string }>":""}()\nconst basenameCache = new Map${t?"<string, string>":""}()\n\nconst normalizePagePath = ${t?"(key: string): string":"(key)"} => {\n if (key.includes('index.vue')) return key.replace('index.vue', 'index.${t?"ts":"js"}')\n if (key.includes('root.vue')) return key.replace('root.vue', 'root/index.${t?"ts":"js"}')\n if (key.includes('404.vue')) return key.replace('404.vue', '404/index.${t?"ts":"js"}')\n if (key.toLowerCase().includes('notfound.vue'))\n return key.toLowerCase().replace('notfound.vue', 'notfound/index.${t?"ts":"js"}')\n return key\n}\n\nconst getBasename = ${t?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const cacheKey = ext ? filePath + ':' + ext : filePath\n if (basenameCache.has(cacheKey)) {\n return basenameCache.get(cacheKey)${t?"!":""}\n }\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1] || ''\n let result = lastPart\n if (ext && lastPart.endsWith(ext)) {\n result = lastPart.slice(0, -ext.length)\n }\n basenameCache.set(cacheKey, result)\n return result\n}\n\nconst getDirname = ${t?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getPathsFromConfig = ${t?"(configPath: string)":"(configPath)"} => {\n const cacheKey = configPath\n if (pathCache.has(cacheKey)) {\n return pathCache.get(cacheKey)${t?"!":""}\n }\n\n let compPath${t?": string":" = ''"}\n let basePath${t?": string":" = ''"}\n\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n\n if (fileName === 'index') {\n compPath = configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"ts":"js"}')\n basePath = dirPath || '/'\n } else {\n compPath = configPath.slice(0, -10) + '.vue'\n basePath = dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n } else {\n compPath = configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"ts":"js"}')\n basePath =\n configPath.replace('/${e}', '').replace('/index.config.${t?"ts":"js"}', '') ||\n '/'\n }\n\n const result = { compPath, basePath }\n pathCache.set(cacheKey, result)\n return result\n}\n\nconst formatPath = ${t?"(path: string): string":"(path)"} => {\n const lowerPath = path.toLowerCase()\n if (lowerPath === '/home') return '/'\n if (lowerPath === '/notfound' || path === '/404') return '/:pathMatch(.*)*'\n return path.replace('/index.${t?"ts":"js"}', '') || '/'\n}\n\nconst getConfigFileName = ${t?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.vue')) {\n return pagePath.slice(0, -4) + '.config.${t?"ts":"js"}'\n }\n return pagePath.replace('index.${t?"ts":"js"}', 'index.config.${t?"ts":"js"}')\n}\n\nconst createBaseRoutes = ()${t?": MyRouteObject[]":""} => {\n const pagesComponent = Object.fromEntries(\n Object.entries({\n ...import.meta.glob('/${e}/**/index.vue'${n?"":", { eager: true, import: 'default' }"}),\n ...import.meta.glob('/${e}/*.vue'${n?"":", { eager: true, import: 'default' }"})\n }${t?" as PagesComponentType":""}).map(([key, value]) => [\n normalizePagePath(key),\n value\n ])\n )\n\n const pagesModule${t?": Record<string, PageConfig>":""} = import.meta.glob(\n '/${e}/**/*.config.${t?"ts":"js"}',\n { eager: true, import: 'default' }\n )\n\n const result${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const pagePath of Object.keys(pagesComponent)) {\n const configPath = getConfigFileName(pagePath)\n const content = pagesModule[configPath] || {}\n const { compPath, basePath } = getPathsFromConfig(configPath)\n const path = replaceBracketsWithColon(basePath || '/')\n const name = path.split('/').filter(Boolean).join('-') || 'index'\n\n result.push({\n path: formatPath(path),\n name,\n component: pagesComponent[compPath],\n isRoot: path === '/root',\n ...content${t?"!":""}\n })\n }\n\n return result\n}\n\nconst processRoutes = ${t?"(\n routes: MyRouteObject[],\n removeLeadingSlash = false\n): MyRouteObject[]":"(routes, removeLeadingSlash)"} =>\n buildRouteTree(routes, removeLeadingSlash)\n .map(removeEmptyChildren)\n .map(cleanIsRoot)\n\nconst handleRootRoute = ${t?"(\n routes: (MyRouteObject & { isRoot?: boolean })[]\n): MyRouteObject[]":"(routes)"} => {\n let rootRoute${t?": (MyRouteObject & { isRoot?: boolean }) | undefined":" = undefined"}\n let homeRoute${t?": MyRouteObject | undefined":" = undefined"}\n let notFoundRoute${t?": MyRouteObject | undefined":" = undefined"}\n const filteredRoutes${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const route of routes) {\n if (route.isRoot) {\n if (rootRoute)\n throw new Error('There cannot be multiple root routes in a route')\n rootRoute = route\n } else if (route.path === '/') {\n homeRoute = route\n } else if (route.path === '/:pathMatch(.*)*') {\n notFoundRoute = route\n } else {\n filteredRoutes.push(route)\n }\n }\n\n if (hasDuplicateProperty(filteredRoutes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n const processedRoutes${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n if (rootRoute) {\n const children = [\n homeRoute && { ...homeRoute, path: '' },\n ...processRoutes(filteredRoutes, true)\n ].filter(Boolean)${t?" as MyRouteObject[]":""}\n processedRoutes.push({ ...rootRoute, path: '/', children })\n }\n\n if (notFoundRoute) processedRoutes.push(notFoundRoute)\n\n return processedRoutes.map(cleanIsRoot)\n}\n\nconst createRoutes = ()${t?": RouteRecordRaw[]":""} => {\n const routes = createBaseRoutes()\n\n if (routes.some((r${t?": MyRouteObject & { isRoot?: boolean }":""}) => r.isRoot))\n return handleRootRoute(routes)${t?" as RouteRecordRaw[]":""}\n\n if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return processRoutes(routes)${t?" as RouteRecordRaw[]":""}\n}\n`)(e,n,o),i=(e=>`\nconst buildRouteTree = ${e?"(\n routes: MyRouteObject[],\n removeLeadingSlash: boolean = false\n)":"(routes, removeLeadingSlash)"} => {\n const routeMap = new Map${e?"<string, MyRouteObject & { isRoot?: boolean }>":""}()\n const rootRoutes${e?": MyRouteObject[]":""} = []\n\n const sortedRoutes = [...routes].sort((a, b) => a.path.length - b.path.length)\n\n for (const route of sortedRoutes) {\n let path = route.path\n if (removeLeadingSlash && path.startsWith('/')) {\n path = path.slice(1)\n }\n routeMap.set(path, { ...route, path, children: [] })\n }\n\n for (const [path, route] of routeMap) {\n const slashIndex = path.lastIndexOf('/')\n\n if (slashIndex <= 0) {\n const { isRoot, ...rest } = route\n rootRoutes.push(rest)\n continue\n }\n\n const parentPath = path.slice(0, slashIndex)\n const parentRoute = routeMap.get(parentPath)\n\n if (parentRoute) {\n const relativePath = path.slice(slashIndex + 1)\n const childRoute = { ...route, path: relativePath }\n parentRoute.children${e?"!":""}.push(childRoute)\n } else {\n const { isRoot, ...rest } = route\n rootRoutes.push(rest)\n }\n }\n\n return rootRoutes\n}\n`)(n),c=(e=>`\nconst cleanIsRoot = ${e?"(\n route: MyRouteObject & { isRoot?: boolean }\n): MyRouteObject":"(route)"} => {\n const { isRoot, type, children, ...rest } = route\n const result${e?": MyRouteObject":""} = { ...rest }\n\n if (children?.length) {\n result.children = children.map(cleanIsRoot)\n }\n\n return result\n}\n`)(n),p=(e=>`\nconst removeEmptyChildren = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n if (!route.children?.length) {\n const { children, ...rest } = route\n return rest\n }\n\n const hasIndexRoute = route.children.some(\n child => child.path === '' || child.path === '/'\n )\n\n const routeType = route.type || 'single'\n\n if (routeType === 'wrap') {\n const { children, ...rest } = route\n return { ...rest, children: children.map(removeEmptyChildren) }\n }\n\n if (routeType === 'single' || (!hasIndexRoute && route.component)) {\n const { path, component, type, ...rest } = route\n return {\n path,\n children: [\n { path: '', component, ...rest }${e?" as MyRouteObject":""},\n ...route.children.map(removeEmptyChildren)\n ]\n }\n }\n\n if (hasIndexRoute) {\n const { path, ...rest } = route\n const updatedChildren = route.children.map(child =>\n child.path === '' || child.path === '/' ? { ...rest, ...child } : child\n )\n return { path, children: updatedChildren.map(removeEmptyChildren) }\n }\n\n return { ...route, children: route.children.map(removeEmptyChildren) }\n}\n`)(n),l=n?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",h=((e,t,n,o,r,s,a)=>`// Auto-generated by ono-auto-router${e}${t}${n}${o}${r}${s}${a}\n`)(n?"\nimport type { RouteRecordRaw } from 'vue-router'\n\ntype PagesComponentType = Record<string, () => Promise<unknown>>\n\ninterface MyRouteObject extends Omit<RouteRecordRaw, 'children'> {\n type?: 'single' | 'wrap'\n children?: MyRouteObject[]\n}\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'component' | 'children' | 'path'>\n>\n":"",(e=>`\nconst hasDuplicateProperty = ${e?"<T>(items: T[], propName: keyof T)":"(items, propName)"} => {\n const seenValues = new Set()\n return items.some(item => {\n if (seenValues.has(item[propName])) {\n return true\n }\n seenValues.add(item[propName])\n return false\n })\n}\n\nconst replaceBracketsWithColon = ${e?"(str: string)":"(str)"} => {\n return str.replace(/\\[([^\\]]+)\\]/g, ':$1').replace('.tsx', '')\n}\n`)(n),p,c,i,a,"\nexport const routes = createRoutes()");n?(we(u.default.resolve(r,"./index.ts"),s),we(u.default.resolve(r,"./autoRouter.ts"),h),we(u.default.resolve(r,"./defineConfig.ts"),l)):we(t,h)},le=(e,t,n,o,r,s)=>{const a=u.default.resolve(n,t);if(!i.default.existsSync(a))throw new Error(`Pages directory not found: ${a}`);const c=y(e,n,o),p=P(n),l=c.split(".")[0];f(l+".js"),f(l+".ts"),f(l+".jsx"),f(l+".tsx"),d(l),"react"===e?s?U(t,c,r,p):H(t,a,n,c,r,p):s?pe(t,c,p,r):ce(t,a,n,c,r,p),console.log(`[ono-auto-router] Routes file generated: ${s?u.default.resolve(c.replace(".tsx","").replace(".ts",""),"./autoRouter"+("react"===e?".tsx":".ts")):c}`)},he=(e,t)=>{if(!t.has(e))return t.add(e),e;let n=1;for(;t.has(`${e}_${n}`);)n++;return`${e}_${n}`};function fe(e){try{const n=i.default.readFileSync(e,"utf-8").match(/export\s+default\s+([\s\S]*?)(?=\n\w|$)/);if(!n)return console.warn("No export default found in:",e),null;const o=n[1].trim();try{if(o.startsWith("{"))return new Function(`return ${o}`)();if(o.includes("defineConfig(")){const e=o.match(/defineConfig([\s\S]*)$/);if(e)return new Function(`return ${e[1]}`)()}return null}catch(t){return console.error("Error parsing export default content:",t),null}}catch(n){return console.error("Error reading file:",n),null}}function de(e,t){let n=u.default.resolve(e);(n.endsWith(".js")||n.endsWith(".jsx")||n.endsWith(".ts")||n.endsWith(".tsx")||n.endsWith(".vue"))&&(n=u.default.dirname(n));const o=u.default.resolve(t);return u.default.relative(n,o)}var ge=/\\/g,me=e=>e.replace(ge,"/"),Pe=(e,t)=>me(u.default.relative(t,e)),Re=/export\s+default\s+[\w(\[\]\{\})]+/;function ye(e){try{if(!i.default.existsSync(e))return console.warn(`File not found: ${e}`),!1;const t=i.default.readFileSync(e,"utf-8");return Re.test(t)}catch(t){return console.error("Read error:",t),!1}}var $e=(e,t)=>{const n=new Set;return e.some(e=>!!n.has(e[t])||(n.add(e[t]),!1))};function je(e){return e.replace(/"<start>([\s\S]*?)<\/end>"/g,"$1")}function be(e){let t=e;for(;;){const e=je(t);if(e===t)break;t=e}return t}var xe=(e,t,n)=>e.replace(/\[([^\]]+)\]/g,":$1").replace("react"===n?t?".tsx":".jsx":".vue","");function Ce(e){i.default.existsSync(e)||i.default.mkdirSync(e,{recursive:!0})}function Oe(e,t){Ce(u.default.dirname(e)),i.default.writeFileSync(e,t,"utf-8")}async function we(e,t){const n=u.default.dirname(e);await i.default.promises.mkdir(n,{recursive:!0}),await i.default.promises.writeFile(e,t,"utf-8")}var Me="index.ts",ve="index.js";Object.defineProperty(exports,"INDEX_JS_SUFFIX",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"INDEX_TS_SUFFIX",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,"capitalize",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"convertFunctionToArrow",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"deleteDir",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"deleteFile",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"ensureDirSync",{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,"formatFunction",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"formatPagesDir",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"formatRoutesFile",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"generateComponentName",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"generateReactRoutes",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"generateReactRoutesHMR",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"generateRoutesTemplate",{enumerable:!0,get:function(){return le}}),Object.defineProperty(exports,"generateUniqueComponentName",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"generateVueRoutes",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(exports,"generateVueRoutesHMR",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,"getDefaultExportContent",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,"getRelativePath",{enumerable:!0,get:function(){return de}}),Object.defineProperty(exports,"getRelativeProjectPath",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,"hasDefaultExport",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,"hasDuplicateProperty",{enumerable:!0,get:function(){return $e}}),Object.defineProperty(exports,"normalizePathWithWindows",{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,"removeCustomTagFunctionFromJSXAll",{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,"replaceBracketsWithColon",{enumerable:!0,get:function(){return xe}}),Object.defineProperty(exports,"useTs",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"writeFile",{enumerable:!0,get:function(){return we}}),Object.defineProperty(exports,"writeFileSync",{enumerable:!0,get:function(){return Oe}});