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

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.md CHANGED
@@ -10,6 +10,8 @@ English | [中文](./README.zh-CN.md)
10
10
  - Supports both React and Vue frameworks
11
11
  - Convention-based routing, automatically mapped by directory structure
12
12
  - Supports dynamic route `[id]` syntax
13
+ - `home` page path automatically converted to `/` (configurable)
14
+ - `root` page as root route container (configurable)
13
15
  - Configurable lazy loading and hot module replacement
14
16
  - Supports page-level configuration files
15
17
  - TypeScript type safety
@@ -22,6 +24,22 @@ npm install -D @onoxm/vite-plugin-auto-router
22
24
 
23
25
  ## 📖 Usage Guide
24
26
 
27
+ ### Page Component Identification Rules
28
+
29
+ The plugin identifies page components based on the following rules:
30
+
31
+ #### React Project
32
+
33
+ - **Page components**: Components with default export (`export default`) in the pages directory
34
+ - **Regular components**: Components with named export (`export const`) in the pages directory
35
+
36
+ #### Vue Project
37
+
38
+ - **Page components**:
39
+ - Direct child components in the views directory (e.g., `src/views/about.vue`)
40
+ - In nested directories, only `index.vue` is considered a page component (e.g., `src/views/a/b/index.vue`)
41
+ - **Regular components**: Non-`index.vue` files in nested directories (e.g., `src/views/a/b.vue`)
42
+
25
43
  ### React Project
26
44
 
27
45
  #### Install Dependencies
