@onoxm/vite-plugin-auto-router 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +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 P={"/home":"/","/__root__":"/"},$=(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__":P[e])(e,n,t);return o||("/notfound"===e.toLowerCase()||"/404"===e?"/*":e)},j=(e,n)=>e.endsWith(".config."+(n?"ts":"js"))?"index"===$(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=$(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=ye(x(i,`/${t}`,o)||"/",o,"react"),p=y(u,r,s),{path:l,...h}=c;a.push(Object.assign({path:p,isRoot:!s&&"/__root__"===u,element:e[n],...h},l?{replacePath:l}:{}))}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),_=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(Re(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(Re(e,"path"))throw new Error("There cannot be duplicate paths in a route");return S(e)},T=(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=e=>e.map(e=>{if(!("replacePath"in e)&&!e.children?.length)return e;const{replacePath:n,children:t,...o}=e,r={...o};if(n)if(n.includes("[currentPath]")){const e=r.path;r.path=n.replace("[currentPath]",e)}else r.path=n;return t?.length&&(r.children=E(t)),r}),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?be:we):e)(ge(e,n),a),c=fe(le(t,e)),u=ue(R(c),s),p=`element(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},W=(e,n,t,o)=>{const r=ge(e,n);t[`/${r}`]=c(r,pe(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(me);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;Ce(o,((e,n,t,o)=>{let r=e;for(const[s,a]of n){const e=T(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 $e(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, '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`}(E(_(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(T(o.componentName,o.path).import);return t})(r,c),((e,n)=>{if(!e)return[];const t=[];for(const o of n.values())t.push(T(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 const { path: replacePath, ...rest } = page\n\n result.push(\n Object.assign(\n {\n path: routePath,\n type: page?.type,\n ${o?"":"isRoot: processedPath === '/__root__',\n "}element: Component,\n ...rest\n },\n (replacePath && { replacePath }) || {}\n )\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\n const { path: replacePath, ...rest } = page\n\n result.push(\n Object.assign(\n {\n path: routePath,\n type: page?.type,\n ${o?"":"isRoot: processedPath === '/__root__',\n "}element: <Component />,\n ...rest\n },\n (replacePath && { replacePath }) || {}\n )\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,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 replacePath?: string\n children?: MyRouteObject[]\n}\n\n${t?"":"type RouteWithIsRoot = MyRouteObject & { isRoot?: boolean }\n\n"}export type PageConfig = Partial<\n Omit<MyRouteObject, 'Component' | 'element' | 'children' | 'replacePath'>\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}\n\nexport const replacePaths = ${e?"(routes: MyRouteObject[]): RouteObject[]":"(routes)"} => {\n return routes.map(route => {\n if (!('replacePath' in route) && !route.children?.length) {\n return route${e?" as RouteObject":""}\n }\n\n const { replacePath, children, ...rest } = route\n const newRoute = { ...rest }\n\n if (replacePath) {\n if (replacePath.includes('[currentPath]')) {\n const currentPath = newRoute.path\n newRoute.path = replacePath.replace('[currentPath]', currentPath)\n } else {\n newRoute.path = replacePath\n }\n }\n\n if (children?.length) {\n ${e?";(newRoute as MyRouteObject)":"newRoute"}.children = replacePaths(\n children\n )${e?" as RouteObject[]":""}\n }\n\n return newRoute${e?" as RouteObject":""}\n })\n}`)(r),f,h,l,p,u,"\nconst getRoutes = () => {\n const baseRoutes = createBaseRoutes()\n return replacePaths(formatRoutes(baseRoutes))\n}\n\nexport const routes = getRoutes()");r?(Ce(n.resolve(i,"./index.ts"),c),Ce(n.resolve(i,"./autoRouter.tsx"),d),Ce(n.resolve(i,"./defineConfig.ts"),g)):Ce(t,d)},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")),H=(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"),"")||"/"},V=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=ye(H(i,`/${t}`,o)||"/",o,"vue"),p=D(u,r,s),l=u.split("/").filter(Boolean).join("-")||"index",{path:h,...f}=c;a.push(Object.assign({name:l,path:p,isRoot:!s&&"/__root__"===u,component:e[n],...f},h?{replacePath:h}:{}))}return a},U=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(U)]}}return e.children?{...e,children:e.children.map(U)}:e},J=e=>(e=>e.map(U))((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)),Z=e=>{const{isRoot:n,type:t,children:o,...r}=e;return o?.length?{...r,children:o.map(Z)}:r},q=e=>{const{children:n}=e;if(!n?.length){const{children:n,...t}=e;return t}const t=n.map(q);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}},G=e=>Z(q(e)),Q=e=>J(e).map(G),X=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(Re(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[t,...Q(r)].filter(e=>Boolean(e)),a=[];return n&&a.push(Z({...n,children:s})),o&&a.push(Z(o)),a})(e);if(Re(e,"path"))throw new Error("There cannot be duplicate paths in a route");return Q(e)},Y=(e,n)=>({import:`import ${e} from './${n}'`,component:`<start>${e}</end>`,lazyComponent:`<start>() => import('${n}')</end>`});var ee=e=>e.map(e=>{if(!("replacePath"in e)&&!e.children?.length)return e;const{replacePath:n,children:t,...o}=e,r={...o};if(n)if(n.includes("[currentPath]")){const e=r.path;r.path=n.replace("[currentPath]",e)}else r.path=n;return t?.length&&(r.children=ee(t)),r}),ne=(e,n,t,o,r,s,a)=>{const i=((e,n)=>e.replace("index.vue",n?be:we))(ge(e,n),a),c=fe(le(t,e)),u=ue(R(c),s),p=`component(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},te=(e,n,t,o)=>{const r=ge(e,n);t[`/${r}`]=c(r,pe(e),o)};function oe(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(me);for(const t of f)if("component"===s){if(t.includes(".config."))continue;ne(t,o,r,p,a,i,u)}else te(t,o,p,c);return p}var re=async(e,n,t,o,r,s,a,i)=>{const c=/* @__PURE__ */new Map,u=/* @__PURE__ */new Set,p=/* @__PURE__ */new Map;Ce(o,((e,n,t,o)=>{let r=e;for(const[s,a]of n){const e=Y(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 $e(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, '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`}(ee(X(await V(oe("/**/*.vue",n,t,o,"component",c,u,p,s),oe("/**/*.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(Y(o.componentName,o.path).import);return t})(r,c),s,r),c,p,r))},se=(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 replacePaths = ${n?"(routes: MyRouteObject[]): RouteRecordRaw[]":"(routes)"} => {\n return routes.map(route => {\n if (!('replacePath' in route) && !route.children?.length) {\n return route${n?" as RouteRecordRaw":""}\n }\n\n const { replacePath, children, ...rest } = route\n const newRoute = { ...rest }\n\n if (replacePath) {\n if (replacePath.includes('[currentPath]')) {\n const currentPath = newRoute.path\n newRoute.path = replacePath.replace('[currentPath]', currentPath)\n } else {\n newRoute.path = replacePath\n }\n }\n\n if (children?.length) {\n ${n?";(newRoute as MyRouteObject)":"newRoute"}.children = replacePaths(children)\n }\n\n return newRoute${n?" as RouteRecordRaw":""}\n })\n}\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 const { path: replacePath, ...rest } = content\n const formattedPath = formatPath(path)\n\n result.push(\n Object.assign(\n {\n path: formattedPath,\n name,\n component: pagesComponent[compPath],\n ${r?"":"isRoot: path === '/__root__',\n "}...rest\n },\n replacePath ? { replacePath } : {}\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 replacePaths(handleRootRoute(routes))\n\n `}if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return replacePaths(processRoutes(routes))\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 replacePath?: string\n children?: MyRouteObject[]\n}\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'component' | 'children' | 'replacePath'>\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('.vue', '')\n}\n`)(r),h,l,p,u,"\nexport const routes = createRoutes()");r?(Ce(n.resolve(i,"./index.ts"),c),Ce(n.resolve(i,"./autoRouter.ts"),g),Ce(n.resolve(i,"./defineConfig.ts"),f)):Ce(t,g)},ae={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)=>se(e,o,r,s,a,i),normal:re}},ie=[".js",".ts",".jsx",".tsx"],ce=(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 ie)a(e+n);i(e)})(d.split(".")[0]),ae[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}`)},ue=(e,n)=>{if(!n.has(e))return n.add(e),e;let t=1;for(;n.has(`${e}_${t}`);)t++;return`${e}_${t}`};function pe(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 le(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 he=/\\/g,fe=e=>e.replace(he,"/"),ge=(e,t)=>fe(n.relative(t,e)),de=/export\s+default\s+[\w(\[\]\{\})]+/;function me(n){try{if(!e.existsSync(n))return console.warn(`File not found: ${n}`),!1;const t=e.readFileSync(n,"utf-8");return de.test(t)}catch(t){return console.error("Read error:",t),!1}}var Re=(e,n)=>{const t=/* @__PURE__ */new Set;return e.some(e=>!!t.has(e[n])||(t.add(e[n]),!1))};function Pe(e){return e.replace(/"<start>([\s\S]*?)<\/end>"/g,"$1")}function $e(e){let n=e;for(;;){const e=Pe(n);if(e===n)break;n=e}return n}var ye=(e,n,t)=>e.replace(/\[([^\]]+)\]/g,":$1").replace("react"===t?n?".tsx":".jsx":".vue","");function je(n){e.existsSync(n)||e.mkdirSync(n,{recursive:!0})}function xe(t,o){je(n.dirname(t)),e.writeFileSync(t,o,"utf-8")}async function Ce(t,o){const r=n.dirname(t);await e.promises.mkdir(r,{recursive:!0}),await e.promises.writeFile(t,o,"utf-8")}var be="index.ts",we="index.js";export{p as C,a as D,i as E,o as O,h as S,c as T,re as _,xe as a,m as b,Re as c,fe as d,le as f,se as g,ce as h,Ce as i,me as l,ue as m,be as n,ye as o,pe as p,je as r,$e as s,we as t,ge as u,z as v,u as w,R as x,B as y};
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__":"/"},$=(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__":P[e])(e,n,t);return o||("/notfound"===e.toLowerCase()||"/404"===e?"/*":e)},j=(e,n)=>e.endsWith(".config."+(n?"ts":"js"))?"index"===$(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=$(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=ye(x(i,`/${t}`,o)||"/",o,"react"),p=y(u,r,s),{path:l,...h}=c;a.push(Object.assign({path:p,isRoot:!s&&"/__root__"===u,element:e[n],...h},l?{replacePath:l}:{}))}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),_=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(Re(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(Re(e,"path"))throw new Error("There cannot be duplicate paths in a route");return S(e)},T=(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=e=>e.map(e=>{if(!("replacePath"in e)&&!e.children?.length)return e;const{replacePath:n,children:t,...o}=e,r={...o};if(n)if(n.includes("[currentPath]")){const e=r.path;r.path=n.replace("[currentPath]",e)}else r.path=n;return t?.length&&(r.children=E(t)),r}),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?be:we):e)(ge(e,n),a),c=fe(le(t,e)),u=ue(R(c),s),p=`element(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},W=(e,n,t,o)=>{const r=ge(e,n);t[`/${r}`]=c(r,pe(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(me);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;Ce(o,((e,n,t,o)=>{let r=e;for(const[s,a]of n){const e=T(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 $e(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, '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`}(E(_(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(T(o.componentName,o.path).import);return t})(r,c),((e,n)=>{if(!e)return[];const t=[];for(const o of n.values())t.push(T(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 const { path: replacePath, ...rest } = page\n\n result.push(\n Object.assign(\n {\n path: routePath,\n type: page?.type,\n ${o?"":"isRoot: processedPath === '/__root__',\n "}element: Component,\n ...rest\n },\n (replacePath && { replacePath }) || {}\n )\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\n const { path: replacePath, ...rest } = page\n\n result.push(\n Object.assign(\n {\n path: routePath,\n type: page?.type,\n ${o?"":"isRoot: processedPath === '/__root__',\n "}element: <Component />,\n ...rest\n },\n (replacePath && { replacePath }) || {}\n )\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,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 replacePath?: string\n children?: MyRouteObject[]\n}\n\n${t?"":"type RouteWithIsRoot = MyRouteObject & { isRoot?: boolean }\n\n"}export type PageConfig = Partial<\n Omit<MyRouteObject, 'Component' | 'element' | 'children' | 'replacePath'>\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}\n\nexport const replacePaths = ${e?"(routes: MyRouteObject[]): RouteObject[]":"(routes)"} => {\n return routes.map(route => {\n if (!('replacePath' in route) && !route.children?.length) {\n return route${e?" as RouteObject":""}\n }\n\n const { replacePath, children, ...rest } = route\n const newRoute = { ...rest }\n\n if (replacePath) {\n if (replacePath.includes('[currentPath]')) {\n const currentPath = newRoute.path\n newRoute.path = replacePath.replace('[currentPath]', currentPath)\n } else {\n newRoute.path = replacePath\n }\n }\n\n if (children?.length) {\n ${e?";(newRoute as MyRouteObject)":"newRoute"}.children = replacePaths(\n children\n )${e?" as RouteObject[]":""}\n }\n\n return newRoute${e?" as RouteObject":""}\n })\n}`)(r),f,h,l,p,u,"\nconst getRoutes = () => {\n const baseRoutes = createBaseRoutes()\n return replacePaths(formatRoutes(baseRoutes))\n}\n\nexport const routes = getRoutes()");r?(Ce(n.resolve(i,"./index.ts"),c),Ce(n.resolve(i,"./autoRouter.tsx"),d),Ce(n.resolve(i,"./defineConfig.ts"),g)):Ce(t,d)},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")),H=(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"),"")||"/"},V=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=ye(H(i,`/${t}`,o)||"/",o,"vue"),p=D(u,r,s),{path:l,...h}=c;a.push(Object.assign({path:p,isRoot:!s&&"/__root__"===u,component:e[n],...h},l?{replacePath:l}:{}))}return a},U=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(U)]}}return e.children?{...e,children:e.children.map(U)}:e},J=e=>(e=>e.map(U))((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)),Z=e=>{const{isRoot:n,type:t,children:o,...r}=e;return o?.length?{...r,children:o.map(Z)}:r},q=e=>{const{children:n}=e;if(!n?.length){const{children:n,...t}=e;return t}const t=n.map(q);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}},G=e=>Z(q(e)),Q=e=>J(e).map(G),X=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(Re(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[t,...Q(r)].filter(e=>Boolean(e)),a=[];return n&&a.push(Z({...n,children:s})),o&&a.push(Z(o)),a})(e);if(Re(e,"path"))throw new Error("There cannot be duplicate paths in a route");return Q(e)},Y=(e,n)=>({import:`import ${e} from './${n}'`,component:`<start>${e}</end>`,lazyComponent:`<start>() => import('${n}')</end>`});var ee=e=>e.map(e=>{if(!("replacePath"in e)&&!e.children?.length)return e;const{replacePath:n,children:t,...o}=e,r={...o};if(n)if(n.includes("[currentPath]")){const e=r.path;r.path=n.replace("[currentPath]",e)}else r.path=n;return t?.length&&(r.children=ee(t)),r}),ne=(e,n,t,o,r,s,a)=>{const i=((e,n)=>e.replace("index.vue",n?be:we))(ge(e,n),a),c=fe(le(t,e)),u=ue(R(c),s),p=`component(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},te=(e,n,t,o)=>{const r=ge(e,n);t[`/${r}`]=c(r,pe(e),o)};function oe(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(me);for(const t of f)if("component"===s){if(t.includes(".config."))continue;ne(t,o,r,p,a,i,u)}else te(t,o,p,c);return p}var re=async(e,n,t,o,r,s,a,i)=>{const c=/* @__PURE__ */new Map,u=/* @__PURE__ */new Set,p=/* @__PURE__ */new Map;Ce(o,((e,n,t,o)=>{let r=e;for(const[s,a]of n){const e=Y(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 $e(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, '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`}(ee(X(await V(oe("/**/*.vue",n,t,o,"component",c,u,p,s),oe("/**/*.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(Y(o.componentName,o.path).import);return t})(r,c),s,r),c,p,r))},se=(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 replacePaths = ${n?"(routes: MyRouteObject[]): RouteRecordRaw[]":"(routes)"} => {\n return routes.map(route => {\n if (!('replacePath' in route) && !route.children?.length) {\n return route${n?" as RouteRecordRaw":""}\n }\n\n const { replacePath, children, ...rest } = route\n const newRoute = { ...rest }\n\n if (replacePath) {\n if (replacePath.includes('[currentPath]')) {\n const currentPath = newRoute.path\n newRoute.path = replacePath.replace('[currentPath]', currentPath)\n } else {\n newRoute.path = replacePath\n }\n }\n\n if (children?.length) {\n ${n?";(newRoute as MyRouteObject)":"newRoute"}.children = replacePaths(children)\n }\n\n return newRoute${n?" as RouteRecordRaw":""}\n })\n}\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\n const { path: replacePath, ...rest } = content\n const formattedPath = formatPath(path)\n\n result.push(\n Object.assign(\n {\n path: formattedPath,\n component: pagesComponent[compPath],\n ${r?"":"isRoot: path === '/__root__',\n "}...rest\n },\n replacePath ? { replacePath } : {}\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 replacePaths(handleRootRoute(routes))\n\n `}if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return replacePaths(processRoutes(routes))\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 replacePath?: string\n children?: MyRouteObject[]\n}\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'component' | 'children' | 'replacePath'>\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('.vue', '')\n}\n`)(r),h,l,p,u,"\nexport const routes = createRoutes()");r?(Ce(n.resolve(i,"./index.ts"),c),Ce(n.resolve(i,"./autoRouter.ts"),g),Ce(n.resolve(i,"./defineConfig.ts"),f)):Ce(t,g)},ae={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)=>se(e,o,r,s,a,i),normal:re}},ie=[".js",".ts",".jsx",".tsx"],ce=(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 ie)a(e+n);i(e)})(d.split(".")[0]),ae[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}`)},ue=(e,n)=>{if(!n.has(e))return n.add(e),e;let t=1;for(;n.has(`${e}_${t}`);)t++;return`${e}_${t}`};function pe(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 le(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 he=/\\/g,fe=e=>e.replace(he,"/"),ge=(e,t)=>fe(n.relative(t,e)),de=/export\s+default\s+[\w(\[\]\{\})]+/;function me(n){try{if(!e.existsSync(n))return console.warn(`File not found: ${n}`),!1;const t=e.readFileSync(n,"utf-8");return de.test(t)}catch(t){return console.error("Read error:",t),!1}}var Re=(e,n)=>{const t=/* @__PURE__ */new Set;return e.some(e=>!!t.has(e[n])||(t.add(e[n]),!1))};function Pe(e){return e.replace(/"<start>([\s\S]*?)<\/end>"/g,"$1")}function $e(e){let n=e;for(;;){const e=Pe(n);if(e===n)break;n=e}return n}var ye=(e,n,t)=>e.replace(/\[([^\]]+)\]/g,":$1").replace("react"===t?n?".tsx":".jsx":".vue","");function je(n){e.existsSync(n)||e.mkdirSync(n,{recursive:!0})}function xe(t,o){je(n.dirname(t)),e.writeFileSync(t,o,"utf-8")}async function Ce(t,o){const r=n.dirname(t);await e.promises.mkdir(r,{recursive:!0}),await e.promises.writeFile(t,o,"utf-8")}var be="index.ts",we="index.js";export{p as C,a as D,i as E,o as O,h as S,c as T,re as _,xe as a,m as b,Re as c,fe as d,le as f,se as g,ce as h,Ce as i,me as l,ue as m,be as n,ye as o,pe as p,je as r,$e as s,we as t,ge as u,z as v,u as w,R as x,B as y};
@@ -1 +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,c)=>(c=null!=a?e(r(a)):{},((e,r,a,i)=>{if(r&&"object"==typeof r||"function"==typeof r)for(var c,u=o(r),p=0,l=u.length;p<l;p++)c=u[p],s.call(e,c)||c===a||t(e,c,{get:(e=>r[e]).bind(null,c),enumerable:!(i=n(r,c))||i.enumerable});return e})(!i&&a&&a.__esModule?c:t(c,"default",{value:a,enumerable:!0}),a));let i=require("node:fs");i=a(i);let c=require("node:path");c=a(c);let u=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}u=a(u);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(c.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?c.default.resolve(t,o):c.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=c.default.extname(e),n=c.default.basename(e,t),o=c.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"),"")||"/"},_=async(e,t,n,o,r,s)=>{const a=[];for(const[i,c]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 u=Me(S(i,`/${n}`,o)||"/",o,"react"),p=M(u,r,s),{path:l,...h}=c;a.push(Object.assign({path:p,isRoot:!s&&"/__root__"===u,element:e[t],...h},l?{replacePath:l}:{}))}return a},T=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(T)]}}return e.children?{...e,children:e.children.map(T)}:e},E=e=>(e=>e.map(T))((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("/"),c=t.get(i);c?(s.path=o[o.length-1],c.children.push(s)):n.push(s)}return n})(e)),k=e=>{const{isRoot:t,type:n,children:o,...r}=e;return o?.length?{...r,children:o.map(k)}:r},N=e=>{const{children:t}=e;if(!t?.length){const{children:t,...n}=e;return n}const n=t.map(N);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}},F=e=>k(N(e)),W=e=>E(e).map(F),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(Ce(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[n&&{...n,index:!0},...W(r)].filter(e=>Boolean(e)),a=[];return t&&a.push(k({...t,children:s})),o&&a.push(k(o)),a})(e);if(Ce(e,"path"))throw new Error("There cannot be duplicate paths in a route");return W(e)},L=(e,t)=>({import:`import ${e} from './${t}'`,component:`<start><${e} /></end>`,lazy:`const ${e} = lazy(() => import('${t}'))`,lazyComponent:`<start><Suspense><${e} /></Suspense></end>`});var z=e=>e.map(e=>{if(!("replacePath"in e)&&!e.children?.length)return e;const{replacePath:t,children:n,...o}=e,r={...o};if(t)if(t.includes("[currentPath]")){const e=r.path;r.path=t.replace("[currentPath]",e)}else r.path=t;return n?.length&&(r.children=z(n)),r}),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?Te:Ee):e)(je(e,t),a),c=$e(Re(n,e)),u=me(C(c),s),p=`element(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},K=(e,t,n,o)=>{const r=je(e,t);n[`/${r}`]=g(r,Pe(e),o)};function H(e,t,n,o,r,s,a,i,c){const p={},l=e.replace(/^\/+/,""),h=u.default.sync(l,{cwd:t,absolute:!0,onlyFiles:!0}).filter(xe);for(const u of h)if("component"===r){if(u.includes(".config."))continue;I(u,n,o,p,s,a,c)}else K(u,n,p,i);return p}var U=async(e,t,n,o,r,s,a,i)=>{const c=new Map,u=new Set,p=new Map;_e(o,((e,t,n,o)=>{let r=e;for(const[s,a]of t){const e=L(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 we(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, '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`}(z(B(await _(H("/**/*.{jsx,tsx}",t,n,o,"component",c,u,p,s),H("/**/*.config.{js,ts,jsx,tsx}",t,n,o,"config",c,u,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(L(o.componentName,o.path).import);return n})(r,c),((e,t)=>{if(!e)return[];const n=[];for(const o of t.values())n.push(L(o.componentName,o.path).lazy);return n})(r,c),s),c,p,r))},V=(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),u=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 const { path: replacePath, ...rest } = page\n\n result.push(\n Object.assign(\n {\n path: routePath,\n type: page?.type,\n ${o?"":"isRoot: processedPath === '/__root__',\n "}element: Component,\n ...rest\n },\n (replacePath && { replacePath }) || {}\n )\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\n const { path: replacePath, ...rest } = page\n\n result.push(\n Object.assign(\n {\n path: routePath,\n type: page?.type,\n ${o?"":"isRoot: processedPath === '/__root__',\n "}element: <Component />,\n ...rest\n },\n (replacePath && { replacePath }) || {}\n )\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,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 replacePath?: string\n children?: MyRouteObject[]\n}\n\n${n?"":"type RouteWithIsRoot = MyRouteObject & { isRoot?: boolean }\n\n"}export type PageConfig = Partial<\n Omit<MyRouteObject, 'Component' | 'element' | 'children' | 'replacePath'>\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}\n\nexport const replacePaths = ${e?"(routes: MyRouteObject[]): RouteObject[]":"(routes)"} => {\n return routes.map(route => {\n if (!('replacePath' in route) && !route.children?.length) {\n return route${e?" as RouteObject":""}\n }\n\n const { replacePath, children, ...rest } = route\n const newRoute = { ...rest }\n\n if (replacePath) {\n if (replacePath.includes('[currentPath]')) {\n const currentPath = newRoute.path\n newRoute.path = replacePath.replace('[currentPath]', currentPath)\n } else {\n newRoute.path = replacePath\n }\n }\n\n if (children?.length) {\n ${e?";(newRoute as MyRouteObject)":"newRoute"}.children = replacePaths(\n children\n )${e?" as RouteObject[]":""}\n }\n\n return newRoute${e?" as RouteObject":""}\n })\n}`)(o),f,h,l,p,u,"\nconst getRoutes = () => {\n const baseRoutes = createBaseRoutes()\n return replacePaths(formatRoutes(baseRoutes))\n}\n\nexport const routes = getRoutes()");o?(_e(c.default.resolve(a,"./index.ts"),i),_e(c.default.resolve(a,"./autoRouter.tsx"),g),_e(c.default.resolve(a,"./defineConfig.ts"),d)):_e(t,g)},X={"/home":"/","/__root__":"/"},q=(e,t)=>{const n=e.split("/"),o=n[n.length-1];return t&&o.endsWith(t)?o.slice(0,-t.length):o},J=(e,t,n)=>{const o=((e,t,n)=>t&&"/home"===e?"/home":n&&"/__root__"===e?"/__root__":X[e])(e,t,n);return o||("/notfound"===e.toLowerCase()||"/404"===e?"/:pathMatch(.*)*":e)},Z=(e,t)=>e.endsWith(".config."+(t?"ts":"js"))?"index"===q(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")),G=(e,t,n)=>{if(e.endsWith(".config."+(n?"ts":"js"))){const o=q(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"),"")||"/"},Q=async(e,t,n,o,r,s)=>{const a=[];for(const[i,c]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=Z(i,o),u=Me(G(i,`/${n}`,o)||"/",o,"vue"),p=J(u,r,s),l=u.split("/").filter(Boolean).join("-")||"index",{path:h,...f}=c;a.push(Object.assign({name:l,path:p,isRoot:!s&&"/__root__"===u,component:e[t],...f},h?{replacePath:h}:{}))}return a},Y=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(Y)]}}return e.children?{...e,children:e.children.map(Y)}:e},ee=e=>(e=>e.map(Y))((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("/"),c=t.get(i);c?(s.path=o[o.length-1],c.children.push(s)):n.push(s)}return n})(e)),te=e=>{const{isRoot:t,type:n,children:o,...r}=e;return o?.length?{...r,children:o.map(te)}:r},ne=e=>{const{children:t}=e;if(!t?.length){const{children:t,...n}=e;return n}const n=t.map(ne);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}},oe=e=>te(ne(e)),re=e=>ee(e).map(oe),se=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(Ce(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[n,...re(r)].filter(e=>Boolean(e)),a=[];return t&&a.push(te({...t,children:s})),o&&a.push(te(o)),a})(e);if(Ce(e,"path"))throw new Error("There cannot be duplicate paths in a route");return re(e)},ae=(e,t)=>({import:`import ${e} from './${t}'`,component:`<start>${e}</end>`,lazyComponent:`<start>() => import('${t}')</end>`});var ie=e=>e.map(e=>{if(!("replacePath"in e)&&!e.children?.length)return e;const{replacePath:t,children:n,...o}=e,r={...o};if(t)if(t.includes("[currentPath]")){const e=r.path;r.path=t.replace("[currentPath]",e)}else r.path=t;return n?.length&&(r.children=ie(n)),r}),ce=(e,t,n,o,r,s,a)=>{const i=((e,t)=>e.replace("index.vue",t?Te:Ee))(je(e,t),a),c=$e(Re(n,e)),u=me(C(c),s),p=`component(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},ue=(e,t,n,o)=>{const r=je(e,t);n[`/${r}`]=g(r,Pe(e),o)};function pe(e,t,n,o,r,s,a,i,c){const p={},l=e.replace(/^\/+/,""),h=u.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(xe);for(const u of f)if("component"===r){if(u.includes(".config."))continue;ce(u,n,o,p,s,a,c)}else ue(u,n,p,i);return p}var le=async(e,t,n,o,r,s,a,i)=>{const c=new Map,u=new Set,p=new Map;_e(o,((e,t,n,o)=>{let r=e;for(const[s,a]of t){const e=ae(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 we(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, '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`}(ie(se(await Q(pe("/**/*.vue",t,n,o,"component",c,u,p,s),pe("/**/*.config.{js,ts}",t,n,o,"config",c,u,p,s),e,s,a,i))),((e,t)=>{if(e)return[];const n=[];for(const o of t.values())n.push(ae(o.componentName,o.path).import);return n})(r,c),s,r),c,p,r))},he=(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),u=((e,t,n,o,r)=>`\nconst pathCache = new Map${t?"<string, { compPath: string; basePath: string }>":""}()\nconst basenameCache = new Map${t?"<string, string>":""}()\n\nconst replacePaths = ${t?"(routes: MyRouteObject[]): RouteRecordRaw[]":"(routes)"} => {\n return routes.map(route => {\n if (!('replacePath' in route) && !route.children?.length) {\n return route${t?" as RouteRecordRaw":""}\n }\n\n const { replacePath, children, ...rest } = route\n const newRoute = { ...rest }\n\n if (replacePath) {\n if (replacePath.includes('[currentPath]')) {\n const currentPath = newRoute.path\n newRoute.path = replacePath.replace('[currentPath]', currentPath)\n } else {\n newRoute.path = replacePath\n }\n }\n\n if (children?.length) {\n ${t?";(newRoute as MyRouteObject)":"newRoute"}.children = replacePaths(children)\n }\n\n return newRoute${t?" as RouteRecordRaw":""}\n })\n}\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 const { path: replacePath, ...rest } = content\n const formattedPath = formatPath(path)\n\n result.push(\n Object.assign(\n {\n path: formattedPath,\n name,\n component: pagesComponent[compPath],\n ${r?"":"isRoot: path === '/__root__',\n "}...rest\n },\n replacePath ? { replacePath } : {}\n )\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 replacePaths(handleRootRoute(routes))\n\n `}if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return replacePaths(processRoutes(routes))\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 replacePath?: string\n children?: MyRouteObject[]\n}\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'component' | 'children' | 'replacePath'>\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('.vue', '')\n}\n`)(o),h,l,p,u,"\nexport const routes = createRoutes()");o?(_e(c.default.resolve(a,"./index.ts"),i),_e(c.default.resolve(a,"./autoRouter.ts"),d),_e(c.default.resolve(a,"./defineConfig.ts"),f)):_e(t,d)},fe={react:{hmr:(e,t,n,o,r,s,a,i)=>V(e,o,r,s,a,i),normal:U},vue:{hmr:(e,t,n,o,r,s,a,i)=>he(e,o,r,s,a,i),normal:le}},de=[".js",".ts",".jsx",".tsx"],ge=(e,t,n,o,r,s,a,u)=>{const p=c.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 de)f(e+t);d(e)})(l.split(".")[0]),fe[e][u?"hmr":"normal"](t,p,n,l,a,P(n),r,s),console.log(`[ono-auto-router] Routes file generated: ${u?c.default.resolve(l.replace(".tsx","").replace(".ts",""),"./autoRouter"+("react"===e?".tsx":".ts")):l}`)},me=(e,t)=>{if(!t.has(e))return t.add(e),e;let n=1;for(;t.has(`${e}_${n}`);)n++;return`${e}_${n}`};function Pe(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 Re(e,t){let n=c.default.resolve(e);(n.endsWith(".js")||n.endsWith(".jsx")||n.endsWith(".ts")||n.endsWith(".tsx")||n.endsWith(".vue"))&&(n=c.default.dirname(n));const o=c.default.resolve(t);return c.default.relative(n,o)}var ye=/\\/g,$e=e=>e.replace(ye,"/"),je=(e,t)=>$e(c.default.relative(t,e)),be=/export\s+default\s+[\w(\[\]\{\})]+/;function xe(e){try{if(!i.default.existsSync(e))return console.warn(`File not found: ${e}`),!1;const t=i.default.readFileSync(e,"utf-8");return be.test(t)}catch(t){return console.error("Read error:",t),!1}}var Ce=(e,t)=>{const n=new Set;return e.some(e=>!!n.has(e[t])||(n.add(e[t]),!1))};function Oe(e){return e.replace(/"<start>([\s\S]*?)<\/end>"/g,"$1")}function we(e){let t=e;for(;;){const e=Oe(t);if(e===t)break;t=e}return t}var Me=(e,t,n)=>e.replace(/\[([^\]]+)\]/g,":$1").replace("react"===n?t?".tsx":".jsx":".vue","");function ve(e){i.default.existsSync(e)||i.default.mkdirSync(e,{recursive:!0})}function Se(e,t){ve(c.default.dirname(e)),i.default.writeFileSync(e,t,"utf-8")}async function _e(e,t){const n=c.default.dirname(e);await i.default.promises.mkdir(n,{recursive:!0}),await i.default.promises.writeFile(e,t,"utf-8")}var Te="index.ts",Ee="index.js";Object.defineProperty(exports,"INDEX_JS_SUFFIX",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(exports,"INDEX_TS_SUFFIX",{enumerable:!0,get:function(){return Te}}),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 ve}}),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 U}}),Object.defineProperty(exports,"generateReactRoutesHMR",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"generateRoutesTemplate",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(exports,"generateUniqueComponentName",{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,"generateVueRoutes",{enumerable:!0,get:function(){return le}}),Object.defineProperty(exports,"generateVueRoutesHMR",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"getDefaultExportContent",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,"getRelativePath",{enumerable:!0,get:function(){return Re}}),Object.defineProperty(exports,"getRelativeProjectPath",{enumerable:!0,get:function(){return je}}),Object.defineProperty(exports,"hasDefaultExport",{enumerable:!0,get:function(){return xe}}),Object.defineProperty(exports,"hasDuplicateProperty",{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,"normalizePathWithWindows",{enumerable:!0,get:function(){return $e}}),Object.defineProperty(exports,"removeCustomTagFunctionFromJSXAll",{enumerable:!0,get:function(){return we}}),Object.defineProperty(exports,"replaceBracketsWithColon",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,"useTs",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"writeFile",{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,"writeFileSync",{enumerable:!0,get:function(){return Se}});
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,a=(a,i,c)=>(c=null!=a?e(r(a)):{},((e,r,a,i)=>{if(r&&"object"==typeof r||"function"==typeof r)for(var c,u=o(r),p=0,l=u.length;p<l;p++)c=u[p],s.call(e,c)||c===a||t(e,c,{get:(e=>r[e]).bind(null,c),enumerable:!(i=n(r,c))||i.enumerable});return e})(!i&&a&&a.__esModule?c:t(c,"default",{value:a,enumerable:!0}),a));let i=require("node:fs");i=a(i);let c=require("node:path");c=a(c);let u=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}u=a(u);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(c.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?c.default.resolve(t,o):c.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=c.default.extname(e),n=c.default.basename(e,t),o=c.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"),"")||"/"},_=async(e,t,n,o,r,s)=>{const a=[];for(const[i,c]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 u=Me(S(i,`/${n}`,o)||"/",o,"react"),p=M(u,r,s),{path:l,...h}=c;a.push(Object.assign({path:p,isRoot:!s&&"/__root__"===u,element:e[t],...h},l?{replacePath:l}:{}))}return a},T=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(T)]}}return e.children?{...e,children:e.children.map(T)}:e},E=e=>(e=>e.map(T))((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("/"),c=t.get(i);c?(s.path=o[o.length-1],c.children.push(s)):n.push(s)}return n})(e)),k=e=>{const{isRoot:t,type:n,children:o,...r}=e;return o?.length?{...r,children:o.map(k)}:r},N=e=>{const{children:t}=e;if(!t?.length){const{children:t,...n}=e;return n}const n=t.map(N);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}},F=e=>k(N(e)),W=e=>E(e).map(F),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(Ce(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[n&&{...n,index:!0},...W(r)].filter(e=>Boolean(e)),a=[];return t&&a.push(k({...t,children:s})),o&&a.push(k(o)),a})(e);if(Ce(e,"path"))throw new Error("There cannot be duplicate paths in a route");return W(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 B=e=>e.map(e=>{if(!("replacePath"in e)&&!e.children?.length)return e;const{replacePath:t,children:n,...o}=e,r={...o};if(t)if(t.includes("[currentPath]")){const e=r.path;r.path=t.replace("[currentPath]",e)}else r.path=t;return n?.length&&(r.children=B(n)),r}),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?Te:Ee):e)(je(e,t),a),c=$e(Re(n,e)),u=me(C(c),s),p=`element(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},K=(e,t,n,o)=>{const r=je(e,t);n[`/${r}`]=g(r,Pe(e),o)};function H(e,t,n,o,r,s,a,i,c){const p={},l=e.replace(/^\/+/,""),h=u.default.sync(l,{cwd:t,absolute:!0,onlyFiles:!0}).filter(xe);for(const u of h)if("component"===r){if(u.includes(".config."))continue;I(u,n,o,p,s,a,c)}else K(u,n,p,i);return p}var U=async(e,t,n,o,r,s,a,i)=>{const c=new Map,u=new Set,p=new Map;_e(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 we(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, '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(L(await _(H("/**/*.{jsx,tsx}",t,n,o,"component",c,u,p,s),H("/**/*.config.{js,ts,jsx,tsx}",t,n,o,"config",c,u,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,c),((e,t)=>{if(!e)return[];const n=[];for(const o of t.values())n.push(z(o.componentName,o.path).lazy);return n})(r,c),s),c,p,r))},V=(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),u=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 const { path: replacePath, ...rest } = page\n\n result.push(\n Object.assign(\n {\n path: routePath,\n type: page?.type,\n ${o?"":"isRoot: processedPath === '/__root__',\n "}element: Component,\n ...rest\n },\n (replacePath && { replacePath }) || {}\n )\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\n const { path: replacePath, ...rest } = page\n\n result.push(\n Object.assign(\n {\n path: routePath,\n type: page?.type,\n ${o?"":"isRoot: processedPath === '/__root__',\n "}element: <Component />,\n ...rest\n },\n (replacePath && { replacePath }) || {}\n )\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,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 replacePath?: string\n children?: MyRouteObject[]\n}\n\n${n?"":"type RouteWithIsRoot = MyRouteObject & { isRoot?: boolean }\n\n"}export type PageConfig = Partial<\n Omit<MyRouteObject, 'Component' | 'element' | 'children' | 'replacePath'>\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}\n\nexport const replacePaths = ${e?"(routes: MyRouteObject[]): RouteObject[]":"(routes)"} => {\n return routes.map(route => {\n if (!('replacePath' in route) && !route.children?.length) {\n return route${e?" as RouteObject":""}\n }\n\n const { replacePath, children, ...rest } = route\n const newRoute = { ...rest }\n\n if (replacePath) {\n if (replacePath.includes('[currentPath]')) {\n const currentPath = newRoute.path\n newRoute.path = replacePath.replace('[currentPath]', currentPath)\n } else {\n newRoute.path = replacePath\n }\n }\n\n if (children?.length) {\n ${e?";(newRoute as MyRouteObject)":"newRoute"}.children = replacePaths(\n children\n )${e?" as RouteObject[]":""}\n }\n\n return newRoute${e?" as RouteObject":""}\n })\n}`)(o),f,h,l,p,u,"\nconst getRoutes = () => {\n const baseRoutes = createBaseRoutes()\n return replacePaths(formatRoutes(baseRoutes))\n}\n\nexport const routes = getRoutes()");o?(_e(c.default.resolve(a,"./index.ts"),i),_e(c.default.resolve(a,"./autoRouter.tsx"),g),_e(c.default.resolve(a,"./defineConfig.ts"),d)):_e(t,g)},X={"/home":"/","/__root__":"/"},q=(e,t)=>{const n=e.split("/"),o=n[n.length-1];return t&&o.endsWith(t)?o.slice(0,-t.length):o},J=(e,t,n)=>{const o=((e,t,n)=>t&&"/home"===e?"/home":n&&"/__root__"===e?"/__root__":X[e])(e,t,n);return o||("/notfound"===e.toLowerCase()||"/404"===e?"/:pathMatch(.*)*":e)},Z=(e,t)=>e.endsWith(".config."+(t?"ts":"js"))?"index"===q(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")),G=(e,t,n)=>{if(e.endsWith(".config."+(n?"ts":"js"))){const o=q(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"),"")||"/"},Q=async(e,t,n,o,r,s)=>{const a=[];for(const[i,c]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=Z(i,o),u=Me(G(i,`/${n}`,o)||"/",o,"vue"),p=J(u,r,s),{path:l,...h}=c;a.push(Object.assign({path:p,isRoot:!s&&"/__root__"===u,component:e[t],...h},l?{replacePath:l}:{}))}return a},Y=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(Y)]}}return e.children?{...e,children:e.children.map(Y)}:e},ee=e=>(e=>e.map(Y))((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("/"),c=t.get(i);c?(s.path=o[o.length-1],c.children.push(s)):n.push(s)}return n})(e)),te=e=>{const{isRoot:t,type:n,children:o,...r}=e;return o?.length?{...r,children:o.map(te)}:r},ne=e=>{const{children:t}=e;if(!t?.length){const{children:t,...n}=e;return n}const n=t.map(ne);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}},oe=e=>te(ne(e)),re=e=>ee(e).map(oe),se=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(Ce(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[n,...re(r)].filter(e=>Boolean(e)),a=[];return t&&a.push(te({...t,children:s})),o&&a.push(te(o)),a})(e);if(Ce(e,"path"))throw new Error("There cannot be duplicate paths in a route");return re(e)},ae=(e,t)=>({import:`import ${e} from './${t}'`,component:`<start>${e}</end>`,lazyComponent:`<start>() => import('${t}')</end>`});var ie=e=>e.map(e=>{if(!("replacePath"in e)&&!e.children?.length)return e;const{replacePath:t,children:n,...o}=e,r={...o};if(t)if(t.includes("[currentPath]")){const e=r.path;r.path=t.replace("[currentPath]",e)}else r.path=t;return n?.length&&(r.children=ie(n)),r}),ce=(e,t,n,o,r,s,a)=>{const i=((e,t)=>e.replace("index.vue",t?Te:Ee))(je(e,t),a),c=$e(Re(n,e)),u=me(C(c),s),p=`component(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},ue=(e,t,n,o)=>{const r=je(e,t);n[`/${r}`]=g(r,Pe(e),o)};function pe(e,t,n,o,r,s,a,i,c){const p={},l=e.replace(/^\/+/,""),h=u.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(xe);for(const u of f)if("component"===r){if(u.includes(".config."))continue;ce(u,n,o,p,s,a,c)}else ue(u,n,p,i);return p}var le=async(e,t,n,o,r,s,a,i)=>{const c=new Map,u=new Set,p=new Map;_e(o,((e,t,n,o)=>{let r=e;for(const[s,a]of t){const e=ae(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 we(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, '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`}(ie(se(await Q(pe("/**/*.vue",t,n,o,"component",c,u,p,s),pe("/**/*.config.{js,ts}",t,n,o,"config",c,u,p,s),e,s,a,i))),((e,t)=>{if(e)return[];const n=[];for(const o of t.values())n.push(ae(o.componentName,o.path).import);return n})(r,c),s,r),c,p,r))},he=(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),u=((e,t,n,o,r)=>`\nconst pathCache = new Map${t?"<string, { compPath: string; basePath: string }>":""}()\nconst basenameCache = new Map${t?"<string, string>":""}()\n\nconst replacePaths = ${t?"(routes: MyRouteObject[]): RouteRecordRaw[]":"(routes)"} => {\n return routes.map(route => {\n if (!('replacePath' in route) && !route.children?.length) {\n return route${t?" as RouteRecordRaw":""}\n }\n\n const { replacePath, children, ...rest } = route\n const newRoute = { ...rest }\n\n if (replacePath) {\n if (replacePath.includes('[currentPath]')) {\n const currentPath = newRoute.path\n newRoute.path = replacePath.replace('[currentPath]', currentPath)\n } else {\n newRoute.path = replacePath\n }\n }\n\n if (children?.length) {\n ${t?";(newRoute as MyRouteObject)":"newRoute"}.children = replacePaths(children)\n }\n\n return newRoute${t?" as RouteRecordRaw":""}\n })\n}\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\n const { path: replacePath, ...rest } = content\n const formattedPath = formatPath(path)\n\n result.push(\n Object.assign(\n {\n path: formattedPath,\n component: pagesComponent[compPath],\n ${r?"":"isRoot: path === '/__root__',\n "}...rest\n },\n replacePath ? { replacePath } : {}\n )\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 replacePaths(handleRootRoute(routes))\n\n `}if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return replacePaths(processRoutes(routes))\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 replacePath?: string\n children?: MyRouteObject[]\n}\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'component' | 'children' | 'replacePath'>\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('.vue', '')\n}\n`)(o),h,l,p,u,"\nexport const routes = createRoutes()");o?(_e(c.default.resolve(a,"./index.ts"),i),_e(c.default.resolve(a,"./autoRouter.ts"),d),_e(c.default.resolve(a,"./defineConfig.ts"),f)):_e(t,d)},fe={react:{hmr:(e,t,n,o,r,s,a,i)=>V(e,o,r,s,a,i),normal:U},vue:{hmr:(e,t,n,o,r,s,a,i)=>he(e,o,r,s,a,i),normal:le}},de=[".js",".ts",".jsx",".tsx"],ge=(e,t,n,o,r,s,a,u)=>{const p=c.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 de)f(e+t);d(e)})(l.split(".")[0]),fe[e][u?"hmr":"normal"](t,p,n,l,a,P(n),r,s),console.log(`[ono-auto-router] Routes file generated: ${u?c.default.resolve(l.replace(".tsx","").replace(".ts",""),"./autoRouter"+("react"===e?".tsx":".ts")):l}`)},me=(e,t)=>{if(!t.has(e))return t.add(e),e;let n=1;for(;t.has(`${e}_${n}`);)n++;return`${e}_${n}`};function Pe(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 Re(e,t){let n=c.default.resolve(e);(n.endsWith(".js")||n.endsWith(".jsx")||n.endsWith(".ts")||n.endsWith(".tsx")||n.endsWith(".vue"))&&(n=c.default.dirname(n));const o=c.default.resolve(t);return c.default.relative(n,o)}var ye=/\\/g,$e=e=>e.replace(ye,"/"),je=(e,t)=>$e(c.default.relative(t,e)),be=/export\s+default\s+[\w(\[\]\{\})]+/;function xe(e){try{if(!i.default.existsSync(e))return console.warn(`File not found: ${e}`),!1;const t=i.default.readFileSync(e,"utf-8");return be.test(t)}catch(t){return console.error("Read error:",t),!1}}var Ce=(e,t)=>{const n=new Set;return e.some(e=>!!n.has(e[t])||(n.add(e[t]),!1))};function Oe(e){return e.replace(/"<start>([\s\S]*?)<\/end>"/g,"$1")}function we(e){let t=e;for(;;){const e=Oe(t);if(e===t)break;t=e}return t}var Me=(e,t,n)=>e.replace(/\[([^\]]+)\]/g,":$1").replace("react"===n?t?".tsx":".jsx":".vue","");function ve(e){i.default.existsSync(e)||i.default.mkdirSync(e,{recursive:!0})}function Se(e,t){ve(c.default.dirname(e)),i.default.writeFileSync(e,t,"utf-8")}async function _e(e,t){const n=c.default.dirname(e);await i.default.promises.mkdir(n,{recursive:!0}),await i.default.promises.writeFile(e,t,"utf-8")}var Te="index.ts",Ee="index.js";Object.defineProperty(exports,"INDEX_JS_SUFFIX",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(exports,"INDEX_TS_SUFFIX",{enumerable:!0,get:function(){return Te}}),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 ve}}),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 U}}),Object.defineProperty(exports,"generateReactRoutesHMR",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"generateRoutesTemplate",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(exports,"generateUniqueComponentName",{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,"generateVueRoutes",{enumerable:!0,get:function(){return le}}),Object.defineProperty(exports,"generateVueRoutesHMR",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"getDefaultExportContent",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,"getRelativePath",{enumerable:!0,get:function(){return Re}}),Object.defineProperty(exports,"getRelativeProjectPath",{enumerable:!0,get:function(){return je}}),Object.defineProperty(exports,"hasDefaultExport",{enumerable:!0,get:function(){return xe}}),Object.defineProperty(exports,"hasDuplicateProperty",{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,"normalizePathWithWindows",{enumerable:!0,get:function(){return $e}}),Object.defineProperty(exports,"removeCustomTagFunctionFromJSXAll",{enumerable:!0,get:function(){return we}}),Object.defineProperty(exports,"replaceBracketsWithColon",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,"useTs",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"writeFile",{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,"writeFileSync",{enumerable:!0,get:function(){return Se}});
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-C0hESLN4.js");exports.generateReactRoutesHMR=e.generateReactRoutesHMR;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-DCsVtd8W.js");exports.generateReactRoutesHMR=e.generateReactRoutesHMR;
@@ -1 +1 @@
1
- import{v as o}from"./core-Ce4vhkvz.js";export{o as generateReactRoutesHMR};
1
+ import{v as o}from"./core-CNIAH3cp.js";export{o as generateReactRoutesHMR};
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-C0hESLN4.js");exports.generateReactRoutes=e.generateReactRoutes;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-DCsVtd8W.js");exports.generateReactRoutes=e.generateReactRoutes;
@@ -1 +1 @@
1
- import{y as o}from"./core-Ce4vhkvz.js";export{o as generateReactRoutes};
1
+ import{y as o}from"./core-CNIAH3cp.js";export{o as generateReactRoutes};
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-C0hESLN4.js");exports.generateVueRoutesHMR=e.generateVueRoutesHMR;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-DCsVtd8W.js");exports.generateVueRoutesHMR=e.generateVueRoutesHMR;
@@ -1 +1 @@
1
- import{g as o}from"./core-Ce4vhkvz.js";export{o as generateVueRoutesHMR};
1
+ import{g as o}from"./core-CNIAH3cp.js";export{o as generateVueRoutesHMR};
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-C0hESLN4.js");exports.generateVueRoutes=e.generateVueRoutes;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-DCsVtd8W.js");exports.generateVueRoutes=e.generateVueRoutes;
@@ -1 +1 @@
1
- import{_ as o}from"./core-Ce4vhkvz.js";export{o as generateVueRoutes};
1
+ import{_ as o}from"./core-CNIAH3cp.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-C0hESLN4.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)}}};
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core-DCsVtd8W.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.js CHANGED
@@ -1 +1 @@
1
- import{h as e,w as o}from"./core-Ce4vhkvz.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};
1
+ import{h as e,w as o}from"./core-CNIAH3cp.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-C0hESLN4.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)}}};
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core-DCsVtd8W.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.js CHANGED
@@ -1 +1 @@
1
- import{h as e,w as o}from"./core-Ce4vhkvz.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};
1
+ import{h as e,w as o}from"./core-CNIAH3cp.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-C0hESLN4.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-DCsVtd8W.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.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-Ce4vhkvz.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-CNIAH3cp.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-C0hESLN4.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)}}};
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core-DCsVtd8W.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.js CHANGED
@@ -1 +1 @@
1
- import{h as e,w as o}from"./core-Ce4vhkvz.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};
1
+ import{h as e,w as o}from"./core-CNIAH3cp.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.5",
3
+ "version": "0.3.6",
4
4
  "description": "a vite plugin for automatically generating react or vue route files",
5
5
  "keywords": [
6
6
  "auto-router",