@@ -417,6 +435,8 @@ export const routes: RouteRecordRaw[] = [
417
435
  | `framework` | `'react' \| 'vue'` | `'react'` | Framework type |
418
436
  | `pagesDir` | `string` | `'./src/pages'` | Pages directory |
419
437
  | `routesFile` | `string` | `undefined` | Generated route file path |
438
+ | `keepHome` | `boolean` | `false` | Whether to keep home page path |
439
+ | `keepRoot` | `boolean` | `false` | Whether to keep root page path |
420
440
  | `lazy` | `boolean` | `true` | Whether to enable lazy loading |
421
441
  | `hmr` | `boolean` | `false` | Whether to enable hot module update |
422
442
 
package/README.zh-CN.md CHANGED
@@ -10,6 +10,8 @@
10
10
  - 支持 React 和 Vue 双框架
11
11
  - 约定式路由,按目录结构自动映射
12
12
  - 支持动态路由 `[id]` 语法
13
+ - `home` 页面路径自动转换为 `/`(可配置)
14
+ - `root` 页面作为根路由容器(可配置)
13
15
  - 可配置懒加载和热更新
14
16
  - 支持页面级配置文件
15
17
  - TypeScript 类型安全
@@ -22,6 +24,22 @@ npm install -D @onoxm/vite-plugin-auto-router
22
24
 
23
25
  ## 📖 使用指南
24
26
 
27
+ ### 页面组件判定规则
28
+
29
+ 插件根据以下规则判定哪些组件是页面组件:
30
+
31
+ #### React 项目
32
+
33
+ - **页面组件**:在页面文件夹中使用默认导出(`export default`)的组件
34
+ - **普通组件**:在页面文件夹中使用具名导出(`export const`)的组件
35
+
36
+ #### Vue 项目
37
+
38
+ - **页面组件**:
39
+ - 页面文件夹的直接子组件(如 `src/views/about.vue`)
40
+ - 嵌套文件夹中必须是 `index.vue` 才会被视为页面(如 `src/views/a/b/index.vue`)
41
+ - **普通组件**:嵌套文件夹中非 `index.vue` 的文件(如 `src/views/a/b.vue`)
42
+
25
43
  ### React 项目
26
44
 
27
45
  #### 安装依赖
@@ -416,6 +434,8 @@ export const routes: RouteRecordRaw[] = [
416
434
  | `framework` | `'react' \| 'vue'` | `'react'` | 框架类型 |
417
435
  | `pagesDir` | `string` | `'./src/pages'` | 页面目录 |
418
436
  | `routesFile` | `string` | `undefined` | 生成的路由文件路径 |
437
+ | `keepHome` | `boolean` | `false` | 是否保留 home 页面 |
438
+ | `keepRoot` | `boolean` | `false` | 是否保留 root 页面 |
419
439
  | `lazy` | `boolean` | `true` | 是否启用懒加载 |
420
440
  | `hmr` | `boolean` | `false` | 是否启用热更新 |
421
441
 
@@ -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,R=e=>i.default.existsSync(u.default.resolve(e,"tsconfig.json")),P={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,P[e][R(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,t,n)=>{const o=((e,t,n)=>t&&"/home"===e?"/home":n&&"/root"===e?"/root":O[e])(e,t,n);return o||("/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,r,s)=>{const a=[];for(const[i,u]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(i,o);if(!e[t])continue;const c=Oe(S(i,`/${n}`,o)||"/",o,"react"),p=M(c,r,s);a.push({...u,path:p,type:u?.type,isRoot:!s&&"/root"===c,element:e[t]})}return a},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)),L=e=>k(e).map(W),B=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(be(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[n&&{...n,index:!0},...L(r)].filter(e=>Boolean(e)),a=[];return t&&a.push(N({...t,children:s})),o&&a.push(N(o)),a})(e);if(be(e,"path"))throw new Error("There cannot be duplicate paths in a route");return L(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?Se:Te):e)(ye(e,t),a),u=Pe(me(n,e)),c=de(C(u),s),p=`element(${u})`;o[`/${i}`]=p,r.set(p,{path:u,componentName:c})},_=(e,t,n,o)=>{const r=ye(e,t);n[`/${r}`]=g(r,ge(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(je);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,a,i)=>{const u=new Map,c=new Set,p=new Map;ve(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 Ce(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`}(B(await T(K("/**/*.{jsx,tsx}",t,n,o,"component",u,c,p,s),K("/**/*.config.{js,ts,jsx,tsx}",t,n,o,"config",u,c,p,s),e,s,a,i)),((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,u),((e,t)=>{if(!e)return[];const n=[];for(const o of t.values())n.push(z(o.componentName,o.path).lazy);return n})(r,u),s),u,p,r))},U=(e,t,n,o,r,s)=>{const a=t.split(".")[0],i=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(o),c=n?((e,t,n,o)=>`\n\n${n&&o?"":`const PATH_REPLACEMENTS${t?": Record<string, string>":""} = {\n${n||o?n?"'/root': '/'":"'/home': '/'":" '/home': '/',\n '/root': '/'"}\n}\n\n`}const 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${n&&o?"":" 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?`: ${o?"MyRouteObject":"(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 ${o?"":"isRoot: processedPath === '/root',\n "}element: Component\n })\n }\n\n return result\n}`)(e,o,r,s):((e,t,n,o)=>`\n\n${n&&o?"":`const PATH_REPLACEMENTS${t?": Record<string, string>":""} = {\n${n||o?n?"'/root': '/'":"'/home': '/'":" '/home': '/',\n '/root': '/'"}\n}\n\n`}const 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${n&&o?"":" 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?`: ${o?"MyRouteObject":"(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 ${o?"":"isRoot: processedPath === '/root',\n "}element: Component\n })\n }\n\n return result\n}`)(e,o,r,s),p=((e,t)=>`\nconst processRoute = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} =>\n ${t?"removeEmptyChildren(route)":"cleanIsRoot(removeEmptyChildren(route))"}\n\nconst processRoutes = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} =>\n buildRouteTree(routes).map(processRoute)\n\n${t?"":`const 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\n`}const formatRoutes = (\n routes${e?`: ${t?"MyRouteObject":"(MyRouteObject & { isRoot?: boolean })"}[]`:""}\n) => {\n ${t?"":"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,s),l=(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),h=s?"":(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),f=(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),d=o?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",g=(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),m=((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,n)=>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\n${n?"":"type RouteWithIsRoot = MyRouteObject & { isRoot?: boolean }\n\n"}export type PageConfig = Partial<\n Omit<MyRouteObject, 'Component' | 'element' | 'children' | 'path'>\n>`:t?"\nimport { lazy, Suspense } from 'react'\n":"")(o,n,s),(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),f,h,l,p,c,g);o?(ve(u.default.resolve(a,"./index.ts"),i),ve(u.default.resolve(a,"./autoRouter.tsx"),m),ve(u.default.resolve(a,"./defineConfig.ts"),d)):ve(t,m)},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,t,n)=>{const o=((e,t,n)=>t&&"/home"===e?"/home":n&&"/root"===e?"/root":V[e])(e,t,n);return o||("/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,r,s)=>{const a=[];for(const[i,u]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(i,o),c=Oe(Z(i,`/${n}`,o)||"/",o,"vue"),p=q(c,r,s);a.push({...u,path:p,type:u?.type,isRoot:!s&&"/root"===c,component:e[t]})}return a},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(be(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[n,...oe(r)].filter(e=>Boolean(e)),a=[];return t&&a.push(ee({...t,children:s})),o&&a.push(ee(o)),a})(e);if(be(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?Se:Te))(ye(e,t),a),u=Pe(me(n,e)),c=de(C(u),s),p=`component(${u})`;o[`/${i}`]=p,r.set(p,{path:u,componentName:c})},ie=(e,t,n,o)=>{const r=ye(e,t);n[`/${r}`]=g(r,ge(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(je);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,a,i)=>{const u=new Map,c=new Set,p=new Map;ve(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 Ce(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",u,c,p,s),ue("/**/*.config.{js,ts}",t,n,o,"config",u,c,p,s),e,s,a,i)),((e,t)=>{if(e)return[];const n=[];for(const o of t.values())n.push(se(o.componentName,o.path).import);return n})(r,u),s,r),u,p,r))},pe=(e,t,n,o,r,s)=>{const a=t.split(".")[0],i=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(o),c=((e,t,n,o,r)=>`\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 ${o?"":"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?`: ${r?"MyRouteObject":"(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 ${r?"":"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 ${r?"buildRouteTree(routes, removeLeadingSlash)\n .map(removeEmptyChildren)":"buildRouteTree(routes, removeLeadingSlash)\n .map(removeEmptyChildren)\n .map(cleanIsRoot)"}\n\n${r?"":`const 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 ${r?"processedRoutes":"processedRoutes.map(cleanIsRoot)"}\n}\n\n`}const createRoutes = ()${t?": RouteRecordRaw[]":""} => {\n const routes = createBaseRoutes()\n\n ${r?"":`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,o,n,r,s),p=((e,t)=>`\nconst buildRouteTree = ${e?"(\n routes: MyRouteObject[],\n removeLeadingSlash: boolean = false\n)":"(routes, removeLeadingSlash)"} => {\n const routeMap = new Map${e?`<string, ${t?"MyRouteObject":"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 ${t?"rootRoutes.push(route)":"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 ${t?"rootRoutes.push(route)":"const { isRoot, ...rest } = route\n rootRoutes.push(rest)"}\n }\n }\n\n return rootRoutes\n}\n`)(o,s),l=s?"":(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`)(o),h=(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`)(o),f=o?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",d=((e,t,n,o,r,s,a)=>`// Auto-generated by ono-auto-router${e}${t}${n}${o}${r}${s}${a}\n`)(o?"\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`)(o),h,l,p,c,"\nexport const routes = createRoutes()");o?(ve(u.default.resolve(a,"./index.ts"),i),ve(u.default.resolve(a,"./autoRouter.ts"),d),ve(u.default.resolve(a,"./defineConfig.ts"),f)):ve(t,d)},le={react:{hmr:(e,t,n,o,r,s,a,i)=>U(e,o,r,s,a,i),normal:H},vue:{hmr:(e,t,n,o,r,s,a,i)=>pe(e,o,r,s,a,i),normal:ce}},he=[".js",".ts",".jsx",".tsx"],fe=(e,t,n,o,r,s,a,c)=>{const p=u.default.resolve(n,t);if(!i.default.existsSync(p))throw new Error(`Pages directory not found: ${p}`);const l=y(e,n,o);(e=>{for(const t of he)f(e+t);d(e)})(l.split(".")[0]),le[e][c?"hmr":"normal"](t,p,n,l,a,R(n),r,s),console.log(`[ono-auto-router] Routes file generated: ${c?u.default.resolve(l.replace(".tsx","").replace(".ts",""),"./autoRouter"+("react"===e?".tsx":".ts")):l}`)},de=(e,t)=>{if(!t.has(e))return t.add(e),e;let n=1;for(;t.has(`${e}_${n}`);)n++;return`${e}_${n}`};function ge(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 me(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 Re=/\\/g,Pe=e=>e.replace(Re,"/"),ye=(e,t)=>Pe(u.default.relative(t,e)),$e=/export\s+default\s+[\w(\[\]\{\})]+/;function je(e){try{if(!i.default.existsSync(e))return console.warn(`File not found: ${e}`),!1;const t=i.default.readFileSync(e,"utf-8");return $e.test(t)}catch(t){return console.error("Read error:",t),!1}}var be=(e,t)=>{const n=new Set;return e.some(e=>!!n.has(e[t])||(n.add(e[t]),!1))};function xe(e){return e.replace(/"<start>([\s\S]*?)<\/end>"/g,"$1")}function Ce(e){let t=e;for(;;){const e=xe(t);if(e===t)break;t=e}return t}var Oe=(e,t,n)=>e.replace(/\[([^\]]+)\]/g,":$1").replace("react"===n?t?".tsx":".jsx":".vue","");function we(e){i.default.existsSync(e)||i.default.mkdirSync(e,{recursive:!0})}function Me(e,t){we(u.default.dirname(e)),i.default.writeFileSync(e,t,"utf-8")}async function ve(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 Se="index.ts",Te="index.js";Object.defineProperty(exports,"INDEX_JS_SUFFIX",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(exports,"INDEX_TS_SUFFIX",{enumerable:!0,get:function(){return Se}}),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 we}}),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 fe}}),Object.defineProperty(exports,"generateUniqueComponentName",{enumerable:!0,get:function(){return de}}),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 ge}}),Object.defineProperty(exports,"getRelativePath",{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,"getRelativeProjectPath",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,"hasDefaultExport",{enumerable:!0,get:function(){return je}}),Object.defineProperty(exports,"hasDuplicateProperty",{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,"normalizePathWithWindows",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,"removeCustomTagFunctionFromJSXAll",{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,"replaceBracketsWithColon",{enumerable:!0,get:function(){return Oe}}),Object.defineProperty(exports,"useTs",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"writeFile",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"writeFileSync",{enumerable:!0,get:function(){return Me}});
@@ -0,0 +1 @@
1
+ import e from"node:fs";import n from"node:path";import t from"fast-glob";function o(e){let n=r(e,0),t=!1;if(n+5<=e.length&&"async"===e.slice(n,n+5).toLowerCase()&&(t=!0,n=r(e,n+5)),n<e.length&&"("===e[n]){const t=s(e,n);if(-1!==t){let n=r(e,t+1);if(n+1<e.length&&"="===e[n]&&">"===e[n+1])return e}}const o=e.indexOf("(");if(-1===o)return e;const a=s(e,o);if(-1===a)return e;return(t?"async ":"")+e.slice(o,a+1)+" => "+e.slice(a+1)}function r(e,n){for(;n<e.length&&/\s/.test(e[n]);)n++;return n}function s(e,n){let t=0,o=!1,r="";for(let s=n;s<e.length;s++){const n=e[s];if('"'!==n&&"'"!==n&&"`"!==n){if(!o)if("("===n)t++;else if(")"===n&&(t--,0===t))return s}else o?n===r&&(o=!1):(o=!0,r=n)}return-1}var a=n=>{try{if(!e.existsSync(n))return;e.unlinkSync(n)}catch(t){console.error("删除文件失败:",t)}},i=n=>{try{if(!e.existsSync(n))return;e.rmSync(n,{recursive:!0})}catch(t){console.error("删除目录失败:",t)}},c=(e,n,t)=>{const r={};for(const[s,a]of Object.entries(n))if("function"==typeof a){const n=`${e}-${s}`;r[s]=n,t.set(n,`<start>${o(a.toString())}</end>`)}else r[s]=a;return r},u=e=>e.startsWith("/")?e.slice(1):e.endsWith("/")?e.slice(0,-1):e.startsWith("./")?e.slice(2):e,p=t=>e.existsSync(n.resolve(t,"tsconfig.json")),l={react:{ts:"src/router/autoRouter.tsx",js:"src/router/autoRouter.jsx"},vue:{ts:"src/router/autoRouter.ts",js:"src/router/autoRouter.js"}},h=(e,t,o)=>{let r=o;return r=r?n.resolve(t,r):n.resolve(t,l[e][p(t)?"ts":"js"]),r},f=/[/\\]/,g=/[^a-zA-Z0-9]/g,d=/^(\d)/,m=e=>e?e.charAt(0).toUpperCase()+e.slice(1).toLowerCase():"";function R(e){const t=n.extname(e),o=n.basename(e,t),r=n.dirname(e).split(f).filter(Boolean);return"index"!==o&&"Index"!==o&&r.push(o),r.map(e=>(e=>e.replace(g,"_").replace(d,"_$1"))(e).split("_").map(m).join("")).join("")||"Component"}var $={"/home":"/","/root":"/"},P=(e,n)=>{const t=e.split("/"),o=t[t.length-1];return n&&o.endsWith(n)?o.slice(0,-n.length):o},y=(e,n,t)=>{const o=((e,n,t)=>n&&"/home"===e?"/home":t&&"/root"===e?"/root":$[e])(e,n,t);return o||("/notfound"===e.toLowerCase()||"/404"===e?"/*":e)},j=(e,n)=>e.endsWith(".config."+(n?"ts":"js"))?"index"===P(e,".config."+(n?"ts":"js"))?e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")):e.slice(0,-10)+"."+(n?"tsx":"jsx"):e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")),x=(e,n,t)=>{if(e.endsWith(".config."+(t?"ts":"js"))){const o=P(e,".config."+(t?"ts":"js")),r=(e=>{const n=e.split("/");return n.pop(),n.join("/")})(e).replace(n,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(n,"").replace("/index.config."+(t?"ts":"js"),"")||"/"},C=async(e,n,t,o,r,s)=>{const a=[];for(const[i,c]of((e,n,t)=>Object.keys(e).map(e=>{const o=((e,n)=>e.endsWith(n?".tsx":".jsx")?e.slice(0,-4)+".config."+(n?"ts":"js"):e.replace("index."+(n?"ts":"js"),"index.config."+(n?"ts":"js")))(e,t);return[o,n[o]||{}]}))(e,n,o)){const n=j(i,o);if(!e[n])continue;const u=$e(x(i,`/${t}`,o)||"/",o,"react"),p=y(u,r,s);a.push({...c,path:p,type:c?.type,isRoot:!s&&"/root"===u,element:e[n]})}return a},b=e=>{if(e.index)return e;if("wrap"!==e.type){const{path:n,children:t,...o}=e;if(Object.keys(o).length>0)return{path:n,children:[{path:"",index:!0,...o},...(t||[]).map(b)]}}return e.children?{...e,children:e.children.map(b)}:e},w=e=>(e=>e.map(b))((e=>{const n=/* @__PURE__ */new Map,t=[],o=/* @__PURE__ */new Map,r=e=>{let n=o.get(e);return void 0===n&&(n="/"===e?[]:e.split("/").filter(Boolean),o.set(e,n)),n},s=e.slice().sort((e,n)=>e.path.length-n.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(n.set(e,s),o.length<=1){t.push(s);continue}const i="/"+o.slice(0,-1).join("/"),c=n.get(i);c?(s.path=o[o.length-1],c.children.push(s)):t.push(s)}return t})(e)),M=e=>{const{isRoot:n,type:t,children:o,...r}=e;return o?.length?{...r,children:o.map(M)}:r},O=e=>{const{children:n}=e;if(!n?.length){const{children:n,...t}=e;return t}const t=n.map(O);if("wrap"===e.type)return{...e,children:t};const{path:o,element:r,type:s,children:a,...i}=e;return r?{path:o,children:[{index:!0,element:r,...i},...t]}:{path:o,...i,children:t}},v=e=>M(O(e)),S=e=>w(e).map(v),T=e=>{if(e.some(e=>e.isRoot))return(e=>{let n,t,o;const r=[];for(const i of e)if(i.isRoot){if(n)throw new Error("There cannot be multiple root routes in a route");n=i}else"/"===i.path?t=i:"/*"===i.path?o=i:r.push(i);if(de(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[t&&{...t,index:!0},...S(r)].filter(e=>Boolean(e)),a=[];return n&&a.push(M({...n,children:s})),o&&a.push(M(o)),a})(e);if(de(e,"path"))throw new Error("There cannot be duplicate paths in a route");return S(e)},E=(e,n)=>({import:`import ${e} from './${n}'`,component:`<start><${e} /></end>`,lazy:`const ${e} = lazy(() => import('${n}'))`,lazyComponent:`<start><Suspense><${e} /></Suspense></end>`});var k="index.tsx",N="index.jsx",F=(e,n,t,o,r,s,a)=>{const i=((e,n)=>e.includes(n?k:N)?e.replace(n?k:N,n?xe:Ce):e)(he(e,n),a),c=le(ue(t,e)),u=ie(R(c),s),p=`element(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},W=(e,n,t,o)=>{const r=he(e,n);t[`/${r}`]=c(r,ce(e),o)};function L(e,n,o,r,s,a,i,c,u){const p={},l=e.replace(/^\/+/,""),h=t.sync(l,{cwd:n,absolute:!0,onlyFiles:!0}).filter(ge);for(const t of h)if("component"===s){if(t.includes(".config."))continue;F(t,o,r,p,a,i,u)}else W(t,o,p,c);return p}var B=async(e,n,t,o,r,s,a,i)=>{const c=/* @__PURE__ */new Map,u=/* @__PURE__ */new Set,p=/* @__PURE__ */new Map;je(o,((e,n,t,o)=>{let r=e;for(const[s,a]of n){const e=E(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of t)r=r.replace(s,a);return Re(r)})(function(e,n,t,o){const r=t.length>0?`\n${t.join("\n")}\n`:"";return`// Auto-generated by ono-auto-router\n${o?"import type { RouteObject } from 'react-router'\n":""}${n.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`}(T(await C(L("/**/*.{jsx,tsx}",n,t,o,"component",c,u,p,s),L("/**/*.config.{js,ts,jsx,tsx}",n,t,o,"config",c,u,p,s),e,s,a,i)),((e,n)=>{if(e)return["import { lazy, Suspense } from 'react'"];const t=[];for(const o of n.values())t.push(E(o.componentName,o.path).import);return t})(r,c),((e,n)=>{if(!e)return[];const t=[];for(const o of n.values())t.push(E(o.componentName,o.path).lazy);return t})(r,c),s),c,p,r))},z=(e,t,o,r,s,a)=>{const i=t.split(".")[0],c=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(r),u=o?((e,n,t,o)=>`\n\n${t&&o?"":`const PATH_REPLACEMENTS${n?": Record<string, string>":""} = {\n${t||o?t?"'/root': '/'":"'/home': '/'":" '/home': '/',\n '/root': '/'"}\n}\n\n`}const cachedLazyComponents${n?": Record<\n string,\n LazyExoticComponent<ComponentType<unknown>>\n>":""} = {}\n\nconst getConfigFileName = ${n?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${n?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${n?"ts":"js"}'\n }\n return pagePath.replace('index.${n?"ts":"js"}', 'index.config.${n?"ts":"js"}')\n}\n\nconst formatPageModule = (${n?"\n pagesComponent: Record<string, ComponentType<unknown>>,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${n?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${n?"(pathStr: string): string":"(pathStr)"} => {\n${t&&o?"":" 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 = ${n?"(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 = ${n?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${n?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"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.${n?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${n?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${n?": 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 = ${n?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${n?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${n?"tsx":"jsx"}')) {\n result[key] = pagesComponent[key]\n }\n }\n\n return result\n}\n\nconst LazyComponent = ({\n Element\n}${n?": {\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}/**/*.${n?"tsx":"jsx"}')${n?" as PagesComponentType":""}\n })\n\n const pagesString = getFileDefault({\n ...import.meta.glob('/${e}/**/*.${n?"tsx":"jsx"}', {\n eager: true\n })\n })${n?" as Record<string, ComponentType<unknown>>":""}\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${n?"ts":"js"}', {\n eager: true\n })\n })${n?" as Record<string, PageConfig>":""}\n\n const result${n?`: ${o?"MyRouteObject":"(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${n?": 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 ${o?"":"isRoot: processedPath === '/root',\n "}element: Component\n })\n }\n\n return result\n}`)(e,r,s,a):((e,n,t,o)=>`\n\n${t&&o?"":`const PATH_REPLACEMENTS${n?": Record<string, string>":""} = {\n${t||o?t?"'/root': '/'":"'/home': '/'":" '/home': '/',\n '/root': '/'"}\n}\n\n`}const getConfigFileName = ${n?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${n?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${n?"ts":"js"}'\n }\n return pagePath.replace('index.${n?"ts":"js"}', 'index.config.${n?"ts":"js"}')\n}\n\nconst formatPageModule = (${n?"\n pagesComponent: PagesComponentType,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${n?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${n?"(pathStr: string): string":"(pathStr)"} => {\n${t&&o?"":" 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 = ${n?"(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 = ${n?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${n?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"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.${n?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${n?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${n?": PagesComponentType | Record<string, PageConfig>":""} = {}\n\n for (const [path, module] of Object.entries(modules)) {\n if ('default' in module) {\n result[path] = module.default${n?" as ComponentType<unknown> | PageConfig":""}\n }\n }\n\n return result\n}\n\nconst filterUnComponent = ${n?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${n?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${n?"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}/**/*.${n?"tsx":"jsx"}', { eager: true })\n })${n?" as PagesComponentType":""}\n )\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${n?"ts":"js"}', {\n eager: true\n })\n })${n?" as Record<string, PageConfig>":""}\n\n const result${n?`: ${o?"MyRouteObject":"(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 ${o?"":"isRoot: processedPath === '/root',\n "}element: Component\n })\n }\n\n return result\n}`)(e,r,s,a),p=((e,n)=>`\nconst processRoute = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} =>\n ${n?"removeEmptyChildren(route)":"cleanIsRoot(removeEmptyChildren(route))"}\n\nconst processRoutes = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} =>\n buildRouteTree(routes).map(processRoute)\n\n${n?"":`const 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\n`}const formatRoutes = (\n routes${e?`: ${n?"MyRouteObject":"(MyRouteObject & { isRoot?: boolean })"}[]`:""}\n) => {\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}`)(r,a),l=(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}`)(r),h=a?"":(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}`)(r),f=(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}`)(r),g=r?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",d=(e=>`\nconst getRoutes = () => {\n const baseRoutes = createBaseRoutes()\n const formattedRoutes = formatRoutes(baseRoutes)${e?" as RouteObject[]":""}\n return formattedRoutes\n}\n\nexport const routes = getRoutes()`)(r),m=((e,n,t,o,r,s,a,i)=>`// Auto-generated by ono-auto-router${e}${n}${t}${o}${r}${s}${a}${i}\n`)(((e,n,t)=>e?`\n${n?"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${n?"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\n${t?"":"type RouteWithIsRoot = MyRouteObject & { isRoot?: boolean }\n\n"}export type PageConfig = Partial<\n Omit<MyRouteObject, 'Component' | 'element' | 'children' | 'path'>\n>`:n?"\nimport { lazy, Suspense } from 'react'\n":"")(r,o,a),(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}`)(r),f,h,l,p,u,d);r?(je(n.resolve(i,"./index.ts"),c),je(n.resolve(i,"./autoRouter.tsx"),m),je(n.resolve(i,"./defineConfig.ts"),g)):je(t,m)},A={"/home":"/","/root":"/"},I=(e,n)=>{const t=e.split("/"),o=t[t.length-1];return n&&o.endsWith(n)?o.slice(0,-n.length):o},D=(e,n,t)=>{const o=((e,n,t)=>n&&"/home"===e?"/home":t&&"/root"===e?"/root":A[e])(e,n,t);return o||("/notfound"===e.toLowerCase()||"/404"===e?"/:pathMatch(.*)*":e)},K=(e,n)=>e.endsWith(".config."+(n?"ts":"js"))?"index"===I(e,".config."+(n?"ts":"js"))?e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")):e.slice(0,-10)+".vue":e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")),_=(e,n,t)=>{if(e.endsWith(".config."+(t?"ts":"js"))){const o=I(e,".config."+(t?"ts":"js")),r=(e=>{const n=e.split("/");return n.pop(),n.join("/")})(e).replace(n,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(n,"").replace("/index.config."+(t?"ts":"js"),"")||"/"},H=async(e,n,t,o,r,s)=>{const a=[];for(const[i,c]of((e,n,t)=>Object.keys(e).map(e=>{const o=((e,n)=>e.replace("index."+(n?"ts":"js"),"index.config."+(n?"ts":"js")))(e,t);return[o,n[o]||{}]}))(e,n,o)){const n=K(i,o),u=$e(_(i,`/${t}`,o)||"/",o,"vue"),p=D(u,r,s);a.push({...c,path:p,type:c?.type,isRoot:!s&&"/root"===u,component:e[n]})}return a},V=e=>{if(!e.path)return e;if("wrap"!==e.type){const{path:n,children:t,...o}=e;if(Object.keys(o).length>0)return{path:n,children:[{path:"",...o},...(t||[]).map(V)]}}return e.children?{...e,children:e.children.map(V)}:e},U=e=>(e=>e.map(V))((e=>{const n=/* @__PURE__ */new Map,t=[],o=/* @__PURE__ */new Map,r=e=>{let n=o.get(e);return void 0===n&&(n="/"===e?[]:e.split("/").filter(Boolean),o.set(e,n)),n},s=e.slice().sort((e,n)=>e.path.length-n.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(n.set(e,s),o.length<=1){t.push(s);continue}const i="/"+o.slice(0,-1).join("/"),c=n.get(i);c?(s.path=o[o.length-1],c.children.push(s)):t.push(s)}return t})(e)),J=e=>{const{isRoot:n,type:t,children:o,...r}=e;return o?.length?{...r,children:o.map(J)}:r},Z=e=>{const{children:n}=e;if(!n?.length){const{children:n,...t}=e;return t}const t=n.map(Z);if("wrap"===e.type)return{...e,children:t};const{path:o,component:r,type:s,children:a,...i}=e;return r?{path:o,children:[{path:"",component:r,...i},...t]}:{path:o,...i,children:t}},q=e=>J(Z(e)),G=e=>U(e).map(q),Q=e=>{if(e.some(e=>e.isRoot))return(e=>{let n,t,o;const r=[];for(const i of e)if(i.isRoot){if(n)throw new Error("There cannot be multiple root routes in a route");n=i}else"/"===i.path?t=i:"/:pathMatch(.*)*"===i.path?o=i:r.push(i);if(de(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[t,...G(r)].filter(e=>Boolean(e)),a=[];return n&&a.push(J({...n,children:s})),o&&a.push(J(o)),a})(e);if(de(e,"path"))throw new Error("There cannot be duplicate paths in a route");return G(e)},X=(e,n)=>({import:`import ${e} from './${n}'`,component:`<start>${e}</end>`,lazyComponent:`<start>() => import('${n}')</end>`});var Y=(e,n,t,o,r,s,a)=>{const i=((e,n)=>e.replace("index.vue",n?xe:Ce))(he(e,n),a),c=le(ue(t,e)),u=ie(R(c),s),p=`component(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},ee=(e,n,t,o)=>{const r=he(e,n);t[`/${r}`]=c(r,ce(e),o)};function ne(e,n,o,r,s,a,i,c,u){const p={},l=e.replace(/^\/+/,""),h=t.sync(l,{cwd:n,absolute:!0,onlyFiles:!0}),f="component"===s?((e,n)=>n.map(n=>n.includes("index.vue")||2===n.replace(e.replaceAll("\\","/"),"").split("/").length?n:void 0).filter(Boolean))(n,h):h.filter(ge);for(const t of f)if("component"===s){if(t.includes(".config."))continue;Y(t,o,r,p,a,i,u)}else ee(t,o,p,c);return p}var te=async(e,n,t,o,r,s,a,i)=>{const c=/* @__PURE__ */new Map,u=/* @__PURE__ */new Set,p=/* @__PURE__ */new Map;je(o,((e,n,t,o)=>{let r=e;for(const[s,a]of n){const e=X(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of t)r=r.replace(s,a);return Re(r)})(function(e,n,t,o){return`// Auto-generated by ono-auto-router${t?"\nimport type { RouteRecordRaw } from 'vue-router'":""}${o?"":`\n${n.join("\n")}${t?"":"\n"}`}${t?"\n\ntype PageConfig = Partial<\n Omit<RouteRecordRaw, 'path' | 'component' | 'children'> & {\n type?: 'single' | 'wrap'\n }\n>\n":""}${t?"\nexport const defineConfig = (config: PageConfig) => config\n":""}\nexport const routes${t?": RouteRecordRaw[]":""} = ${JSON.stringify(e,null,2)}\n`}(Q(await H(ne("/**/*.vue",n,t,o,"component",c,u,p,s),ne("/**/*.config.{js,ts}",n,t,o,"config",c,u,p,s),e,s,a,i)),((e,n)=>{if(e)return[];const t=[];for(const o of n.values())t.push(X(o.componentName,o.path).import);return t})(r,c),s,r),c,p,r))},oe=(e,t,o,r,s,a)=>{const i=t.split(".")[0],c=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(r),u=((e,n,t,o,r)=>`\nconst pathCache = new Map${n?"<string, { compPath: string; basePath: string }>":""}()\nconst basenameCache = new Map${n?"<string, string>":""}()\n\nconst normalizePagePath = ${n?"(key: string): string":"(key)"} => {\n if (key.includes('index.vue')) return key.replace('index.vue', 'index.${n?"ts":"js"}')\n if (key.includes('root.vue')) return key.replace('root.vue', 'root/index.${n?"ts":"js"}')\n if (key.includes('404.vue')) return key.replace('404.vue', '404/index.${n?"ts":"js"}')\n if (key.toLowerCase().includes('notfound.vue'))\n return key.toLowerCase().replace('notfound.vue', 'notfound/index.${n?"ts":"js"}')\n return key\n}\n\nconst getBasename = ${n?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const cacheKey = ext ? filePath + ':' + ext : filePath\n if (basenameCache.has(cacheKey)) {\n return basenameCache.get(cacheKey)${n?"!":""}\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 = ${n?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getPathsFromConfig = ${n?"(configPath: string)":"(configPath)"} => {\n const cacheKey = configPath\n if (pathCache.has(cacheKey)) {\n return pathCache.get(cacheKey)${n?"!":""}\n }\n\n let compPath${n?": string":" = ''"}\n let basePath${n?": string":" = ''"}\n\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n\n if (fileName === 'index') {\n compPath = configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"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.${n?"ts":"js"}', 'index.${n?"ts":"js"}')\n basePath =\n configPath.replace('/${e}', '').replace('/index.config.${n?"ts":"js"}', '') ||\n '/'\n }\n\n const result = { compPath, basePath }\n pathCache.set(cacheKey, result)\n return result\n}\n\nconst formatPath = ${n?"(path: string): string":"(path)"} => {\n const lowerPath = path.toLowerCase()\n ${o?"":"if (lowerPath === '/home') return '/'\n "}if (lowerPath === '/notfound' || path === '/404') return '/:pathMatch(.*)*'\n return path.replace('/index.${n?"ts":"js"}', '') || '/'\n}\n\nconst getConfigFileName = ${n?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.vue')) {\n return pagePath.slice(0, -4) + '.config.${n?"ts":"js"}'\n }\n return pagePath.replace('index.${n?"ts":"js"}', 'index.config.${n?"ts":"js"}')\n}\n\nconst createBaseRoutes = ()${n?": MyRouteObject[]":""} => {\n const pagesComponent = Object.fromEntries(\n Object.entries({\n ...import.meta.glob('/${e}/**/index.vue'${t?"":", { eager: true, import: 'default' }"}),\n ...import.meta.glob('/${e}/*.vue'${t?"":", { eager: true, import: 'default' }"})\n }${n?" as PagesComponentType":""}).map(([key, value]) => [\n normalizePagePath(key),\n value\n ])\n )\n\n const pagesModule${n?": Record<string, PageConfig>":""} = import.meta.glob(\n '/${e}/**/*.config.${n?"ts":"js"}',\n { eager: true, import: 'default' }\n )\n\n const result${n?`: ${r?"MyRouteObject":"(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 ${r?"":"isRoot: path === '/root',\n "}...content${n?"!":""}\n })\n }\n\n return result\n}\n\nconst processRoutes = ${n?"(\n routes: MyRouteObject[],\n removeLeadingSlash = false\n): MyRouteObject[]":"(routes, removeLeadingSlash)"} =>\n ${r?"buildRouteTree(routes, removeLeadingSlash)\n .map(removeEmptyChildren)":"buildRouteTree(routes, removeLeadingSlash)\n .map(removeEmptyChildren)\n .map(cleanIsRoot)"}\n\n${r?"":`const handleRootRoute = ${n?"(\n routes: (MyRouteObject & { isRoot?: boolean })[]\n): MyRouteObject[]":"(routes)"} => {\n let rootRoute${n?": (MyRouteObject & { isRoot?: boolean }) | undefined":" = undefined"}\n let homeRoute${n?": MyRouteObject | undefined":" = undefined"}\n let notFoundRoute${n?": MyRouteObject | undefined":" = undefined"}\n const filteredRoutes${n?": (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${n?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n if (rootRoute) {\n const children = [\n homeRoute && { ...homeRoute, path: '' },\n ...processRoutes(filteredRoutes, true)\n ].filter(Boolean)${n?" as MyRouteObject[]":""}\n processedRoutes.push({ ...rootRoute, path: '/', children })\n }\n\n if (notFoundRoute) processedRoutes.push(notFoundRoute)\n\n return ${r?"processedRoutes":"processedRoutes.map(cleanIsRoot)"}\n}\n\n`}const createRoutes = ()${n?": RouteRecordRaw[]":""} => {\n const routes = createBaseRoutes()\n\n ${r?"":`if (routes.some((r${n?": MyRouteObject & { isRoot?: boolean }":""}) => r.isRoot))\n return handleRootRoute(routes)${n?" 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)${n?" as RouteRecordRaw[]":""}\n}\n`)(e,r,o,s,a),p=((e,n)=>`\nconst buildRouteTree = ${e?"(\n routes: MyRouteObject[],\n removeLeadingSlash: boolean = false\n)":"(routes, removeLeadingSlash)"} => {\n const routeMap = new Map${e?`<string, ${n?"MyRouteObject":"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 ${n?"rootRoutes.push(route)":"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 ${n?"rootRoutes.push(route)":"const { isRoot, ...rest } = route\n rootRoutes.push(rest)"}\n }\n }\n\n return rootRoutes\n}\n`)(r,a),l=a?"":(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`)(r),h=(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`)(r),f=r?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",g=((e,n,t,o,r,s,a)=>`// Auto-generated by ono-auto-router${e}${n}${t}${o}${r}${s}${a}\n`)(r?"\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`)(r),h,l,p,u,"\nexport const routes = createRoutes()");r?(je(n.resolve(i,"./index.ts"),c),je(n.resolve(i,"./autoRouter.ts"),g),je(n.resolve(i,"./defineConfig.ts"),f)):je(t,g)},re={react:{hmr:(e,n,t,o,r,s,a,i)=>z(e,o,r,s,a,i),normal:B},vue:{hmr:(e,n,t,o,r,s,a,i)=>oe(e,o,r,s,a,i),normal:te}},se=[".js",".ts",".jsx",".tsx"],ae=(t,o,r,s,c,u,l,f)=>{const g=n.resolve(r,o);if(!e.existsSync(g))throw new Error(`Pages directory not found: ${g}`);const d=h(t,r,s);(e=>{for(const n of se)a(e+n);i(e)})(d.split(".")[0]),re[t][f?"hmr":"normal"](o,g,r,d,l,p(r),c,u),console.log(`[ono-auto-router] Routes file generated: ${f?n.resolve(d.replace(".tsx","").replace(".ts",""),"./autoRouter"+("react"===t?".tsx":".ts")):d}`)},ie=(e,n)=>{if(!n.has(e))return n.add(e),e;let t=1;for(;n.has(`${e}_${t}`);)t++;return`${e}_${t}`};function ce(n){try{const o=e.readFileSync(n,"utf-8").match(/export\s+default\s+([\s\S]*?)(?=\n\w|$)/);if(!o)return console.warn("No export default found in:",n),null;const r=o[1].trim();try{if(r.startsWith("{"))return new Function(`return ${r}`)();if(r.includes("defineConfig(")){const e=r.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(o){return console.error("Error reading file:",o),null}}function ue(e,t){let o=n.resolve(e);(o.endsWith(".js")||o.endsWith(".jsx")||o.endsWith(".ts")||o.endsWith(".tsx")||o.endsWith(".vue"))&&(o=n.dirname(o));const r=n.resolve(t);return n.relative(o,r)}var pe=/\\/g,le=e=>e.replace(pe,"/"),he=(e,t)=>le(n.relative(t,e)),fe=/export\s+default\s+[\w(\[\]\{\})]+/;function ge(n){try{if(!e.existsSync(n))return console.warn(`File not found: ${n}`),!1;const t=e.readFileSync(n,"utf-8");return fe.test(t)}catch(t){return console.error("Read error:",t),!1}}var de=(e,n)=>{const t=/* @__PURE__ */new Set;return e.some(e=>!!t.has(e[n])||(t.add(e[n]),!1))};function me(e){return e.replace(/"<start>([\s\S]*?)<\/end>"/g,"$1")}function Re(e){let n=e;for(;;){const e=me(n);if(e===n)break;n=e}return n}var $e=(e,n,t)=>e.replace(/\[([^\]]+)\]/g,":$1").replace("react"===t?n?".tsx":".jsx":".vue","");function Pe(n){e.existsSync(n)||e.mkdirSync(n,{recursive:!0})}function ye(t,o){Pe(n.dirname(t)),e.writeFileSync(t,o,"utf-8")}async function je(t,o){const r=n.dirname(t);await e.promises.mkdir(r,{recursive:!0}),await e.promises.writeFile(t,o,"utf-8")}var xe="index.ts",Ce="index.js";export{p as C,a as D,i as E,o as O,h as S,c as T,te as _,ye as a,m as b,de as c,le as d,ue as f,oe as g,ae as h,je as i,ge as l,ie as m,xe as n,$e as o,ce as p,Pe as r,Re as s,Ce as t,he as u,z as v,u as w,R as x,B as y};
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-B67wyGzH.js");exports.generateReactRoutesHMR=e.generateReactRoutesHMR;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-C52uO5Pr.js");exports.generateReactRoutesHMR=e.generateReactRoutesHMR;
@@ -1,3 +1,3 @@
1
- export declare const generateReactRoutesHMR: (pagesDir: string, routesPath: string, lazy: boolean, useTs: boolean) => void;
1
+ export declare const generateReactRoutesHMR: (pagesDir: string, routesPath: string, lazy: boolean, useTs: boolean, keepHome: boolean, keepRoot: boolean) => void;
2
2
 
3
3
  export { }
@@ -1 +1 @@
1
- import{v as o}from"./core-C8iisJJt.js";export{o as generateReactRoutesHMR};
1
+ import{v as o}from"./core-CU6bBT1B.js";export{o as generateReactRoutesHMR};
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-B67wyGzH.js");exports.generateReactRoutes=e.generateReactRoutes;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-C52uO5Pr.js");exports.generateReactRoutes=e.generateReactRoutes;
@@ -1,3 +1,3 @@
1
- export declare const generateReactRoutes: (pagesDir: string, resolvedPagesDir: string, projectRoot: string, routesDir: string, lazy: boolean, useTs: boolean) => Promise<void>;
1
+ export declare const generateReactRoutes: (pagesDir: string, resolvedPagesDir: string, projectRoot: string, routesDir: string, lazy: boolean, useTs: boolean, keepHome: boolean, keepRoot: boolean) => Promise<void>;
2
2
 
3
3
  export { }
@@ -1 +1 @@
1
- import{y as o}from"./core-C8iisJJt.js";export{o as generateReactRoutes};
1
+ import{y as o}from"./core-CU6bBT1B.js";export{o as generateReactRoutes};
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-B67wyGzH.js");exports.generateVueRoutesHMR=e.generateVueRoutesHMR;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-C52uO5Pr.js");exports.generateVueRoutesHMR=e.generateVueRoutesHMR;
@@ -1,3 +1,3 @@
1
- export declare const generateVueRoutesHMR: (pagesDir: string, routesPath: string, useTs: boolean, lazy: boolean) => void;
1
+ export declare const generateVueRoutesHMR: (pagesDir: string, routesPath: string, lazy: boolean, useTs: boolean, keepHome: boolean, keepRoot: boolean) => void;
2
2
 
3
3
  export { }
@@ -1 +1 @@
1
- import{g as o}from"./core-C8iisJJt.js";export{o as generateVueRoutesHMR};
1
+ import{g as o}from"./core-CU6bBT1B.js";export{o as generateVueRoutesHMR};
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-B67wyGzH.js");exports.generateVueRoutes=e.generateVueRoutes;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-C52uO5Pr.js");exports.generateVueRoutes=e.generateVueRoutes;
@@ -1,3 +1,3 @@
1
- export declare const generateVueRoutes: (pagesDir: string, resolvedPagesDir: string, projectRoot: string, routesDir: string, lazy: boolean, useTs: boolean) => Promise<void>;
1
+ export declare const generateVueRoutes: (pagesDir: string, resolvedPagesDir: string, projectRoot: string, routesDir: string, lazy: boolean, useTs: boolean, keepHome: boolean, keepRoot: boolean) => Promise<void>;
2
2
 
3
3
  export { }
@@ -1 +1 @@
1
- import{_ as o}from"./core-C8iisJJt.js";export{o as generateVueRoutes};
1
+ import{_ as o}from"./core-CU6bBT1B.js";export{o as generateVueRoutes};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core-B67wyGzH.js");exports.default=function(o){const{framework:r="react",pagesDir:t="./src/pages",routesFile:a,lazy:s=!0,hmr:u=!1}=o||{};let l,n;return{name:"ono-vite-plugin-auto-router",configResolved:o=>{l=o,n=l.root,e.generateRoutesTemplate(r,e.formatPagesDir(t),n,a,s,u)}}};
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core-C52uO5Pr.js");exports.default=function(o){const{framework:r="react",pagesDir:t="./src/pages",routesFile:a,keepHome:s=!1,keepRoot:u=!1,lazy:l=!0,hmr:n=!1}=o||{};let i,p;return{name:"ono-vite-plugin-auto-router",configResolved:o=>{i=o,p=i.root,e.generateRoutesTemplate(r,e.formatPagesDir(t),p,a,s,u,l,n)}}};
package/dist/index.d.ts CHANGED
@@ -10,6 +10,8 @@ export declare interface OnoVitePluginOptions {
10
10
  framework?: 'react' | 'vue';
11
11
  pagesDir?: string;
12
12
  routesFile?: string;
13
+ keepHome?: boolean;
14
+ keepRoot?: boolean;
13
15
  lazy?: boolean;
14
16
  hmr?: boolean;
15
17
  }
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{h as e,w as o}from"./core-C8iisJJt.js";function r(r){const{framework:t="react",pagesDir:a="./src/pages",routesFile:s,lazy:n=!0,hmr:i=!1}=r||{};let u,c;return{name:"ono-vite-plugin-auto-router",configResolved:r=>{u=r,c=u.root,e(t,o(a),c,s,n,i)}}}export{r as default};
1
+ import{h as e,w as o}from"./core-CU6bBT1B.js";function r(r){const{framework:t="react",pagesDir:a="./src/pages",routesFile:s,keepHome:n=!1,keepRoot:i=!1,lazy:p=!0,hmr:u=!1}=r||{};let c,l;return{name:"ono-vite-plugin-auto-router",configResolved:r=>{c=r,l=c.root,e(t,o(a),l,s,n,i,p,u)}}}export{r as default};
package/dist/react.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core-B67wyGzH.js");exports.default=function(t){const{pagesDir:o="./src/pages",routesFile:r,lazy:a=!0,hmr:s=!1}=t||{};let n,u;return{name:"ono-vite-plugin-auto-router-react",configResolved:async t=>{n=t,u=n.root,e.generateRoutesTemplate("react",e.formatPagesDir(o),u,r,a,s)}}};
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core-C52uO5Pr.js");exports.default=function(o){const{pagesDir:t="./src/pages",routesFile:r,keepHome:a=!1,keepRoot:s=!1,lazy:n=!0,hmr:u=!1}=o||{};let l,i;return{name:"ono-vite-plugin-auto-router-react",configResolved:async o=>{l=o,i=l.root,e.generateRoutesTemplate("react",e.formatPagesDir(t),i,r,a,s,n,u)}}};
package/dist/react.d.ts CHANGED
@@ -9,6 +9,8 @@ export default onoVitePluginAutoRoutesReact;
9
9
  export declare interface OnoVitePluginOptions {
10
10
  pagesDir?: string;
11
11
  routesFile?: string;
12
+ keepHome?: boolean;
13
+ keepRoot?: boolean;
12
14
  lazy?: boolean;
13
15
  hmr?: boolean;
14
16
  }
package/dist/react.js CHANGED
@@ -1 +1 @@
1
- import{h as e,w as o}from"./core-C8iisJJt.js";function r(r){const{pagesDir:t="./src/pages",routesFile:a,lazy:s=!0,hmr:n=!1}=r||{};let c,i;return{name:"ono-vite-plugin-auto-router-react",configResolved:async r=>{c=r,i=c.root,e("react",o(t),i,a,s,n)}}}export{r as default};
1
+ import{h as e,w as o}from"./core-CU6bBT1B.js";function r(r){const{pagesDir:t="./src/pages",routesFile:a,keepHome:s=!1,keepRoot:n=!1,lazy:c=!0,hmr:i=!1}=r||{};let p,u;return{name:"ono-vite-plugin-auto-router-react",configResolved:async r=>{p=r,u=p.root,e("react",o(t),u,a,s,n,c,i)}}}export{r as default};
package/dist/utils.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-B67wyGzH.js");exports.INDEX_JS_SUFFIX=e.INDEX_JS_SUFFIX,exports.INDEX_TS_SUFFIX=e.INDEX_TS_SUFFIX,exports.capitalize=e.capitalize,exports.convertFunctionToArrow=e.convertFunctionToArrow,exports.deleteDir=e.deleteDir,exports.deleteFile=e.deleteFile,exports.ensureDirSync=e.ensureDirSync,exports.formatFunction=e.formatFunction,exports.formatPagesDir=e.formatPagesDir,exports.formatRoutesFile=e.formatRoutesFile,exports.generateComponentName=e.generateComponentName,exports.generateRoutesTemplate=e.generateRoutesTemplate,exports.generateUniqueComponentName=e.generateUniqueComponentName,exports.getDefaultExportContent=e.getDefaultExportContent,exports.getRelativePath=e.getRelativePath,exports.getRelativeProjectPath=e.getRelativeProjectPath,exports.hasDefaultExport=e.hasDefaultExport,exports.hasDuplicateProperty=e.hasDuplicateProperty,exports.normalizePathWithWindows=e.normalizePathWithWindows,exports.removeCustomTagFunctionFromJSXAll=e.removeCustomTagFunctionFromJSXAll,exports.replaceBracketsWithColon=e.replaceBracketsWithColon,exports.useTs=e.useTs,exports.writeFile=e.writeFile,exports.writeFileSync=e.writeFileSync;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-C52uO5Pr.js");exports.INDEX_JS_SUFFIX=e.INDEX_JS_SUFFIX,exports.INDEX_TS_SUFFIX=e.INDEX_TS_SUFFIX,exports.capitalize=e.capitalize,exports.convertFunctionToArrow=e.convertFunctionToArrow,exports.deleteDir=e.deleteDir,exports.deleteFile=e.deleteFile,exports.ensureDirSync=e.ensureDirSync,exports.formatFunction=e.formatFunction,exports.formatPagesDir=e.formatPagesDir,exports.formatRoutesFile=e.formatRoutesFile,exports.generateComponentName=e.generateComponentName,exports.generateRoutesTemplate=e.generateRoutesTemplate,exports.generateUniqueComponentName=e.generateUniqueComponentName,exports.getDefaultExportContent=e.getDefaultExportContent,exports.getRelativePath=e.getRelativePath,exports.getRelativeProjectPath=e.getRelativeProjectPath,exports.hasDefaultExport=e.hasDefaultExport,exports.hasDuplicateProperty=e.hasDuplicateProperty,exports.normalizePathWithWindows=e.normalizePathWithWindows,exports.removeCustomTagFunctionFromJSXAll=e.removeCustomTagFunctionFromJSXAll,exports.replaceBracketsWithColon=e.replaceBracketsWithColon,exports.useTs=e.useTs,exports.writeFile=e.writeFile,exports.writeFileSync=e.writeFileSync;
package/dist/utils.d.ts CHANGED
@@ -16,7 +16,7 @@ export declare const formatRoutesFile: (framework: "react" | "vue", projectRoot:
16
16
 
17
17
  export declare function generateComponentName(filePath: string): string;
18
18
 
19
- export declare const generateRoutesTemplate: (framework: "react" | "vue", pagesDir: string, projectRoot: string, routesFile: string | undefined, lazy: boolean, hmr: boolean) => void;
19
+ export declare const generateRoutesTemplate: (framework: "react" | "vue", pagesDir: string, projectRoot: string, routesFile: string | undefined, keepHome: boolean, keepRoot: boolean, lazy: boolean, hmr: boolean) => void;
20
20
 
21
21
  export declare const generateUniqueComponentName: (baseName: string, componentNames: Set<string>) => string;
22
22
 
package/dist/utils.js CHANGED
@@ -1 +1 @@
1
- import{C as s,D as a,E as o,O as r,S as m,T as p,a as t,b as c,c as e,d as f,f as i,h as x,i as b,l as d,m as h,n as j,o as l,p as n,r as u,s as w,t as C,u as D,w as E,x as O}from"./core-C8iisJJt.js";export{C as INDEX_JS_SUFFIX,j as INDEX_TS_SUFFIX,c as capitalize,r as convertFunctionToArrow,o as deleteDir,a as deleteFile,u as ensureDirSync,p as formatFunction,E as formatPagesDir,m as formatRoutesFile,O as generateComponentName,x as generateRoutesTemplate,h as generateUniqueComponentName,n as getDefaultExportContent,i as getRelativePath,D as getRelativeProjectPath,d as hasDefaultExport,e as hasDuplicateProperty,f as normalizePathWithWindows,w as removeCustomTagFunctionFromJSXAll,l as replaceBracketsWithColon,s as useTs,b as writeFile,t as writeFileSync};
1
+ import{C as s,D as a,E as o,O as r,S as m,T as p,a as t,b as c,c as e,d as f,f as i,h as x,i as b,l as d,m as h,n as j,o as l,p as n,r as u,s as w,t as C,u as D,w as E,x as O}from"./core-CU6bBT1B.js";export{C as INDEX_JS_SUFFIX,j as INDEX_TS_SUFFIX,c as capitalize,r as convertFunctionToArrow,o as deleteDir,a as deleteFile,u as ensureDirSync,p as formatFunction,E as formatPagesDir,m as formatRoutesFile,O as generateComponentName,x as generateRoutesTemplate,h as generateUniqueComponentName,n as getDefaultExportContent,i as getRelativePath,D as getRelativeProjectPath,d as hasDefaultExport,e as hasDuplicateProperty,f as normalizePathWithWindows,w as removeCustomTagFunctionFromJSXAll,l as replaceBracketsWithColon,s as useTs,b as writeFile,t as writeFileSync};
package/dist/vue.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core-B67wyGzH.js");exports.default=function(o){const{pagesDir:t="./src/pages",routesFile:r,lazy:s=!0,hmr:u=!1}=o||{};let a,n;return{name:"ono-vite-plugin-auto-router-vue",configResolved:async o=>{a=o,n=a.root,e.generateRoutesTemplate("vue",e.formatPagesDir(t),n,r,s,u)}}};
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core-C52uO5Pr.js");exports.default=function(o){const{pagesDir:t="./src/pages",routesFile:r,keepHome:s=!1,keepRoot:u=!1,lazy:a=!0,hmr:n=!1}=o||{};let l,i;return{name:"ono-vite-plugin-auto-router-vue",configResolved:async o=>{l=o,i=l.root,e.generateRoutesTemplate("vue",e.formatPagesDir(t),i,r,s,u,a,n)}}};
package/dist/vue.d.ts CHANGED
@@ -9,6 +9,8 @@ export default onoVitePluginAutoRoutesVue;
9
9
  export declare interface OnoVitePluginOptions {
10
10
  pagesDir?: string;
11
11
  routesFile?: string;
12
+ keepHome?: boolean;
13
+ keepRoot?: boolean;
12
14
  lazy?: boolean;
13
15
  hmr?: boolean;
14
16
  }
package/dist/vue.js CHANGED
@@ -1 +1 @@
1
- import{h as e,w as o}from"./core-C8iisJJt.js";function r(r){const{pagesDir:t="./src/pages",routesFile:s,lazy:a=!0,hmr:n=!1}=r||{};let u,i;return{name:"ono-vite-plugin-auto-router-vue",configResolved:async r=>{u=r,i=u.root,e("vue",o(t),i,s,a,n)}}}export{r as default};
1
+ import{h as e,w as o}from"./core-CU6bBT1B.js";function r(r){const{pagesDir:t="./src/pages",routesFile:s,keepHome:a=!1,keepRoot:n=!1,lazy:u=!0,hmr:i=!1}=r||{};let p,c;return{name:"ono-vite-plugin-auto-router-vue",configResolved:async r=>{p=r,c=p.root,e("vue",o(t),c,s,a,n,u,i)}}}export{r as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onoxm/vite-plugin-auto-router",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "a vite plugin for automatically generating react or vue route files",
5
5
  "keywords": [
6
6
  "auto-router",
@@ -1 +0,0 @@
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}});
@@ -1 +0,0 @@
1
- import e from"node:fs";import n from"node:path";import t from"fast-glob";function o(e){let n=r(e,0),t=!1;if(n+5<=e.length&&"async"===e.slice(n,n+5).toLowerCase()&&(t=!0,n=r(e,n+5)),n<e.length&&"("===e[n]){const t=s(e,n);if(-1!==t){let n=r(e,t+1);if(n+1<e.length&&"="===e[n]&&">"===e[n+1])return e}}const o=e.indexOf("(");if(-1===o)return e;const a=s(e,o);if(-1===a)return e;return(t?"async ":"")+e.slice(o,a+1)+" => "+e.slice(a+1)}function r(e,n){for(;n<e.length&&/\s/.test(e[n]);)n++;return n}function s(e,n){let t=0,o=!1,r="";for(let s=n;s<e.length;s++){const n=e[s];if('"'!==n&&"'"!==n&&"`"!==n){if(!o)if("("===n)t++;else if(")"===n&&(t--,0===t))return s}else o?n===r&&(o=!1):(o=!0,r=n)}return-1}var a=n=>{try{if(!e.existsSync(n))return;e.unlinkSync(n)}catch(t){console.error("删除文件失败:",t)}},i=n=>{try{if(!e.existsSync(n))return;e.rmSync(n,{recursive:!0})}catch(t){console.error("删除目录失败:",t)}},c=(e,n,t)=>{const r={};for(const[s,a]of Object.entries(n))if("function"==typeof a){const n=`${e}-${s}`;r[s]=n,t.set(n,`<start>${o(a.toString())}</end>`)}else r[s]=a;return r},u=e=>e.startsWith("/")?e.slice(1):e.endsWith("/")?e.slice(0,-1):e.startsWith("./")?e.slice(2):e,p=t=>e.existsSync(n.resolve(t,"tsconfig.json")),l={react:{ts:"src/router/autoRouter.tsx",js:"src/router/autoRouter.jsx"},vue:{ts:"src/router/autoRouter.ts",js:"src/router/autoRouter.js"}},h=(e,t,o)=>{let r=o;return r=r?n.resolve(t,r):n.resolve(t,l[e][p(t)?"ts":"js"]),r},f=/[/\\]/,g=/[^a-zA-Z0-9]/g,d=/^(\d)/,m=e=>e?e.charAt(0).toUpperCase()+e.slice(1).toLowerCase():"";function R(e){const t=n.extname(e),o=n.basename(e,t),r=n.dirname(e).split(f).filter(Boolean);return"index"!==o&&"Index"!==o&&r.push(o),r.map(e=>(e=>e.replace(g,"_").replace(d,"_$1"))(e).split("_").map(m).join("")).join("")||"Component"}var P={"/home":"/","/root":"/"},y=(e,n)=>{const t=e.split("/"),o=t[t.length-1];return n&&o.endsWith(n)?o.slice(0,-n.length):o},$=e=>{const n=P[e];return n||("/notfound"===e.toLowerCase()||"/404"===e?"/*":e)},x=(e,n)=>e.endsWith(".config."+(n?"ts":"js"))?"index"===y(e,".config."+(n?"ts":"js"))?e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")):e.slice(0,-10)+"."+(n?"tsx":"jsx"):e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")),j=(e,n,t)=>{if(e.endsWith(".config."+(t?"ts":"js"))){const o=y(e,".config."+(t?"ts":"js")),r=(e=>{const n=e.split("/");return n.pop(),n.join("/")})(e).replace(n,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(n,"").replace("/index.config."+(t?"ts":"js"),"")||"/"},C=async(e,n,t,o)=>{const r=[];for(const[s,a]of((e,n,t)=>Object.keys(e).map(e=>{const o=((e,n)=>e.endsWith(n?".tsx":".jsx")?e.slice(0,-4)+".config."+(n?"ts":"js"):e.replace("index."+(n?"ts":"js"),"index.config."+(n?"ts":"js")))(e,t);return[o,n[o]||{}]}))(e,n,o)){const n=x(s,o);if(!e[n])continue;const i=me(j(s,`/${t}`,o)||"/",o,"react"),c=$(i);r.push({...a,path:c,type:a?.type,isRoot:"/root"===i,element:e[n]})}return r},b=e=>{if(e.index)return e;if("wrap"!==e.type){const{path:n,children:t,...o}=e;if(Object.keys(o).length>0)return{path:n,children:[{path:"",index:!0,...o},...(t||[]).map(b)]}}return e.children?{...e,children:e.children.map(b)}:e},w=e=>(e=>e.map(b))((e=>{const n=/* @__PURE__ */new Map,t=[],o=/* @__PURE__ */new Map,r=e=>{let n=o.get(e);return void 0===n&&(n="/"===e?[]:e.split("/").filter(Boolean),o.set(e,n)),n},s=e.slice().sort((e,n)=>e.path.length-n.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(n.set(e,s),o.length<=1){t.push(s);continue}const i="/"+o.slice(0,-1).join("/"),c=n.get(i);c?(s.path=o[o.length-1],c.children.push(s)):t.push(s)}return t})(e)),M=e=>{const{isRoot:n,type:t,children:o,...r}=e;return o?.length?{...r,children:o.map(M)}:r},O=e=>{const{children:n}=e;if(!n?.length){const{children:n,...t}=e;return t}const t=n.map(O);if("wrap"===e.type)return{...e,children:t};const{path:o,element:r,type:s,children:a,...i}=e;return r?{path:o,children:[{index:!0,element:r,...i},...t]}:{path:o,...i,children:t}},v=e=>M(O(e)),S=e=>w(e).map(v),T=e=>{if(e.some(e=>e.isRoot))return(e=>{let n,t,o;const r=[];for(const i of e)if(i.isRoot){if(n)throw new Error("There cannot be multiple root routes in a route");n=i}else"/"===i.path?t=i:"/*"===i.path?o=i:r.push(i);if(fe(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[t&&{...t,index:!0},...S(r)].filter(e=>Boolean(e)),a=[];return n&&a.push(M({...n,children:s})),o&&a.push(M(o)),a})(e);if(fe(e,"path"))throw new Error("There cannot be duplicate paths in a route");return S(e)},k=(e,n)=>({import:`import ${e} from './${n}'`,component:`<start><${e} /></end>`,lazy:`const ${e} = lazy(() => import('${n}'))`,lazyComponent:`<start><Suspense><${e} /></Suspense></end>`});var E="index.tsx",N="index.jsx",F=(e,n,t,o,r,s,a)=>{const i=((e,n)=>e.includes(n?E:N)?e.replace(n?E:N,n?$e:xe):e)(pe(e,n),a),c=ue(ie(t,e)),u=se(R(c),s),p=`element(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},W=(e,n,t,o)=>{const r=pe(e,n);t[`/${r}`]=c(r,ae(e),o)};function L(e,n,o,r,s,a,i,c,u){const p={},l=e.replace(/^\/+/,""),h=t.sync(l,{cwd:n,absolute:!0,onlyFiles:!0}).filter(he);for(const t of h)if("component"===s){if(t.includes(".config."))continue;F(t,o,r,p,a,i,u)}else W(t,o,p,c);return p}var B=async(e,n,t,o,r,s)=>{const a=/* @__PURE__ */new Map,i=/* @__PURE__ */new Set,c=/* @__PURE__ */new Map;ye(o,((e,n,t,o)=>{let r=e;for(const[s,a]of n){const e=k(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of t)r=r.replace(s,a);return de(r)})(function(e,n,t,o){const r=t.length>0?`\n${t.join("\n")}\n`:"";return`// Auto-generated by ono-auto-router\n${o?"import type { RouteObject } from 'react-router'\n":""}${n.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`}(T(await C(L("/**/*.{jsx,tsx}",n,t,o,"component",a,i,c,s),L("/**/*.config.{js,ts,jsx,tsx}",n,t,o,"config",a,i,c,s),e,s)),((e,n)=>{if(e)return["import { lazy, Suspense } from 'react'"];const t=[];for(const o of n.values())t.push(k(o.componentName,o.path).import);return t})(r,a),((e,n)=>{if(!e)return[];const t=[];for(const o of n.values())t.push(k(o.componentName,o.path).lazy);return t})(r,a),s),a,c,r))},z=(e,t,o,r)=>{const s=t.split(".")[0],a=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(r),i=o?((e,n)=>`\nconst PATH_REPLACEMENTS${n?": Record<string, string>":""} = {\n '/home': '/',\n '/root': '/'\n}\n\nconst cachedLazyComponents${n?": Record<\n string,\n LazyExoticComponent<ComponentType<unknown>>\n>":""} = {}\n\nconst getConfigFileName = ${n?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${n?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${n?"ts":"js"}'\n }\n return pagePath.replace('index.${n?"ts":"js"}', 'index.config.${n?"ts":"js"}')\n}\n\nconst formatPageModule = (${n?"\n pagesComponent: Record<string, ComponentType<unknown>>,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${n?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${n?"(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 = ${n?"(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 = ${n?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${n?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"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.${n?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${n?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${n?": 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 = ${n?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${n?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${n?"tsx":"jsx"}')) {\n result[key] = pagesComponent[key]\n }\n }\n\n return result\n}\n\nconst LazyComponent = ({\n Element\n}${n?": {\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}/**/*.${n?"tsx":"jsx"}')${n?" as PagesComponentType":""}\n })\n\n const pagesString = getFileDefault({\n ...import.meta.glob('/${e}/**/*.${n?"tsx":"jsx"}', {\n eager: true\n })\n })${n?" as Record<string, ComponentType<unknown>>":""}\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${n?"ts":"js"}', {\n eager: true\n })\n })${n?" as Record<string, PageConfig>":""}\n\n const result${n?": (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${n?": 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,r):((e,n)=>`\nconst PATH_REPLACEMENTS${n?": Record<string, string>":""} = {\n '/home': '/',\n '/root': '/'\n}\n\nconst getConfigFileName = ${n?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${n?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${n?"ts":"js"}'\n }\n return pagePath.replace('index.${n?"ts":"js"}', 'index.config.${n?"ts":"js"}')\n}\n\nconst formatPageModule = (${n?"\n pagesComponent: PagesComponentType,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${n?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${n?"(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 = ${n?"(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 = ${n?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${n?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"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.${n?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${n?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${n?": PagesComponentType | Record<string, PageConfig>":""} = {}\n\n for (const [path, module] of Object.entries(modules)) {\n if ('default' in module) {\n result[path] = module.default${n?" as ComponentType<unknown> | PageConfig":""}\n }\n }\n\n return result\n}\n\nconst filterUnComponent = ${n?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${n?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${n?"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}/**/*.${n?"tsx":"jsx"}', { eager: true })\n })${n?" as PagesComponentType":""}\n )\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${n?"ts":"js"}', {\n eager: true\n })\n })${n?" as Record<string, PageConfig>":""}\n\n const result${n?": (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,r),c=(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}`)(r),u=(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}`)(r),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}`)(r),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}`)(r),h=r?"// 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()`)(r),g=((e,n,t,o,r,s,a,i)=>`// Auto-generated by ono-auto-router${e}${n}${t}${o}${r}${s}${a}${i}\n`)(((e,n)=>e?`\n${n?"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${n?"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>`:n?"\nimport { lazy, Suspense } from 'react'\n":"")(r,o),(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}`)(r),l,p,u,c,i,f);r?(ye(n.resolve(s,"./index.ts"),a),ye(n.resolve(s,"./autoRouter.tsx"),g),ye(n.resolve(s,"./defineConfig.ts"),h)):ye(t,g)},A={"/home":"/","/root":"/"},I=(e,n)=>{const t=e.split("/"),o=t[t.length-1];return n&&o.endsWith(n)?o.slice(0,-n.length):o},D=e=>{const n=A[e];return n||("/notfound"===e.toLowerCase()||"/404"===e?"/:pathMatch(.*)*":e)},K=(e,n)=>e.endsWith(".config."+(n?"ts":"js"))?"index"===I(e,".config."+(n?"ts":"js"))?e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")):e.slice(0,-10)+".vue":e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")),_=(e,n,t)=>{if(e.endsWith(".config."+(t?"ts":"js"))){const o=I(e,".config."+(t?"ts":"js")),r=(e=>{const n=e.split("/");return n.pop(),n.join("/")})(e).replace(n,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(n,"").replace("/index.config."+(t?"ts":"js"),"")||"/"},H=async(e,n,t,o)=>{const r=[];for(const[s,a]of((e,n,t)=>Object.keys(e).map(e=>{const o=((e,n)=>e.replace("index."+(n?"ts":"js"),"index.config."+(n?"ts":"js")))(e,t);return[o,n[o]||{}]}))(e,n,o)){const n=K(s,o),i=me(_(s,`/${t}`,o)||"/",o,"vue"),c=D(i);r.push({...a,path:c,type:a?.type,isRoot:"/root"===i,component:e[n]})}return r},V=e=>{if(!e.path)return e;if("wrap"!==e.type){const{path:n,children:t,...o}=e;if(Object.keys(o).length>0)return{path:n,children:[{path:"",...o},...(t||[]).map(V)]}}return e.children?{...e,children:e.children.map(V)}:e},U=e=>(e=>e.map(V))((e=>{const n=/* @__PURE__ */new Map,t=[],o=/* @__PURE__ */new Map,r=e=>{let n=o.get(e);return void 0===n&&(n="/"===e?[]:e.split("/").filter(Boolean),o.set(e,n)),n},s=e.slice().sort((e,n)=>e.path.length-n.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(n.set(e,s),o.length<=1){t.push(s);continue}const i="/"+o.slice(0,-1).join("/"),c=n.get(i);c?(s.path=o[o.length-1],c.children.push(s)):t.push(s)}return t})(e)),J=e=>{const{isRoot:n,type:t,children:o,...r}=e;return o?.length?{...r,children:o.map(J)}:r},Z=e=>{const{children:n}=e;if(!n?.length){const{children:n,...t}=e;return t}const t=n.map(Z);if("wrap"===e.type)return{...e,children:t};const{path:o,component:r,type:s,children:a,...i}=e;return r?{path:o,children:[{path:"",component:r,...i},...t]}:{path:o,...i,children:t}},q=e=>J(Z(e)),G=e=>U(e).map(q),Q=e=>{if(e.some(e=>e.isRoot))return(e=>{let n,t,o;const r=[];for(const i of e)if(i.isRoot){if(n)throw new Error("There cannot be multiple root routes in a route");n=i}else"/"===i.path?t=i:"/:pathMatch(.*)*"===i.path?o=i:r.push(i);if(fe(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[t&&{...t,index:!0},...G(r)].filter(e=>Boolean(e)),a=[];return n&&a.push(J({...n,children:s})),o&&a.push(J(o)),a})(e);if(fe(e,"path"))throw new Error("There cannot be duplicate paths in a route");return G(e)},X=(e,n)=>({import:`import ${e} from './${n}'`,component:`<start>${e}</end>`,lazyComponent:`<start>() => import('${n}')</end>`});var Y=(e,n,t,o,r,s,a)=>{const i=((e,n)=>e.replace("index.vue",n?$e:xe))(pe(e,n),a),c=ue(ie(t,e)),u=se(R(c),s),p=`component(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},ee=(e,n,t,o)=>{const r=pe(e,n);t[`/${r}`]=c(r,ae(e),o)};function ne(e,n,o,r,s,a,i,c,u){const p={},l=e.replace(/^\/+/,""),h=t.sync(l,{cwd:n,absolute:!0,onlyFiles:!0}),f="component"===s?((e,n)=>n.map(n=>n.includes("index.vue")||2===n.replace(e.replaceAll("\\","/"),"").split("/").length?n:void 0).filter(Boolean))(n,h):h.filter(he);for(const t of f)if("component"===s){if(t.includes(".config."))continue;Y(t,o,r,p,a,i,u)}else ee(t,o,p,c);return p}var te=async(e,n,t,o,r,s)=>{const a=/* @__PURE__ */new Map,i=/* @__PURE__ */new Set,c=/* @__PURE__ */new Map;ye(o,((e,n,t,o)=>{let r=e;for(const[s,a]of n){const e=X(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of t)r=r.replace(s,a);return de(r)})(function(e,n,t,o){return`// Auto-generated by ono-auto-router${t?"\nimport type { RouteRecordRaw } from 'vue-router'":""}${o?"":`\n${n.join("\n")}${t?"":"\n"}`}${t?"\n\ntype PageConfig = Partial<\n Omit<RouteRecordRaw, 'path' | 'component' | 'children'> & {\n type?: 'single' | 'wrap'\n }\n>\n":""}${t?"\nexport const defineConfig = (config: PageConfig) => config\n":""}\nexport const routes${t?": RouteRecordRaw[]":""} = ${JSON.stringify(e,null,2)}\n`}(Q(await H(ne("/**/*.vue",n,t,o,"component",a,i,c,s),ne("/**/*.config.{js,ts}",n,t,o,"config",a,i,c,s),e,s)),((e,n)=>{if(e)return[];const t=[];for(const o of n.values())t.push(X(o.componentName,o.path).import);return t})(r,a),s,r),a,c,r))},oe=(e,t,o,r)=>{const s=t.split(".")[0],a=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(o),i=((e,n,t)=>`\nconst pathCache = new Map${n?"<string, { compPath: string; basePath: string }>":""}()\nconst basenameCache = new Map${n?"<string, string>":""}()\n\nconst normalizePagePath = ${n?"(key: string): string":"(key)"} => {\n if (key.includes('index.vue')) return key.replace('index.vue', 'index.${n?"ts":"js"}')\n if (key.includes('root.vue')) return key.replace('root.vue', 'root/index.${n?"ts":"js"}')\n if (key.includes('404.vue')) return key.replace('404.vue', '404/index.${n?"ts":"js"}')\n if (key.toLowerCase().includes('notfound.vue'))\n return key.toLowerCase().replace('notfound.vue', 'notfound/index.${n?"ts":"js"}')\n return key\n}\n\nconst getBasename = ${n?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const cacheKey = ext ? filePath + ':' + ext : filePath\n if (basenameCache.has(cacheKey)) {\n return basenameCache.get(cacheKey)${n?"!":""}\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 = ${n?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getPathsFromConfig = ${n?"(configPath: string)":"(configPath)"} => {\n const cacheKey = configPath\n if (pathCache.has(cacheKey)) {\n return pathCache.get(cacheKey)${n?"!":""}\n }\n\n let compPath${n?": string":" = ''"}\n let basePath${n?": string":" = ''"}\n\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n\n if (fileName === 'index') {\n compPath = configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"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.${n?"ts":"js"}', 'index.${n?"ts":"js"}')\n basePath =\n configPath.replace('/${e}', '').replace('/index.config.${n?"ts":"js"}', '') ||\n '/'\n }\n\n const result = { compPath, basePath }\n pathCache.set(cacheKey, result)\n return result\n}\n\nconst formatPath = ${n?"(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.${n?"ts":"js"}', '') || '/'\n}\n\nconst getConfigFileName = ${n?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.vue')) {\n return pagePath.slice(0, -4) + '.config.${n?"ts":"js"}'\n }\n return pagePath.replace('index.${n?"ts":"js"}', 'index.config.${n?"ts":"js"}')\n}\n\nconst createBaseRoutes = ()${n?": MyRouteObject[]":""} => {\n const pagesComponent = Object.fromEntries(\n Object.entries({\n ...import.meta.glob('/${e}/**/index.vue'${t?"":", { eager: true, import: 'default' }"}),\n ...import.meta.glob('/${e}/*.vue'${t?"":", { eager: true, import: 'default' }"})\n }${n?" as PagesComponentType":""}).map(([key, value]) => [\n normalizePagePath(key),\n value\n ])\n )\n\n const pagesModule${n?": Record<string, PageConfig>":""} = import.meta.glob(\n '/${e}/**/*.config.${n?"ts":"js"}',\n { eager: true, import: 'default' }\n )\n\n const result${n?": (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${n?"!":""}\n })\n }\n\n return result\n}\n\nconst processRoutes = ${n?"(\n routes: MyRouteObject[],\n removeLeadingSlash = false\n): MyRouteObject[]":"(routes, removeLeadingSlash)"} =>\n buildRouteTree(routes, removeLeadingSlash)\n .map(removeEmptyChildren)\n .map(cleanIsRoot)\n\nconst handleRootRoute = ${n?"(\n routes: (MyRouteObject & { isRoot?: boolean })[]\n): MyRouteObject[]":"(routes)"} => {\n let rootRoute${n?": (MyRouteObject & { isRoot?: boolean }) | undefined":" = undefined"}\n let homeRoute${n?": MyRouteObject | undefined":" = undefined"}\n let notFoundRoute${n?": MyRouteObject | undefined":" = undefined"}\n const filteredRoutes${n?": (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${n?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n if (rootRoute) {\n const children = [\n homeRoute && { ...homeRoute, path: '' },\n ...processRoutes(filteredRoutes, true)\n ].filter(Boolean)${n?" 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 = ()${n?": RouteRecordRaw[]":""} => {\n const routes = createBaseRoutes()\n\n if (routes.some((r${n?": MyRouteObject & { isRoot?: boolean }":""}) => r.isRoot))\n return handleRootRoute(routes)${n?" 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)${n?" as RouteRecordRaw[]":""}\n}\n`)(e,o,r),c=(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`)(o),u=(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`)(o),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`)(o),l=o?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",h=((e,n,t,o,r,s,a)=>`// Auto-generated by ono-auto-router${e}${n}${t}${o}${r}${s}${a}\n`)(o?"\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`)(o),p,u,c,i,"\nexport const routes = createRoutes()");o?(ye(n.resolve(s,"./index.ts"),a),ye(n.resolve(s,"./autoRouter.ts"),h),ye(n.resolve(s,"./defineConfig.ts"),l)):ye(t,h)},re=(t,o,r,s,c,u)=>{const l=n.resolve(r,o);if(!e.existsSync(l))throw new Error(`Pages directory not found: ${l}`);const f=h(t,r,s),g=p(r),d=f.split(".")[0];a(d+".js"),a(d+".ts"),a(d+".jsx"),a(d+".tsx"),i(d),"react"===t?u?z(o,f,c,g):B(o,l,r,f,c,g):u?oe(o,f,g,c):te(o,l,r,f,c,g),console.log(`[ono-auto-router] Routes file generated: ${u?n.resolve(f.replace(".tsx","").replace(".ts",""),"./autoRouter"+("react"===t?".tsx":".ts")):f}`)},se=(e,n)=>{if(!n.has(e))return n.add(e),e;let t=1;for(;n.has(`${e}_${t}`);)t++;return`${e}_${t}`};function ae(n){try{const o=e.readFileSync(n,"utf-8").match(/export\s+default\s+([\s\S]*?)(?=\n\w|$)/);if(!o)return console.warn("No export default found in:",n),null;const r=o[1].trim();try{if(r.startsWith("{"))return new Function(`return ${r}`)();if(r.includes("defineConfig(")){const e=r.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(o){return console.error("Error reading file:",o),null}}function ie(e,t){let o=n.resolve(e);(o.endsWith(".js")||o.endsWith(".jsx")||o.endsWith(".ts")||o.endsWith(".tsx")||o.endsWith(".vue"))&&(o=n.dirname(o));const r=n.resolve(t);return n.relative(o,r)}var ce=/\\/g,ue=e=>e.replace(ce,"/"),pe=(e,t)=>ue(n.relative(t,e)),le=/export\s+default\s+[\w(\[\]\{\})]+/;function he(n){try{if(!e.existsSync(n))return console.warn(`File not found: ${n}`),!1;const t=e.readFileSync(n,"utf-8");return le.test(t)}catch(t){return console.error("Read error:",t),!1}}var fe=(e,n)=>{const t=/* @__PURE__ */new Set;return e.some(e=>!!t.has(e[n])||(t.add(e[n]),!1))};function ge(e){return e.replace(/"<start>([\s\S]*?)<\/end>"/g,"$1")}function de(e){let n=e;for(;;){const e=ge(n);if(e===n)break;n=e}return n}var me=(e,n,t)=>e.replace(/\[([^\]]+)\]/g,":$1").replace("react"===t?n?".tsx":".jsx":".vue","");function Re(n){e.existsSync(n)||e.mkdirSync(n,{recursive:!0})}function Pe(t,o){Re(n.dirname(t)),e.writeFileSync(t,o,"utf-8")}async function ye(t,o){const r=n.dirname(t);await e.promises.mkdir(r,{recursive:!0}),await e.promises.writeFile(t,o,"utf-8")}var $e="index.ts",xe="index.js";export{p as C,a as D,i as E,o as O,h as S,c as T,te as _,Pe as a,m as b,fe as c,ue as d,ie as f,oe as g,re as h,ye as i,he as l,se as m,$e as n,me as o,ae as p,Re as r,de as s,xe as t,pe as u,z as v,u as w,R as x,B as y};