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

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,l[e][p(t)?"ts":"js"])),r},f=/[/\\]/,g=/[^a-zA-Z0-9]/g,d=/^(\d)/,m=e=>e?e.charAt(0).toUpperCase()+e.slice(1).toLowerCase():"";function R(e){const t=n.extname(e),o=n.basename(e,t),r=n.dirname(e).split(f).filter(Boolean);return"index"!==o&&"Index"!==o&&r.push(o),r.map(e=>(e=>e.replace(g,"_").replace(d,"_$1"))(e).split("_").map(m).join("")).join("")||"Component"}var P={"/home":"/","/root":"/"},y=(e,n)=>{const t=e.split("/"),o=t[t.length-1];return n&&o.endsWith(n)?o.slice(0,-n.length):o},$=e=>{const n=P[e];return n||("/notfound"===e.toLowerCase()||"/404"===e?"/*":e)},j=(e,n)=>e.endsWith(".config."+(n?"ts":"js"))?"index"===y(e,".config."+(n?"ts":"js"))?e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")):e.slice(0,-10)+"."+(n?"tsx":"jsx"):e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")),x=(e,n,t)=>{if(e.endsWith(".config."+(t?"ts":"js"))){const o=y(e,".config."+(t?"ts":"js")),r=(e=>{const n=e.split("/");return n.pop(),n.join("/")})(e).replace(n,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(n,"").replace("/index.config."+(t?"ts":"js"),"")||"/"},C=async(e,n,t,o)=>{const r=[];for(const[s,a]of((e,n,t)=>Object.keys(e).map(e=>{const o=((e,n)=>e.endsWith(n?".tsx":".jsx")?e.slice(0,-4)+".config."+(n?"ts":"js"):e.replace("index."+(n?"ts":"js"),"index.config."+(n?"ts":"js")))(e,t);return[o,n[o]||{}]}))(e,n,o)){const n=j(s,o);if(!e[n])continue;const i=me(x(s,`/${t}`,o)||"/",o,"react"),c=$(i);r.push({...a,path:c,type:a?.type,isRoot:"/root"===i,element:e[n]})}return r},b=e=>{if(e.index)return e;if("wrap"!==e.type){const{path:n,children:t,...o}=e;if(Object.keys(o).length>0)return{path:n,children:[{path:"",index:!0,...o},...(t||[]).map(b)]}}return e.children?{...e,children:e.children.map(b)}:e},w=e=>(e=>e.map(b))((e=>{const n=/* @__PURE__ */new Map,t=[],o=/* @__PURE__ */new Map,r=e=>{let n=o.get(e);return void 0===n&&(n="/"===e?[]:e.split("/").filter(Boolean),o.set(e,n)),n},s=e.slice().sort((e,n)=>e.path.length-n.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(n.set(e,s),o.length<=1){t.push(s);continue}const i="/"+o.slice(0,-1).join("/"),c=n.get(i);c?(s.path=o[o.length-1],c.children.push(s)):t.push(s)}return t})(e)),M=e=>{const{isRoot:n,type:t,children:o,...r}=e;return o?.length?{...r,children:o.map(M)}:r},O=e=>{const{children:n}=e;if(!n?.length){const{children:n,...t}=e;return t}const t=n.map(O);if("wrap"===e.type)return{...e,children:t};const{path:o,element:r,type:s,children:a,...i}=e;return r?{path:o,children:[{index:!0,element:r,...i},...t]}:{path:o,...i,children:t}},v=e=>M(O(e)),S=e=>w(e).map(v),T=e=>{if(e.some(e=>e.isRoot))return(e=>{let n,t,o;const r=[];for(const i of e)if(i.isRoot){if(n)throw new Error("There cannot be multiple root routes in a route");n=i}else"/"===i.path?t=i:"/*"===i.path?o=i:r.push(i);if(fe(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[t&&{...t,index:!0},...S(r)].filter(e=>Boolean(e)),a=[];return n&&a.push(M({...n,children:s})),o&&a.push(M(o)),a})(e);if(fe(e,"path"))throw new Error("There cannot be duplicate paths in a route");return S(e)},k=(e,n)=>({import:`import ${e} from './${n}'`,component:`<start><${e} /></end>`,lazy:`const ${e} = lazy(() => import('${n}'))`,lazyComponent:`<start><Suspense><${e} /></Suspense></end>`});var E="index.tsx",N="index.jsx",F=(e,n,t,o,r,s,a)=>{const i=((e,n)=>e.includes(n?E:N)?e.replace(n?E:N,n?$e:je):e)(pe(e,n),a),c=ue(ie(t,e)),u=se(R(c),s),p=`element(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},W=(e,n,t,o)=>{const r=pe(e,n);t[`/${r}`]=c(r,ae(e),o)};function L(e,n,o,r,s,a,i,c,u){const p={},l=e.replace(/^\/+/,""),h=t.sync(l,{cwd:n,absolute:!0,onlyFiles:!0}).filter(he);for(const t of h)if("component"===s){if(t.includes(".config."))continue;F(t,o,r,p,a,i,u)}else W(t,o,p,c);return p}var B=async(e,n,t,o,r,s)=>{const a=/* @__PURE__ */new Map,i=/* @__PURE__ */new Set,c=/* @__PURE__ */new Map;ye(o,((e,n,t,o)=>{let r=e;for(const[s,a]of n){const e=k(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of t)r=r.replace(s,a);return de(r)})(function(e,n,t,o){const r=t.length>0?`\n${t.join("\n")}\n`:"";return`// Auto-generated by ono-auto-router\n${o?"import type { RouteObject } from 'react-router-dom'\n":""}${n.join("\n")}${o?"\n\ntype PageConfig = Partial<\n Omit<RouteObject, 'path' | 'Component' | 'element' | 'children'> & {\n type?: 'single' | 'wrap'\n }\n>\n":""}${o?"\nexport const defineConfig = (config: PageConfig) => config":""}\n${r}\nexport const routes${o?": RouteObject[]":""} = ${JSON.stringify(e,null,2)}\n`}(T(await C(L("/**/*.{jsx,tsx}",n,t,o,"component",a,i,c,s),L("/**/*.config.{js,ts,jsx,tsx}",n,t,o,"config",a,i,c,s),e,s)),((e,n)=>{if(e)return["import { lazy, Suspense } from 'react'"];const t=[];for(const o of n.values())t.push(k(o.componentName,o.path).import);return t})(r,a),((e,n)=>{if(!e)return[];const t=[];for(const o of n.values())t.push(k(o.componentName,o.path).lazy);return t})(r,a),s),a,c,r))},z=(e,t,o,r)=>{const s=t.split(".")[0],a=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(r),i=o?((e,n)=>`\nconst PATH_REPLACEMENTS${n?": Record<string, string>":""} = {\n '/home': '/',\n '/root': '/'\n}\n\nconst cachedLazyComponents${n?": Record<\n string,\n LazyExoticComponent<ComponentType<unknown>>\n>":""} = {}\n\nconst getConfigFileName = ${n?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${n?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${n?"ts":"js"}'\n }\n return pagePath.replace('index.${n?"ts":"js"}', 'index.config.${n?"ts":"js"}')\n}\n\nconst formatPageModule = (${n?"\n pagesComponent: Record<string, ComponentType<unknown>>,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${n?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${n?"(pathStr: string): string":"(pathStr)"} => {\n if (PATH_REPLACEMENTS[pathStr]) {\n return PATH_REPLACEMENTS[pathStr]\n }\n\n const lowerPath = pathStr.toLowerCase()\n if (lowerPath === '/notfound' || pathStr === '/404') {\n return '/*'\n }\n\n return pathStr\n}\n\nconst getBasename = ${n?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1]\n if (ext && lastPart.endsWith(ext)) {\n return lastPart.slice(0, -ext.length)\n }\n return lastPart\n}\n\nconst getDirname = ${n?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${n?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n if (fileName === 'index') {\n return dirPath || '/'\n }\n return dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n return (\n configPath.replace('/${e}', '').replace('/index.config.${n?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${n?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${n?": Record<string, unknown>":""} = {}\n\n for (const [path, module] of Object.entries(modules)) {\n if ('default' in module) {\n result[path] = module.default\n }\n }\n\n return result\n}\n\nconst filterUnComponent = ${n?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${n?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${n?"tsx":"jsx"}')) {\n result[key] = pagesComponent[key]\n }\n }\n\n return result\n}\n\nconst LazyComponent = ({\n Element\n}${n?": {\n Element: LazyExoticComponent<ComponentType<unknown>>\n}":""}) => {\n return (\n <Suspense>\n <Element />\n </Suspense>\n )\n}\n\nconst createBaseRoutes = () => {\n const pagesComponent = filterUnComponent({\n ...import.meta.glob('/${e}/**/*.${n?"tsx":"jsx"}')${n?" as PagesComponentType":""}\n })\n\n const pagesString = getFileDefault({\n ...import.meta.glob('/${e}/**/*.${n?"tsx":"jsx"}', {\n eager: true\n })\n })${n?" as Record<string, ComponentType<unknown>>":""}\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${n?"ts":"js"}', {\n eager: true\n })\n })${n?" as Record<string, PageConfig>":""}\n\n const result${n?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const [pagePath, page] of formatPageModule(pagesString, pagesModule)) {\n const compPath = getCompPathFromConfig(pagePath)\n\n if (!pagesComponent[compPath]) continue\n\n const rawPath = getRawPathFromConfig(pagePath) || '/'\n const processedPath = replaceBracketsWithColon(rawPath)\n const routePath = normalizePath(processedPath)\n\n let Component${n?": MyRouteObject['element']":""}\n if (!cachedLazyComponents[compPath]) {\n cachedLazyComponents[compPath] = lazy(pagesComponent[compPath])\n }\n Component = <LazyComponent Element={cachedLazyComponents[compPath]} />\n\n result.push({\n ...page,\n path: routePath,\n type: page?.type,\n isRoot: processedPath === '/root',\n element: Component\n })\n }\n\n return result\n}`)(e,r):((e,n)=>`\nconst PATH_REPLACEMENTS${n?": Record<string, string>":""} = {\n '/home': '/',\n '/root': '/'\n}\n\nconst getConfigFileName = ${n?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${n?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${n?"ts":"js"}'\n }\n return pagePath.replace('index.${n?"ts":"js"}', 'index.config.${n?"ts":"js"}')\n}\n\nconst formatPageModule = (${n?"\n pagesComponent: PagesComponentType,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${n?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${n?"(pathStr: string): string":"(pathStr)"} => {\n if (PATH_REPLACEMENTS[pathStr]) {\n return PATH_REPLACEMENTS[pathStr]\n }\n\n const lowerPath = pathStr.toLowerCase()\n if (lowerPath === '/notfound' || pathStr === '/404') {\n return '/*'\n }\n\n return pathStr\n}\n\nconst getBasename = ${n?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1]\n if (ext && lastPart.endsWith(ext)) {\n return lastPart.slice(0, -ext.length)\n }\n return lastPart\n}\n\nconst getDirname = ${n?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${n?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n if (fileName === 'index') {\n return dirPath || '/'\n }\n return dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n return (\n configPath.replace('/${e}', '').replace('/index.config.${n?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${n?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${n?": PagesComponentType | Record<string, PageConfig>":""} = {}\n\n for (const [path, module] of Object.entries(modules)) {\n if ('default' in module) {\n result[path] = module.default${n?" as ComponentType<unknown> | PageConfig":""}\n }\n }\n\n return result\n}\n\nconst filterUnComponent = ${n?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${n?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${n?"tsx":"jsx"}')) {\n result[key] = pagesComponent[key]\n }\n }\n\n return result\n}\n\nconst createBaseRoutes = () => {\n const pagesComponent = filterUnComponent(\n getFileDefault({\n ...import.meta.glob('/${e}/**/*.${n?"tsx":"jsx"}', { eager: true })\n })${n?" as PagesComponentType":""}\n )\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${n?"ts":"js"}', {\n eager: true\n })\n })${n?" as Record<string, PageConfig>":""}\n\n const result${n?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const [pagePath, page] of formatPageModule(pagesComponent, pagesModule)) {\n const compPath = getCompPathFromConfig(pagePath)\n\n if (!pagesComponent[compPath]) continue\n\n const rawPath = getRawPathFromConfig(pagePath) || '/'\n const processedPath = replaceBracketsWithColon(rawPath)\n const routePath = normalizePath(processedPath)\n\n const Component = pagesComponent[compPath]\n result.push({\n ...page,\n path: routePath,\n type: page?.type,\n isRoot: processedPath === '/root',\n element: <Component />\n })\n }\n\n return result\n}`)(e,r),c=(e=>`\nconst processRoute = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} =>\n cleanIsRoot(removeEmptyChildren(route))\n\nconst processRoutes = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} =>\n buildRouteTree(routes).map(processRoute)\n\nconst handleRootRoute = ${e?"(routes: (MyRouteObject & { isRoot?: boolean })[])":"(routes)"} => {\n let rootRoute${e?": MyRouteObject | undefined":" = undefined"}\n let homeRoute${e?": MyRouteObject | undefined":" = undefined"}\n let notFoundRoute${e?": MyRouteObject | undefined":" = undefined"}\n const filteredRoutes${e?": MyRouteObject[]":""} = []\n\n for (const route of routes) {\n if (route.isRoot) {\n if (rootRoute)\n throw new Error('There cannot be multiple root routes in a route')\n rootRoute = route\n } else if (route.path === '/') {\n homeRoute = route\n } else if (route.path === '/*') {\n notFoundRoute = route\n } else {\n filteredRoutes.push(route)\n }\n }\n\n if (hasDuplicateProperty(filteredRoutes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n const children = [\n homeRoute && { ...homeRoute, index: true },\n ...processRoutes(filteredRoutes)\n ].filter(${e?"(route): route is NonNullable<typeof route> => Boolean(route)":"Boolean"})\n\n const result${e?": MyRouteObject[]":""} = []\n\n if (rootRoute) {\n result.push(cleanIsRoot({ ...rootRoute, children }))\n }\n\n if (notFoundRoute) {\n result.push(cleanIsRoot(notFoundRoute))\n }\n\n return result\n}\n\nconst formatRoutes = (\n routes${e?": (MyRouteObject & { isRoot?: boolean })[]":""}\n) => {\n if (routes.some(r => r.isRoot)) return handleRootRoute(routes)\n\n if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return processRoutes(routes)\n}`)(r),u=(e=>`\nconst processSingleRoute = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n if (route.index) {\n return route\n }\n\n if (route.type !== 'wrap') {\n const { path: routePath, children, ...extraProps } = route\n const hasExtraProps = Object.keys(extraProps).length > 0\n\n if (hasExtraProps) {\n const indexRoute${e?": MyRouteObject":""} = {\n path: '',\n index: true,\n ...extraProps\n }\n\n return {\n path: routePath,\n children: [indexRoute, ...(children || []).map(processSingleRoute)]\n }\n }\n }\n\n if (route.children) {\n return {\n ...route,\n children: route.children.map(processSingleRoute)\n }\n }\n\n return route\n}\n\nconst formatRouteTree = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n return routes.map(processSingleRoute)\n}\n\nconst buildTreeStructure = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n const routeMap = new Map${e?"<string, MyRouteObject>":""}()\n const rootRoutes${e?": MyRouteObject[]":""} = []\n const pathPartsCache = new Map${e?"<string, string[]>":""}()\n\n const getPathParts = ${e?"(pathStr: string): string[]":"(pathStr)"} => {\n let parts = pathPartsCache.get(pathStr)\n if (parts === undefined) {\n parts = pathStr === '/' ? [] : pathStr.split('/').filter(Boolean)\n pathPartsCache.set(pathStr, parts)\n }\n return parts\n }\n\n const sortedRoutes = routes\n .slice()\n .sort((a, b) => a.path.length - b.path.length)\n\n for (const route of sortedRoutes) {\n const routePath = route.path\n const pathParts = getPathParts(routePath)\n const currentRoute = { ...route, children: [] }\n routeMap.set(routePath, currentRoute)\n\n if (pathParts.length <= 1) {\n rootRoutes.push(currentRoute)\n continue\n }\n\n const parentPath = '/' + pathParts.slice(0, -1).join('/')\n const parentRoute = routeMap.get(parentPath)\n\n if (parentRoute) {\n currentRoute.path = pathParts[pathParts.length - 1]\n parentRoute.children${e?"!":""}.push(currentRoute)\n } else {\n rootRoutes.push(currentRoute)\n }\n }\n\n return rootRoutes\n}\n\nconst buildRouteTree = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n const treeStructure = buildTreeStructure(routes)\n return formatRouteTree(treeStructure)\n}`)(r),p=(e=>`\nconst cleanIsRoot = ${e?"(route: RouteWithIsRoot): MyRouteObject":"(route)"} => {\n const { isRoot, type, children, ...rest } = route${e?" as RouteWithIsRoot & {\n type?: unknown\n }":""}\n\n if (!children?.length) {\n return rest\n }\n\n return {\n ...rest,\n children: children.map(cleanIsRoot)\n }\n}`)(r),l=(e=>`\nconst removeEmptyChildren = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n const { children } = route\n\n if (!children?.length) {\n const { children: _, ...rest } = route\n return rest\n }\n\n const processedChildren = children.map(removeEmptyChildren)\n\n if (route.type === 'wrap') {\n return { ...route, children: processedChildren }\n }\n\n const { path, element, type, children: _, ...rest } = route\n\n if (!element) {\n return { path, ...rest, children: processedChildren }\n }\n\n return {\n path,\n children: [\n { index: true, element, ...rest }${e?" as MyRouteObject":""},\n ...processedChildren\n ]\n }\n}`)(r),h=r?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",f=(e=>`\nconst getRoutes = () => {\n const baseRoutes = createBaseRoutes()\n const formattedRoutes = formatRoutes(baseRoutes)${e?" as RouteObject[]":""}\n return formattedRoutes\n}\n\nexport const routes = getRoutes()`)(r),g=((e,n,t,o,r,s,a,i)=>`// Auto-generated by ono-auto-router${e}${n}${t}${o}${r}${s}${a}${i}\n`)(((e,n)=>e?`\n${n?"import {\n lazy,\n Suspense,\n type ComponentType,\n type LazyExoticComponent\n} from 'react'":"import type { ComponentType } from 'react'"}\nimport type { RouteObject } from 'react-router-dom'\n\n${n?"type PagesComponentType = Record<\n string,\n () => Promise<{ default: ComponentType<unknown> }>\n>":"type PagesComponentType = Record<string, ComponentType<unknown>>"}\n\ninterface MyRouteObject extends Omit<RouteObject, 'path' | 'children'> {\n path: string\n type?: 'single' | 'wrap'\n children?: MyRouteObject[]\n}\n\ntype RouteWithIsRoot = MyRouteObject & { isRoot?: boolean }\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'Component' | 'element' | 'children' | 'path'>\n>`:n?"\nimport { lazy, Suspense } from 'react'\n":"")(r,o),(e=>`\nconst hasDuplicateProperty = ${e?"<T, K extends keyof T>(items: T[], propName: K)":"(items, propName)"} => {\n const seenValues = new Set()\n return items.some(item => {\n if (seenValues.has(item[propName])) {\n return true\n }\n seenValues.add(item[propName])\n return false\n })\n}\n\nconst replaceBracketsWithColon = ${e?"(str: string)":"(str)"} => {\n return str.replace(/\\[([^\\]]+)\\]/g, ':$1').replace('.tsx', '')\n}`)(r),l,p,u,c,i,f);r?(ye(n.resolve(s,"./index.ts"),a),ye(n.resolve(s,"./autoRouter.tsx"),g),ye(n.resolve(s,"./defineConfig.ts"),h)):ye(t,g)},A={"/home":"/","/root":"/"},I=(e,n)=>{const t=e.split("/"),o=t[t.length-1];return n&&o.endsWith(n)?o.slice(0,-n.length):o},D=e=>{const n=A[e];return n||("/notfound"===e.toLowerCase()||"/404"===e?"/:pathMatch(.*)*":e)},K=(e,n)=>e.endsWith(".config."+(n?"ts":"js"))?"index"===I(e,".config."+(n?"ts":"js"))?e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")):e.slice(0,-10)+".vue":e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")),_=(e,n,t)=>{if(e.endsWith(".config."+(t?"ts":"js"))){const o=I(e,".config."+(t?"ts":"js")),r=(e=>{const n=e.split("/");return n.pop(),n.join("/")})(e).replace(n,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(n,"").replace("/index.config."+(t?"ts":"js"),"")||"/"},H=async(e,n,t,o)=>{const r=[];for(const[s,a]of((e,n,t)=>Object.keys(e).map(e=>{const o=((e,n)=>e.replace("index."+(n?"ts":"js"),"index.config."+(n?"ts":"js")))(e,t);return[o,n[o]||{}]}))(e,n,o)){const n=K(s,o),i=me(_(s,`/${t}`,o)||"/",o,"vue"),c=D(i);r.push({...a,path:c,type:a?.type,isRoot:"/root"===i,component:e[n]})}return r},V=e=>{if(!e.path)return e;if("wrap"!==e.type){const{path:n,children:t,...o}=e;if(Object.keys(o).length>0)return{path:n,children:[{path:"",...o},...(t||[]).map(V)]}}return e.children?{...e,children:e.children.map(V)}:e},U=e=>(e=>e.map(V))((e=>{const n=/* @__PURE__ */new Map,t=[],o=/* @__PURE__ */new Map,r=e=>{let n=o.get(e);return void 0===n&&(n="/"===e?[]:e.split("/").filter(Boolean),o.set(e,n)),n},s=e.slice().sort((e,n)=>e.path.length-n.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(n.set(e,s),o.length<=1){t.push(s);continue}const i="/"+o.slice(0,-1).join("/"),c=n.get(i);c?(s.path=o[o.length-1],c.children.push(s)):t.push(s)}return t})(e)),J=e=>{const{isRoot:n,type:t,children:o,...r}=e;return o?.length?{...r,children:o.map(J)}:r},Z=e=>{const{children:n}=e;if(!n?.length){const{children:n,...t}=e;return t}const t=n.map(Z);if("wrap"===e.type)return{...e,children:t};const{path:o,component:r,type:s,children:a,...i}=e;return r?{path:o,children:[{path:"",component:r,...i},...t]}:{path:o,...i,children:t}},q=e=>J(Z(e)),G=e=>U(e).map(q),Q=e=>{if(e.some(e=>e.isRoot))return(e=>{let n,t,o;const r=[];for(const i of e)if(i.isRoot){if(n)throw new Error("There cannot be multiple root routes in a route");n=i}else"/"===i.path?t=i:"/:pathMatch(.*)*"===i.path?o=i:r.push(i);if(fe(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[t&&{...t,index:!0},...G(r)].filter(e=>Boolean(e)),a=[];return n&&a.push(J({...n,children:s})),o&&a.push(J(o)),a})(e);if(fe(e,"path"))throw new Error("There cannot be duplicate paths in a route");return G(e)},X=(e,n)=>({import:`import ${e} from './${n}'`,component:`<start>${e}</end>`,lazyComponent:`<start>() => import('${n}')</end>`});var Y=(e,n,t,o,r,s,a)=>{const i=((e,n)=>e.replace("index.vue",n?$e:je))(pe(e,n),a),c=ue(ie(t,e)),u=se(R(c),s),p=`component(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},ee=(e,n,t,o)=>{const r=pe(e,n);t[`/${r}`]=c(r,ae(e),o)};function ne(e,n,o,r,s,a,i,c,u){const p={},l=e.replace(/^\/+/,""),h=t.sync(l,{cwd:n,absolute:!0,onlyFiles:!0}),f="component"===s?((e,n)=>n.map(n=>n.includes("index.vue")||2===n.replace(e.replaceAll("\\","/"),"").split("/").length?n:void 0).filter(Boolean))(n,h):h.filter(he);for(const t of f)if("component"===s){if(t.includes(".config."))continue;Y(t,o,r,p,a,i,u)}else ee(t,o,p,c);return p}var te=async(e,n,t,o,r,s)=>{const a=/* @__PURE__ */new Map,i=/* @__PURE__ */new Set,c=/* @__PURE__ */new Map;ye(o,((e,n,t,o)=>{let r=e;for(const[s,a]of n){const e=X(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of t)r=r.replace(s,a);return de(r)})(function(e,n,t,o){return`// Auto-generated by ono-auto-router${t?"\nimport type { RouteRecordRaw } from 'vue-router'":""}${o?"":`\n${n.join("\n")}${t?"":"\n"}`}${t?"\n\ntype PageConfig = Partial<\n Omit<RouteRecordRaw, 'path' | 'component' | 'children'> & {\n type?: 'single' | 'wrap'\n }\n>\n":""}${t?"\nexport const defineConfig = (config: PageConfig) => config\n":""}\nexport const routes${t?": RouteRecordRaw[]":""} = ${JSON.stringify(e,null,2)}\n`}(Q(await H(ne("/**/*.vue",n,t,o,"component",a,i,c,s),ne("/**/*.config.{js,ts}",n,t,o,"config",a,i,c,s),e,s)),((e,n)=>{if(e)return[];const t=[];for(const o of n.values())t.push(X(o.componentName,o.path).import);return t})(r,a),s,r),a,c,r))},oe=(e,t,o,r)=>{const s=t.split(".")[0],a=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(o),i=((e,n,t)=>`\nconst pathCache = new Map${n?"<string, { compPath: string; basePath: string }>":""}()\nconst basenameCache = new Map${n?"<string, string>":""}()\n\nconst normalizePagePath = ${n?"(key: string): string":"(key)"} => {\n if (key.includes('index.vue')) return key.replace('index.vue', 'index.${n?"ts":"js"}')\n if (key.includes('root.vue')) return key.replace('root.vue', 'root/index.${n?"ts":"js"}')\n if (key.includes('404.vue')) return key.replace('404.vue', '404/index.${n?"ts":"js"}')\n if (key.toLowerCase().includes('notfound.vue'))\n return key.toLowerCase().replace('notfound.vue', 'notfound/index.${n?"ts":"js"}')\n return key\n}\n\nconst getBasename = ${n?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const cacheKey = ext ? filePath + ':' + ext : filePath\n if (basenameCache.has(cacheKey)) {\n return basenameCache.get(cacheKey)${n?"!":""}\n }\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1] || ''\n let result = lastPart\n if (ext && lastPart.endsWith(ext)) {\n result = lastPart.slice(0, -ext.length)\n }\n basenameCache.set(cacheKey, result)\n return result\n}\n\nconst getDirname = ${n?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getPathsFromConfig = ${n?"(configPath: string)":"(configPath)"} => {\n const cacheKey = configPath\n if (pathCache.has(cacheKey)) {\n return pathCache.get(cacheKey)${n?"!":""}\n }\n\n let compPath${n?": string":" = ''"}\n let basePath${n?": string":" = ''"}\n\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n\n if (fileName === 'index') {\n compPath = configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"ts":"js"}')\n basePath = dirPath || '/'\n } else {\n compPath = configPath.slice(0, -10) + '.vue'\n basePath = dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n } else {\n compPath = configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"ts":"js"}')\n basePath =\n configPath.replace('/${e}', '').replace('/index.config.${n?"ts":"js"}', '') ||\n '/'\n }\n\n const result = { compPath, basePath }\n pathCache.set(cacheKey, result)\n return result\n}\n\nconst formatPath = ${n?"(path: string): string":"(path)"} => {\n const lowerPath = path.toLowerCase()\n if (lowerPath === '/home') return '/'\n if (lowerPath === '/notfound' || path === '/404') return '/:pathMatch(.*)*'\n return path.replace('/index.${n?"ts":"js"}', '') || '/'\n}\n\nconst getConfigFileName = ${n?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.vue')) {\n return pagePath.slice(0, -4) + '.config.${n?"ts":"js"}'\n }\n return pagePath.replace('index.${n?"ts":"js"}', 'index.config.${n?"ts":"js"}')\n}\n\nconst createBaseRoutes = ()${n?": MyRouteObject[]":""} => {\n const pagesComponent = Object.fromEntries(\n Object.entries({\n ...import.meta.glob('/${e}/**/index.vue'${t?"":", { eager: true, import: 'default' }"}),\n ...import.meta.glob('/${e}/*.vue'${t?"":", { eager: true, import: 'default' }"})\n }${n?" as PagesComponentType":""}).map(([key, value]) => [\n normalizePagePath(key),\n value\n ])\n )\n\n const pagesModule${n?": Record<string, PageConfig>":""} = import.meta.glob(\n '/${e}/**/*.config.${n?"ts":"js"}',\n { eager: true, import: 'default' }\n )\n\n const result${n?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const pagePath of Object.keys(pagesComponent)) {\n const configPath = getConfigFileName(pagePath)\n const content = pagesModule[configPath] || {}\n const { compPath, basePath } = getPathsFromConfig(configPath)\n const path = replaceBracketsWithColon(basePath || '/')\n const name = path.split('/').filter(Boolean).join('-') || 'index'\n\n result.push({\n path: formatPath(path),\n name,\n component: pagesComponent[compPath],\n isRoot: path === '/root',\n ...content${n?"!":""}\n })\n }\n\n return result\n}\n\nconst processRoutes = ${n?"(\n routes: MyRouteObject[],\n removeLeadingSlash = false\n): MyRouteObject[]":"(routes, removeLeadingSlash)"} =>\n buildRouteTree(routes, removeLeadingSlash)\n .map(removeEmptyChildren)\n .map(cleanIsRoot)\n\nconst handleRootRoute = ${n?"(\n routes: (MyRouteObject & { isRoot?: boolean })[]\n): MyRouteObject[]":"(routes)"} => {\n let rootRoute${n?": (MyRouteObject & { isRoot?: boolean }) | undefined":" = undefined"}\n let homeRoute${n?": MyRouteObject | undefined":" = undefined"}\n let notFoundRoute${n?": MyRouteObject | undefined":" = undefined"}\n const filteredRoutes${n?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const route of routes) {\n if (route.isRoot) {\n if (rootRoute)\n throw new Error('There cannot be multiple root routes in a route')\n rootRoute = route\n } else if (route.path === '/') {\n homeRoute = route\n } else if (route.path === '/:pathMatch(.*)*') {\n notFoundRoute = route\n } else {\n filteredRoutes.push(route)\n }\n }\n\n if (hasDuplicateProperty(filteredRoutes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n const processedRoutes${n?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n if (rootRoute) {\n const children = [\n homeRoute && { ...homeRoute, path: '' },\n ...processRoutes(filteredRoutes, true)\n ].filter(Boolean)${n?" as MyRouteObject[]":""}\n processedRoutes.push({ ...rootRoute, path: '/', children })\n }\n\n if (notFoundRoute) processedRoutes.push(notFoundRoute)\n\n return processedRoutes.map(cleanIsRoot)\n}\n\nconst createRoutes = ()${n?": RouteRecordRaw[]":""} => {\n const routes = createBaseRoutes()\n\n if (routes.some((r${n?": MyRouteObject & { isRoot?: boolean }":""}) => r.isRoot))\n return handleRootRoute(routes)${n?" as RouteRecordRaw[]":""}\n\n if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return processRoutes(routes)${n?" as RouteRecordRaw[]":""}\n}\n`)(e,o,r),c=(e=>`\nconst buildRouteTree = ${e?"(\n routes: MyRouteObject[],\n removeLeadingSlash: boolean = false\n)":"(routes, removeLeadingSlash)"} => {\n const routeMap = new Map${e?"<string, MyRouteObject & { isRoot?: boolean }>":""}()\n const rootRoutes${e?": MyRouteObject[]":""} = []\n\n const sortedRoutes = [...routes].sort((a, b) => a.path.length - b.path.length)\n\n for (const route of sortedRoutes) {\n let path = route.path\n if (removeLeadingSlash && path.startsWith('/')) {\n path = path.slice(1)\n }\n routeMap.set(path, { ...route, path, children: [] })\n }\n\n for (const [path, route] of routeMap) {\n const slashIndex = path.lastIndexOf('/')\n\n if (slashIndex <= 0) {\n const { isRoot, ...rest } = route\n rootRoutes.push(rest)\n continue\n }\n\n const parentPath = path.slice(0, slashIndex)\n const parentRoute = routeMap.get(parentPath)\n\n if (parentRoute) {\n const relativePath = path.slice(slashIndex + 1)\n const childRoute = { ...route, path: relativePath }\n parentRoute.children${e?"!":""}.push(childRoute)\n } else {\n const { isRoot, ...rest } = route\n rootRoutes.push(rest)\n }\n }\n\n return rootRoutes\n}\n`)(o),u=(e=>`\nconst cleanIsRoot = ${e?"(\n route: MyRouteObject & { isRoot?: boolean }\n): MyRouteObject":"(route)"} => {\n const { isRoot, type, children, ...rest } = route\n const result${e?": MyRouteObject":""} = { ...rest }\n\n if (children?.length) {\n result.children = children.map(cleanIsRoot)\n }\n\n return result\n}\n`)(o),p=(e=>`\nconst removeEmptyChildren = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n if (!route.children?.length) {\n const { children, ...rest } = route\n return rest\n }\n\n const hasIndexRoute = route.children.some(\n child => child.path === '' || child.path === '/'\n )\n\n const routeType = route.type || 'single'\n\n if (routeType === 'wrap') {\n const { children, ...rest } = route\n return { ...rest, children: children.map(removeEmptyChildren) }\n }\n\n if (routeType === 'single' || (!hasIndexRoute && route.component)) {\n const { path, component, type, ...rest } = route\n return {\n path,\n children: [\n { path: '', component, ...rest }${e?" as MyRouteObject":""},\n ...route.children.map(removeEmptyChildren)\n ]\n }\n }\n\n if (hasIndexRoute) {\n const { path, ...rest } = route\n const updatedChildren = route.children.map(child =>\n child.path === '' || child.path === '/' ? { ...rest, ...child } : child\n )\n return { path, children: updatedChildren.map(removeEmptyChildren) }\n }\n\n return { ...route, children: route.children.map(removeEmptyChildren) }\n}\n`)(o),l=o?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",h=((e,n,t,o,r,s,a)=>`// Auto-generated by ono-auto-router${e}${n}${t}${o}${r}${s}${a}\n`)(o?"\nimport type { RouteRecordRaw } from 'vue-router'\n\ntype PagesComponentType = Record<string, () => Promise<unknown>>\n\ninterface MyRouteObject extends Omit<RouteRecordRaw, 'children'> {\n type?: 'single' | 'wrap'\n children?: MyRouteObject[]\n}\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'component' | 'children' | 'path'>\n>\n":"",(e=>`\nconst hasDuplicateProperty = ${e?"<T>(items: T[], propName: keyof T)":"(items, propName)"} => {\n const seenValues = new Set()\n return items.some(item => {\n if (seenValues.has(item[propName])) {\n return true\n }\n seenValues.add(item[propName])\n return false\n })\n}\n\nconst replaceBracketsWithColon = ${e?"(str: string)":"(str)"} => {\n return str.replace(/\\[([^\\]]+)\\]/g, ':$1').replace('.tsx', '')\n}\n`)(o),p,u,c,i,"\nexport const routes = createRoutes()");o?(ye(n.resolve(s,"./index.ts"),a),ye(n.resolve(s,"./autoRouter.ts"),h),ye(n.resolve(s,"./defineConfig.ts"),l)):ye(t,h)},re=(t,o,r,s,c,u)=>{const l=n.resolve(r,o);if(!e.existsSync(l))throw new Error(`Pages directory not found: ${l}`);const f=h(t,r,s),g=p(r),d=f.split(".")[0];a(d+".js"),a(d+".ts"),a(d+".jsx"),a(d+".tsx"),i(d),"react"===t?u?z(o,f,c,g):B(o,l,r,f,c,g):u?oe(o,f,g,c):te(o,l,r,f,c,g),console.log(`[ono-auto-router] Routes file generated: ${f}`)},se=(e,n)=>{if(!n.has(e))return n.add(e),e;let t=1;for(;n.has(`${e}_${t}`);)t++;return`${e}_${t}`};function ae(n){try{const o=e.readFileSync(n,"utf-8").match(/export\s+default\s+([\s\S]*?)(?=\n\w|$)/);if(!o)return console.warn("No export default found in:",n),null;const r=o[1].trim();try{if(r.startsWith("{"))return new Function(`return ${r}`)();if(r.includes("defineConfig(")){const e=r.match(/defineConfig([\s\S]*)$/);if(e)return new Function(`return ${e[1]}`)()}return null}catch(t){return console.error("Error parsing export default content:",t),null}}catch(o){return console.error("Error reading file:",o),null}}function ie(e,t){let o=n.resolve(e);(o.endsWith(".js")||o.endsWith(".jsx")||o.endsWith(".ts")||o.endsWith(".tsx")||o.endsWith(".vue"))&&(o=n.dirname(o));const r=n.resolve(t);return n.relative(o,r)}var ce=/\\/g,ue=e=>e.replace(ce,"/"),pe=(e,t)=>ue(n.relative(t,e)),le=/export\s+default\s+[\w(\[\]\{\})]+/;function he(n){try{if(!e.existsSync(n))return console.warn(`File not found: ${n}`),!1;const t=e.readFileSync(n,"utf-8");return le.test(t)}catch(t){return console.error("Read error:",t),!1}}var fe=(e,n)=>{const t=/* @__PURE__ */new Set;return e.some(e=>!!t.has(e[n])||(t.add(e[n]),!1))};function ge(e){return e.replace(/"<start>([\s\S]*?)<\/end>"/g,"$1")}function de(e){let n=e;for(;;){const e=ge(n);if(e===n)break;n=e}return n}var me=(e,n,t)=>e.replace(/\[([^\]]+)\]/g,":$1").replace("react"===t?n?".tsx":".jsx":".vue","");function Re(n){e.existsSync(n)||e.mkdirSync(n,{recursive:!0})}function Pe(t,o){Re(n.dirname(t)),e.writeFileSync(t,o,"utf-8")}async function ye(t,o){const r=n.dirname(t);await e.promises.mkdir(r,{recursive:!0}),await e.promises.writeFile(t,o,"utf-8")}var $e="index.ts",je="index.js";export{p as C,a as D,i as E,o as O,h as S,c as T,te as _,Pe as a,m as b,fe as c,ue as d,ie as f,oe as g,re as h,ye as i,he as l,se as m,$e as n,me as o,ae as p,Re as r,de as s,je as t,pe 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,l[e][p(t)?"ts":"js"])),r},f=/[/\\]/,g=/[^a-zA-Z0-9]/g,d=/^(\d)/,m=e=>e?e.charAt(0).toUpperCase()+e.slice(1).toLowerCase():"";function R(e){const t=n.extname(e),o=n.basename(e,t),r=n.dirname(e).split(f).filter(Boolean);return"index"!==o&&"Index"!==o&&r.push(o),r.map(e=>(e=>e.replace(g,"_").replace(d,"_$1"))(e).split("_").map(m).join("")).join("")||"Component"}var P={"/home":"/","/root":"/"},y=(e,n)=>{const t=e.split("/"),o=t[t.length-1];return n&&o.endsWith(n)?o.slice(0,-n.length):o},$=e=>{const n=P[e];return n||("/notfound"===e.toLowerCase()||"/404"===e?"/*":e)},j=(e,n)=>e.endsWith(".config."+(n?"ts":"js"))?"index"===y(e,".config."+(n?"ts":"js"))?e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")):e.slice(0,-10)+"."+(n?"tsx":"jsx"):e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")),x=(e,n,t)=>{if(e.endsWith(".config."+(t?"ts":"js"))){const o=y(e,".config."+(t?"ts":"js")),r=(e=>{const n=e.split("/");return n.pop(),n.join("/")})(e).replace(n,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(n,"").replace("/index.config."+(t?"ts":"js"),"")||"/"},C=async(e,n,t,o)=>{const r=[];for(const[s,a]of((e,n,t)=>Object.keys(e).map(e=>{const o=((e,n)=>e.endsWith(n?".tsx":".jsx")?e.slice(0,-4)+".config."+(n?"ts":"js"):e.replace("index."+(n?"ts":"js"),"index.config."+(n?"ts":"js")))(e,t);return[o,n[o]||{}]}))(e,n,o)){const n=j(s,o);if(!e[n])continue;const i=me(x(s,`/${t}`,o)||"/",o,"react"),c=$(i);r.push({...a,path:c,type:a?.type,isRoot:"/root"===i,element:e[n]})}return r},b=e=>{if(e.index)return e;if("wrap"!==e.type){const{path:n,children:t,...o}=e;if(Object.keys(o).length>0)return{path:n,children:[{path:"",index:!0,...o},...(t||[]).map(b)]}}return e.children?{...e,children:e.children.map(b)}:e},w=e=>(e=>e.map(b))((e=>{const n=/* @__PURE__ */new Map,t=[],o=/* @__PURE__ */new Map,r=e=>{let n=o.get(e);return void 0===n&&(n="/"===e?[]:e.split("/").filter(Boolean),o.set(e,n)),n},s=e.slice().sort((e,n)=>e.path.length-n.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(n.set(e,s),o.length<=1){t.push(s);continue}const i="/"+o.slice(0,-1).join("/"),c=n.get(i);c?(s.path=o[o.length-1],c.children.push(s)):t.push(s)}return t})(e)),M=e=>{const{isRoot:n,type:t,children:o,...r}=e;return o?.length?{...r,children:o.map(M)}:r},O=e=>{const{children:n}=e;if(!n?.length){const{children:n,...t}=e;return t}const t=n.map(O);if("wrap"===e.type)return{...e,children:t};const{path:o,element:r,type:s,children:a,...i}=e;return r?{path:o,children:[{index:!0,element:r,...i},...t]}:{path:o,...i,children:t}},v=e=>M(O(e)),S=e=>w(e).map(v),T=e=>{if(e.some(e=>e.isRoot))return(e=>{let n,t,o;const r=[];for(const i of e)if(i.isRoot){if(n)throw new Error("There cannot be multiple root routes in a route");n=i}else"/"===i.path?t=i:"/*"===i.path?o=i:r.push(i);if(fe(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[t&&{...t,index:!0},...S(r)].filter(e=>Boolean(e)),a=[];return n&&a.push(M({...n,children:s})),o&&a.push(M(o)),a})(e);if(fe(e,"path"))throw new Error("There cannot be duplicate paths in a route");return S(e)},k=(e,n)=>({import:`import ${e} from './${n}'`,component:`<start><${e} /></end>`,lazy:`const ${e} = lazy(() => import('${n}'))`,lazyComponent:`<start><Suspense><${e} /></Suspense></end>`});var E="index.tsx",N="index.jsx",F=(e,n,t,o,r,s,a)=>{const i=((e,n)=>e.includes(n?E:N)?e.replace(n?E:N,n?$e:je):e)(pe(e,n),a),c=ue(ie(t,e)),u=se(R(c),s),p=`element(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},W=(e,n,t,o)=>{const r=pe(e,n);t[`/${r}`]=c(r,ae(e),o)};function L(e,n,o,r,s,a,i,c,u){const p={},l=e.replace(/^\/+/,""),h=t.sync(l,{cwd:n,absolute:!0,onlyFiles:!0}).filter(he);for(const t of h)if("component"===s){if(t.includes(".config."))continue;F(t,o,r,p,a,i,u)}else W(t,o,p,c);return p}var B=async(e,n,t,o,r,s)=>{const a=/* @__PURE__ */new Map,i=/* @__PURE__ */new Set,c=/* @__PURE__ */new Map;ye(o,((e,n,t,o)=>{let r=e;for(const[s,a]of n){const e=k(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of t)r=r.replace(s,a);return de(r)})(function(e,n,t,o){const r=t.length>0?`\n${t.join("\n")}\n`:"";return`// Auto-generated by ono-auto-router\n${o?"import type { RouteObject } from 'react-router-dom'\n":""}${n.join("\n")}${o?"\n\ntype PageConfig = Partial<\n Omit<RouteObject, 'path' | 'Component' | 'element' | 'children'> & {\n type?: 'single' | 'wrap'\n }\n>\n":""}${o?"\nexport const defineConfig = (config: PageConfig) => config":""}\n${r}\nexport const routes${o?": RouteObject[]":""} = ${JSON.stringify(e,null,2)}\n`}(T(await C(L("/**/*.{jsx,tsx}",n,t,o,"component",a,i,c,s),L("/**/*.config.{js,ts,jsx,tsx}",n,t,o,"config",a,i,c,s),e,s)),((e,n)=>{if(e)return["import { lazy, Suspense } from 'react'"];const t=[];for(const o of n.values())t.push(k(o.componentName,o.path).import);return t})(r,a),((e,n)=>{if(!e)return[];const t=[];for(const o of n.values())t.push(k(o.componentName,o.path).lazy);return t})(r,a),s),a,c,r))},z=(e,t,o,r)=>{const s=t.split(".")[0],a=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(r),i=o?((e,n)=>`\nconst PATH_REPLACEMENTS${n?": Record<string, string>":""} = {\n '/home': '/',\n '/root': '/'\n}\n\nconst cachedLazyComponents${n?": Record<\n string,\n LazyExoticComponent<ComponentType<unknown>>\n>":""} = {}\n\nconst getConfigFileName = ${n?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${n?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${n?"ts":"js"}'\n }\n return pagePath.replace('index.${n?"ts":"js"}', 'index.config.${n?"ts":"js"}')\n}\n\nconst formatPageModule = (${n?"\n pagesComponent: Record<string, ComponentType<unknown>>,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${n?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${n?"(pathStr: string): string":"(pathStr)"} => {\n if (PATH_REPLACEMENTS[pathStr]) {\n return PATH_REPLACEMENTS[pathStr]\n }\n\n const lowerPath = pathStr.toLowerCase()\n if (lowerPath === '/notfound' || pathStr === '/404') {\n return '/*'\n }\n\n return pathStr\n}\n\nconst getBasename = ${n?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1]\n if (ext && lastPart.endsWith(ext)) {\n return lastPart.slice(0, -ext.length)\n }\n return lastPart\n}\n\nconst getDirname = ${n?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${n?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n if (fileName === 'index') {\n return dirPath || '/'\n }\n return dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n return (\n configPath.replace('/${e}', '').replace('/index.config.${n?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${n?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${n?": Record<string, unknown>":""} = {}\n\n for (const [path, module] of Object.entries(modules)) {\n if ('default' in module) {\n result[path] = module.default\n }\n }\n\n return result\n}\n\nconst filterUnComponent = ${n?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${n?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${n?"tsx":"jsx"}')) {\n result[key] = pagesComponent[key]\n }\n }\n\n return result\n}\n\nconst LazyComponent = ({\n Element\n}${n?": {\n Element: LazyExoticComponent<ComponentType<unknown>>\n}":""}) => {\n return (\n <Suspense>\n <Element />\n </Suspense>\n )\n}\n\nconst createBaseRoutes = () => {\n const pagesComponent = filterUnComponent({\n ...import.meta.glob('/${e}/**/*.${n?"tsx":"jsx"}')${n?" as PagesComponentType":""}\n })\n\n const pagesString = getFileDefault({\n ...import.meta.glob('/${e}/**/*.${n?"tsx":"jsx"}', {\n eager: true\n })\n })${n?" as Record<string, ComponentType<unknown>>":""}\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${n?"ts":"js"}', {\n eager: true\n })\n })${n?" as Record<string, PageConfig>":""}\n\n const result${n?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const [pagePath, page] of formatPageModule(pagesString, pagesModule)) {\n const compPath = getCompPathFromConfig(pagePath)\n\n if (!pagesComponent[compPath]) continue\n\n const rawPath = getRawPathFromConfig(pagePath) || '/'\n const processedPath = replaceBracketsWithColon(rawPath)\n const routePath = normalizePath(processedPath)\n\n let Component${n?": MyRouteObject['element']":""}\n if (!cachedLazyComponents[compPath]) {\n cachedLazyComponents[compPath] = lazy(pagesComponent[compPath])\n }\n Component = <LazyComponent Element={cachedLazyComponents[compPath]} />\n\n result.push({\n ...page,\n path: routePath,\n type: page?.type,\n isRoot: processedPath === '/root',\n element: Component\n })\n }\n\n return result\n}`)(e,r):((e,n)=>`\nconst PATH_REPLACEMENTS${n?": Record<string, string>":""} = {\n '/home': '/',\n '/root': '/'\n}\n\nconst getConfigFileName = ${n?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${n?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${n?"ts":"js"}'\n }\n return pagePath.replace('index.${n?"ts":"js"}', 'index.config.${n?"ts":"js"}')\n}\n\nconst formatPageModule = (${n?"\n pagesComponent: PagesComponentType,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${n?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${n?"(pathStr: string): string":"(pathStr)"} => {\n if (PATH_REPLACEMENTS[pathStr]) {\n return PATH_REPLACEMENTS[pathStr]\n }\n\n const lowerPath = pathStr.toLowerCase()\n if (lowerPath === '/notfound' || pathStr === '/404') {\n return '/*'\n }\n\n return pathStr\n}\n\nconst getBasename = ${n?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1]\n if (ext && lastPart.endsWith(ext)) {\n return lastPart.slice(0, -ext.length)\n }\n return lastPart\n}\n\nconst getDirname = ${n?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${n?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${n?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n if (fileName === 'index') {\n return dirPath || '/'\n }\n return dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n return (\n configPath.replace('/${e}', '').replace('/index.config.${n?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${n?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${n?": PagesComponentType | Record<string, PageConfig>":""} = {}\n\n for (const [path, module] of Object.entries(modules)) {\n if ('default' in module) {\n result[path] = module.default${n?" as ComponentType<unknown> | PageConfig":""}\n }\n }\n\n return result\n}\n\nconst filterUnComponent = ${n?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${n?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${n?"tsx":"jsx"}')) {\n result[key] = pagesComponent[key]\n }\n }\n\n return result\n}\n\nconst createBaseRoutes = () => {\n const pagesComponent = filterUnComponent(\n getFileDefault({\n ...import.meta.glob('/${e}/**/*.${n?"tsx":"jsx"}', { eager: true })\n })${n?" as PagesComponentType":""}\n )\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${n?"ts":"js"}', {\n eager: true\n })\n })${n?" as Record<string, PageConfig>":""}\n\n const result${n?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const [pagePath, page] of formatPageModule(pagesComponent, pagesModule)) {\n const compPath = getCompPathFromConfig(pagePath)\n\n if (!pagesComponent[compPath]) continue\n\n const rawPath = getRawPathFromConfig(pagePath) || '/'\n const processedPath = replaceBracketsWithColon(rawPath)\n const routePath = normalizePath(processedPath)\n\n const Component = pagesComponent[compPath]\n result.push({\n ...page,\n path: routePath,\n type: page?.type,\n isRoot: processedPath === '/root',\n element: <Component />\n })\n }\n\n return result\n}`)(e,r),c=(e=>`\nconst processRoute = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} =>\n cleanIsRoot(removeEmptyChildren(route))\n\nconst processRoutes = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} =>\n buildRouteTree(routes).map(processRoute)\n\nconst handleRootRoute = ${e?"(routes: (MyRouteObject & { isRoot?: boolean })[])":"(routes)"} => {\n let rootRoute${e?": MyRouteObject | undefined":" = undefined"}\n let homeRoute${e?": MyRouteObject | undefined":" = undefined"}\n let notFoundRoute${e?": MyRouteObject | undefined":" = undefined"}\n const filteredRoutes${e?": MyRouteObject[]":""} = []\n\n for (const route of routes) {\n if (route.isRoot) {\n if (rootRoute)\n throw new Error('There cannot be multiple root routes in a route')\n rootRoute = route\n } else if (route.path === '/') {\n homeRoute = route\n } else if (route.path === '/*') {\n notFoundRoute = route\n } else {\n filteredRoutes.push(route)\n }\n }\n\n if (hasDuplicateProperty(filteredRoutes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n const children = [\n homeRoute && { ...homeRoute, index: true },\n ...processRoutes(filteredRoutes)\n ].filter(${e?"(route): route is NonNullable<typeof route> => Boolean(route)":"Boolean"})\n\n const result${e?": MyRouteObject[]":""} = []\n\n if (rootRoute) {\n result.push(cleanIsRoot({ ...rootRoute, children }))\n }\n\n if (notFoundRoute) {\n result.push(cleanIsRoot(notFoundRoute))\n }\n\n return result\n}\n\nconst formatRoutes = (\n routes${e?": (MyRouteObject & { isRoot?: boolean })[]":""}\n) => {\n if (routes.some(r => r.isRoot)) return handleRootRoute(routes)\n\n if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return processRoutes(routes)\n}`)(r),u=(e=>`\nconst processSingleRoute = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n if (route.index) {\n return route\n }\n\n if (route.type !== 'wrap') {\n const { path: routePath, children, ...extraProps } = route\n const hasExtraProps = Object.keys(extraProps).length > 0\n\n if (hasExtraProps) {\n const indexRoute${e?": MyRouteObject":""} = {\n path: '',\n index: true,\n ...extraProps\n }\n\n return {\n path: routePath,\n children: [indexRoute, ...(children || []).map(processSingleRoute)]\n }\n }\n }\n\n if (route.children) {\n return {\n ...route,\n children: route.children.map(processSingleRoute)\n }\n }\n\n return route\n}\n\nconst formatRouteTree = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n return routes.map(processSingleRoute)\n}\n\nconst buildTreeStructure = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n const routeMap = new Map${e?"<string, MyRouteObject>":""}()\n const rootRoutes${e?": MyRouteObject[]":""} = []\n const pathPartsCache = new Map${e?"<string, string[]>":""}()\n\n const getPathParts = ${e?"(pathStr: string): string[]":"(pathStr)"} => {\n let parts = pathPartsCache.get(pathStr)\n if (parts === undefined) {\n parts = pathStr === '/' ? [] : pathStr.split('/').filter(Boolean)\n pathPartsCache.set(pathStr, parts)\n }\n return parts\n }\n\n const sortedRoutes = routes\n .slice()\n .sort((a, b) => a.path.length - b.path.length)\n\n for (const route of sortedRoutes) {\n const routePath = route.path\n const pathParts = getPathParts(routePath)\n const currentRoute = { ...route, children: [] }\n routeMap.set(routePath, currentRoute)\n\n if (pathParts.length <= 1) {\n rootRoutes.push(currentRoute)\n continue\n }\n\n const parentPath = '/' + pathParts.slice(0, -1).join('/')\n const parentRoute = routeMap.get(parentPath)\n\n if (parentRoute) {\n currentRoute.path = pathParts[pathParts.length - 1]\n parentRoute.children${e?"!":""}.push(currentRoute)\n } else {\n rootRoutes.push(currentRoute)\n }\n }\n\n return rootRoutes\n}\n\nconst buildRouteTree = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n const treeStructure = buildTreeStructure(routes)\n return formatRouteTree(treeStructure)\n}`)(r),p=(e=>`\nconst cleanIsRoot = ${e?"(route: RouteWithIsRoot): MyRouteObject":"(route)"} => {\n const { isRoot, type, children, ...rest } = route${e?" as RouteWithIsRoot & {\n type?: unknown\n }":""}\n\n if (!children?.length) {\n return rest\n }\n\n return {\n ...rest,\n children: children.map(cleanIsRoot)\n }\n}`)(r),l=(e=>`\nconst removeEmptyChildren = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n const { children } = route\n\n if (!children?.length) {\n const { children: _, ...rest } = route\n return rest\n }\n\n const processedChildren = children.map(removeEmptyChildren)\n\n if (route.type === 'wrap') {\n return { ...route, children: processedChildren }\n }\n\n const { path, element, type, children: _, ...rest } = route\n\n if (!element) {\n return { path, ...rest, children: processedChildren }\n }\n\n return {\n path,\n children: [\n { index: true, element, ...rest }${e?" as MyRouteObject":""},\n ...processedChildren\n ]\n }\n}`)(r),h=r?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",f=(e=>`\nconst getRoutes = () => {\n const baseRoutes = createBaseRoutes()\n const formattedRoutes = formatRoutes(baseRoutes)${e?" as RouteObject[]":""}\n return formattedRoutes\n}\n\nexport const routes = getRoutes()`)(r),g=((e,n,t,o,r,s,a,i)=>`// Auto-generated by ono-auto-router${e}${n}${t}${o}${r}${s}${a}${i}\n`)(((e,n)=>e?`\n${n?"import {\n lazy,\n Suspense,\n type ComponentType,\n type LazyExoticComponent\n} from 'react'":"import type { ComponentType } from 'react'"}\nimport type { RouteObject } from 'react-router-dom'\n\n${n?"type PagesComponentType = Record<\n string,\n () => Promise<{ default: ComponentType<unknown> }>\n>":"type PagesComponentType = Record<string, ComponentType<unknown>>"}\n\ninterface MyRouteObject extends Omit<RouteObject, 'path' | 'children'> {\n path: string\n type?: 'single' | 'wrap'\n children?: MyRouteObject[]\n}\n\ntype RouteWithIsRoot = MyRouteObject & { isRoot?: boolean }\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'Component' | 'element' | 'children' | 'path'>\n>`:n?"\nimport { lazy, Suspense } from 'react'\n":"")(r,o),(e=>`\nconst hasDuplicateProperty = ${e?"<T, K extends keyof T>(items: T[], propName: K)":"(items, propName)"} => {\n const seenValues = new Set()\n return items.some(item => {\n if (seenValues.has(item[propName])) {\n return true\n }\n seenValues.add(item[propName])\n return false\n })\n}\n\nconst replaceBracketsWithColon = ${e?"(str: string)":"(str)"} => {\n return str.replace(/\\[([^\\]]+)\\]/g, ':$1').replace('.tsx', '')\n}`)(r),l,p,u,c,i,f);r?(ye(n.resolve(s,"./index.ts"),a),ye(n.resolve(s,"./autoRouter.tsx"),g),ye(n.resolve(s,"./defineConfig.ts"),h)):ye(t,g)},A={"/home":"/","/root":"/"},I=(e,n)=>{const t=e.split("/"),o=t[t.length-1];return n&&o.endsWith(n)?o.slice(0,-n.length):o},D=e=>{const n=A[e];return n||("/notfound"===e.toLowerCase()||"/404"===e?"/:pathMatch(.*)*":e)},K=(e,n)=>e.endsWith(".config."+(n?"ts":"js"))?"index"===I(e,".config."+(n?"ts":"js"))?e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")):e.slice(0,-10)+".vue":e.replace("index.config."+(n?"ts":"js"),"index."+(n?"ts":"js")),_=(e,n,t)=>{if(e.endsWith(".config."+(t?"ts":"js"))){const o=I(e,".config."+(t?"ts":"js")),r=(e=>{const n=e.split("/");return n.pop(),n.join("/")})(e).replace(n,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(n,"").replace("/index.config."+(t?"ts":"js"),"")||"/"},H=async(e,n,t,o)=>{const r=[];for(const[s,a]of((e,n,t)=>Object.keys(e).map(e=>{const o=((e,n)=>e.replace("index."+(n?"ts":"js"),"index.config."+(n?"ts":"js")))(e,t);return[o,n[o]||{}]}))(e,n,o)){const n=K(s,o),i=me(_(s,`/${t}`,o)||"/",o,"vue"),c=D(i);r.push({...a,path:c,type:a?.type,isRoot:"/root"===i,component:e[n]})}return r},V=e=>{if(!e.path)return e;if("wrap"!==e.type){const{path:n,children:t,...o}=e;if(Object.keys(o).length>0)return{path:n,children:[{path:"",...o},...(t||[]).map(V)]}}return e.children?{...e,children:e.children.map(V)}:e},U=e=>(e=>e.map(V))((e=>{const n=/* @__PURE__ */new Map,t=[],o=/* @__PURE__ */new Map,r=e=>{let n=o.get(e);return void 0===n&&(n="/"===e?[]:e.split("/").filter(Boolean),o.set(e,n)),n},s=e.slice().sort((e,n)=>e.path.length-n.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(n.set(e,s),o.length<=1){t.push(s);continue}const i="/"+o.slice(0,-1).join("/"),c=n.get(i);c?(s.path=o[o.length-1],c.children.push(s)):t.push(s)}return t})(e)),J=e=>{const{isRoot:n,type:t,children:o,...r}=e;return o?.length?{...r,children:o.map(J)}:r},Z=e=>{const{children:n}=e;if(!n?.length){const{children:n,...t}=e;return t}const t=n.map(Z);if("wrap"===e.type)return{...e,children:t};const{path:o,component:r,type:s,children:a,...i}=e;return r?{path:o,children:[{path:"",component:r,...i},...t]}:{path:o,...i,children:t}},q=e=>J(Z(e)),G=e=>U(e).map(q),Q=e=>{if(e.some(e=>e.isRoot))return(e=>{let n,t,o;const r=[];for(const i of e)if(i.isRoot){if(n)throw new Error("There cannot be multiple root routes in a route");n=i}else"/"===i.path?t=i:"/:pathMatch(.*)*"===i.path?o=i:r.push(i);if(fe(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[t&&{...t,index:!0},...G(r)].filter(e=>Boolean(e)),a=[];return n&&a.push(J({...n,children:s})),o&&a.push(J(o)),a})(e);if(fe(e,"path"))throw new Error("There cannot be duplicate paths in a route");return G(e)},X=(e,n)=>({import:`import ${e} from './${n}'`,component:`<start>${e}</end>`,lazyComponent:`<start>() => import('${n}')</end>`});var Y=(e,n,t,o,r,s,a)=>{const i=((e,n)=>e.replace("index.vue",n?$e:je))(pe(e,n),a),c=ue(ie(t,e)),u=se(R(c),s),p=`component(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},ee=(e,n,t,o)=>{const r=pe(e,n);t[`/${r}`]=c(r,ae(e),o)};function ne(e,n,o,r,s,a,i,c,u){const p={},l=e.replace(/^\/+/,""),h=t.sync(l,{cwd:n,absolute:!0,onlyFiles:!0}),f="component"===s?((e,n)=>n.map(n=>n.includes("index.vue")||2===n.replace(e.replaceAll("\\","/"),"").split("/").length?n:void 0).filter(Boolean))(n,h):h.filter(he);for(const t of f)if("component"===s){if(t.includes(".config."))continue;Y(t,o,r,p,a,i,u)}else ee(t,o,p,c);return p}var te=async(e,n,t,o,r,s)=>{const a=/* @__PURE__ */new Map,i=/* @__PURE__ */new Set,c=/* @__PURE__ */new Map;ye(o,((e,n,t,o)=>{let r=e;for(const[s,a]of n){const e=X(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of t)r=r.replace(s,a);return de(r)})(function(e,n,t,o){return`// Auto-generated by ono-auto-router${t?"\nimport type { RouteRecordRaw } from 'vue-router'":""}${o?"":`\n${n.join("\n")}${t?"":"\n"}`}${t?"\n\ntype PageConfig = Partial<\n Omit<RouteRecordRaw, 'path' | 'component' | 'children'> & {\n type?: 'single' | 'wrap'\n }\n>\n":""}${t?"\nexport const defineConfig = (config: PageConfig) => config\n":""}\nexport const routes${t?": RouteRecordRaw[]":""} = ${JSON.stringify(e,null,2)}\n`}(Q(await H(ne("/**/*.vue",n,t,o,"component",a,i,c,s),ne("/**/*.config.{js,ts}",n,t,o,"config",a,i,c,s),e,s)),((e,n)=>{if(e)return[];const t=[];for(const o of n.values())t.push(X(o.componentName,o.path).import);return t})(r,a),s,r),a,c,r))},oe=(e,t,o,r)=>{const s=t.split(".")[0],a=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(o),i=((e,n,t)=>`\nconst pathCache = new Map${n?"<string, { compPath: string; basePath: string }>":""}()\nconst basenameCache = new Map${n?"<string, string>":""}()\n\nconst normalizePagePath = ${n?"(key: string): string":"(key)"} => {\n if (key.includes('index.vue')) return key.replace('index.vue', 'index.${n?"ts":"js"}')\n if (key.includes('root.vue')) return key.replace('root.vue', 'root/index.${n?"ts":"js"}')\n if (key.includes('404.vue')) return key.replace('404.vue', '404/index.${n?"ts":"js"}')\n if (key.toLowerCase().includes('notfound.vue'))\n return key.toLowerCase().replace('notfound.vue', 'notfound/index.${n?"ts":"js"}')\n return key\n}\n\nconst getBasename = ${n?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const cacheKey = ext ? filePath + ':' + ext : filePath\n if (basenameCache.has(cacheKey)) {\n return basenameCache.get(cacheKey)${n?"!":""}\n }\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1] || ''\n let result = lastPart\n if (ext && lastPart.endsWith(ext)) {\n result = lastPart.slice(0, -ext.length)\n }\n basenameCache.set(cacheKey, result)\n return result\n}\n\nconst getDirname = ${n?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getPathsFromConfig = ${n?"(configPath: string)":"(configPath)"} => {\n const cacheKey = configPath\n if (pathCache.has(cacheKey)) {\n return pathCache.get(cacheKey)${n?"!":""}\n }\n\n let compPath${n?": string":" = ''"}\n let basePath${n?": string":" = ''"}\n\n if (configPath.endsWith('.config.${n?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${n?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n\n if (fileName === 'index') {\n compPath = configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"ts":"js"}')\n basePath = dirPath || '/'\n } else {\n compPath = configPath.slice(0, -10) + '.vue'\n basePath = dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n } else {\n compPath = configPath.replace('index.config.${n?"ts":"js"}', 'index.${n?"ts":"js"}')\n basePath =\n configPath.replace('/${e}', '').replace('/index.config.${n?"ts":"js"}', '') ||\n '/'\n }\n\n const result = { compPath, basePath }\n pathCache.set(cacheKey, result)\n return result\n}\n\nconst formatPath = ${n?"(path: string): string":"(path)"} => {\n const lowerPath = path.toLowerCase()\n if (lowerPath === '/home') return '/'\n if (lowerPath === '/notfound' || path === '/404') return '/:pathMatch(.*)*'\n return path.replace('/index.${n?"ts":"js"}', '') || '/'\n}\n\nconst getConfigFileName = ${n?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.vue')) {\n return pagePath.slice(0, -4) + '.config.${n?"ts":"js"}'\n }\n return pagePath.replace('index.${n?"ts":"js"}', 'index.config.${n?"ts":"js"}')\n}\n\nconst createBaseRoutes = ()${n?": MyRouteObject[]":""} => {\n const pagesComponent = Object.fromEntries(\n Object.entries({\n ...import.meta.glob('/${e}/**/index.vue'${t?"":", { eager: true, import: 'default' }"}),\n ...import.meta.glob('/${e}/*.vue'${t?"":", { eager: true, import: 'default' }"})\n }${n?" as PagesComponentType":""}).map(([key, value]) => [\n normalizePagePath(key),\n value\n ])\n )\n\n const pagesModule${n?": Record<string, PageConfig>":""} = import.meta.glob(\n '/${e}/**/*.config.${n?"ts":"js"}',\n { eager: true, import: 'default' }\n )\n\n const result${n?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const pagePath of Object.keys(pagesComponent)) {\n const configPath = getConfigFileName(pagePath)\n const content = pagesModule[configPath] || {}\n const { compPath, basePath } = getPathsFromConfig(configPath)\n const path = replaceBracketsWithColon(basePath || '/')\n const name = path.split('/').filter(Boolean).join('-') || 'index'\n\n result.push({\n path: formatPath(path),\n name,\n component: pagesComponent[compPath],\n isRoot: path === '/root',\n ...content${n?"!":""}\n })\n }\n\n return result\n}\n\nconst processRoutes = ${n?"(\n routes: MyRouteObject[],\n removeLeadingSlash = false\n): MyRouteObject[]":"(routes, removeLeadingSlash)"} =>\n buildRouteTree(routes, removeLeadingSlash)\n .map(removeEmptyChildren)\n .map(cleanIsRoot)\n\nconst handleRootRoute = ${n?"(\n routes: (MyRouteObject & { isRoot?: boolean })[]\n): MyRouteObject[]":"(routes)"} => {\n let rootRoute${n?": (MyRouteObject & { isRoot?: boolean }) | undefined":" = undefined"}\n let homeRoute${n?": MyRouteObject | undefined":" = undefined"}\n let notFoundRoute${n?": MyRouteObject | undefined":" = undefined"}\n const filteredRoutes${n?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const route of routes) {\n if (route.isRoot) {\n if (rootRoute)\n throw new Error('There cannot be multiple root routes in a route')\n rootRoute = route\n } else if (route.path === '/') {\n homeRoute = route\n } else if (route.path === '/:pathMatch(.*)*') {\n notFoundRoute = route\n } else {\n filteredRoutes.push(route)\n }\n }\n\n if (hasDuplicateProperty(filteredRoutes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n const processedRoutes${n?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n if (rootRoute) {\n const children = [\n homeRoute && { ...homeRoute, path: '' },\n ...processRoutes(filteredRoutes, true)\n ].filter(Boolean)${n?" as MyRouteObject[]":""}\n processedRoutes.push({ ...rootRoute, path: '/', children })\n }\n\n if (notFoundRoute) processedRoutes.push(notFoundRoute)\n\n return processedRoutes.map(cleanIsRoot)\n}\n\nconst createRoutes = ()${n?": RouteRecordRaw[]":""} => {\n const routes = createBaseRoutes()\n\n if (routes.some((r${n?": MyRouteObject & { isRoot?: boolean }":""}) => r.isRoot))\n return handleRootRoute(routes)${n?" as RouteRecordRaw[]":""}\n\n if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return processRoutes(routes)${n?" as RouteRecordRaw[]":""}\n}\n`)(e,o,r),c=(e=>`\nconst buildRouteTree = ${e?"(\n routes: MyRouteObject[],\n removeLeadingSlash: boolean = false\n)":"(routes, removeLeadingSlash)"} => {\n const routeMap = new Map${e?"<string, MyRouteObject & { isRoot?: boolean }>":""}()\n const rootRoutes${e?": MyRouteObject[]":""} = []\n\n const sortedRoutes = [...routes].sort((a, b) => a.path.length - b.path.length)\n\n for (const route of sortedRoutes) {\n let path = route.path\n if (removeLeadingSlash && path.startsWith('/')) {\n path = path.slice(1)\n }\n routeMap.set(path, { ...route, path, children: [] })\n }\n\n for (const [path, route] of routeMap) {\n const slashIndex = path.lastIndexOf('/')\n\n if (slashIndex <= 0) {\n const { isRoot, ...rest } = route\n rootRoutes.push(rest)\n continue\n }\n\n const parentPath = path.slice(0, slashIndex)\n const parentRoute = routeMap.get(parentPath)\n\n if (parentRoute) {\n const relativePath = path.slice(slashIndex + 1)\n const childRoute = { ...route, path: relativePath }\n parentRoute.children${e?"!":""}.push(childRoute)\n } else {\n const { isRoot, ...rest } = route\n rootRoutes.push(rest)\n }\n }\n\n return rootRoutes\n}\n`)(o),u=(e=>`\nconst cleanIsRoot = ${e?"(\n route: MyRouteObject & { isRoot?: boolean }\n): MyRouteObject":"(route)"} => {\n const { isRoot, type, children, ...rest } = route\n const result${e?": MyRouteObject":""} = { ...rest }\n\n if (children?.length) {\n result.children = children.map(cleanIsRoot)\n }\n\n return result\n}\n`)(o),p=(e=>`\nconst removeEmptyChildren = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n if (!route.children?.length) {\n const { children, ...rest } = route\n return rest\n }\n\n const hasIndexRoute = route.children.some(\n child => child.path === '' || child.path === '/'\n )\n\n const routeType = route.type || 'single'\n\n if (routeType === 'wrap') {\n const { children, ...rest } = route\n return { ...rest, children: children.map(removeEmptyChildren) }\n }\n\n if (routeType === 'single' || (!hasIndexRoute && route.component)) {\n const { path, component, type, ...rest } = route\n return {\n path,\n children: [\n { path: '', component, ...rest }${e?" as MyRouteObject":""},\n ...route.children.map(removeEmptyChildren)\n ]\n }\n }\n\n if (hasIndexRoute) {\n const { path, ...rest } = route\n const updatedChildren = route.children.map(child =>\n child.path === '' || child.path === '/' ? { ...rest, ...child } : child\n )\n return { path, children: updatedChildren.map(removeEmptyChildren) }\n }\n\n return { ...route, children: route.children.map(removeEmptyChildren) }\n}\n`)(o),l=o?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",h=((e,n,t,o,r,s,a)=>`// Auto-generated by ono-auto-router${e}${n}${t}${o}${r}${s}${a}\n`)(o?"\nimport type { RouteRecordRaw } from 'vue-router'\n\ntype PagesComponentType = Record<string, () => Promise<unknown>>\n\ninterface MyRouteObject extends Omit<RouteRecordRaw, 'children'> {\n type?: 'single' | 'wrap'\n children?: MyRouteObject[]\n}\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'component' | 'children' | 'path'>\n>\n":"",(e=>`\nconst hasDuplicateProperty = ${e?"<T>(items: T[], propName: keyof T)":"(items, propName)"} => {\n const seenValues = new Set()\n return items.some(item => {\n if (seenValues.has(item[propName])) {\n return true\n }\n seenValues.add(item[propName])\n return false\n })\n}\n\nconst replaceBracketsWithColon = ${e?"(str: string)":"(str)"} => {\n return str.replace(/\\[([^\\]]+)\\]/g, ':$1').replace('.tsx', '')\n}\n`)(o),p,u,c,i,"\nexport const routes = createRoutes()");o?(ye(n.resolve(s,"./index.ts"),a),ye(n.resolve(s,"./autoRouter.ts"),h),ye(n.resolve(s,"./defineConfig.ts"),l)):ye(t,h)},re=(t,o,r,s,c,u)=>{const l=n.resolve(r,o);if(!e.existsSync(l))throw new Error(`Pages directory not found: ${l}`);const f=h(t,r,s),g=p(r),d=f.split(".")[0];a(d+".js"),a(d+".ts"),a(d+".jsx"),a(d+".tsx"),i(d),"react"===t?u?z(o,f,c,g):B(o,l,r,f,c,g):u?oe(o,f,g,c):te(o,l,r,f,c,g),console.log(`[ono-auto-router] Routes file generated: ${u?f.replace(".tsx","").replace(".ts",""):f}`)},se=(e,n)=>{if(!n.has(e))return n.add(e),e;let t=1;for(;n.has(`${e}_${t}`);)t++;return`${e}_${t}`};function ae(n){try{const o=e.readFileSync(n,"utf-8").match(/export\s+default\s+([\s\S]*?)(?=\n\w|$)/);if(!o)return console.warn("No export default found in:",n),null;const r=o[1].trim();try{if(r.startsWith("{"))return new Function(`return ${r}`)();if(r.includes("defineConfig(")){const e=r.match(/defineConfig([\s\S]*)$/);if(e)return new Function(`return ${e[1]}`)()}return null}catch(t){return console.error("Error parsing export default content:",t),null}}catch(o){return console.error("Error reading file:",o),null}}function ie(e,t){let o=n.resolve(e);(o.endsWith(".js")||o.endsWith(".jsx")||o.endsWith(".ts")||o.endsWith(".tsx")||o.endsWith(".vue"))&&(o=n.dirname(o));const r=n.resolve(t);return n.relative(o,r)}var ce=/\\/g,ue=e=>e.replace(ce,"/"),pe=(e,t)=>ue(n.relative(t,e)),le=/export\s+default\s+[\w(\[\]\{\})]+/;function he(n){try{if(!e.existsSync(n))return console.warn(`File not found: ${n}`),!1;const t=e.readFileSync(n,"utf-8");return le.test(t)}catch(t){return console.error("Read error:",t),!1}}var fe=(e,n)=>{const t=/* @__PURE__ */new Set;return e.some(e=>!!t.has(e[n])||(t.add(e[n]),!1))};function ge(e){return e.replace(/"<start>([\s\S]*?)<\/end>"/g,"$1")}function de(e){let n=e;for(;;){const e=ge(n);if(e===n)break;n=e}return n}var me=(e,n,t)=>e.replace(/\[([^\]]+)\]/g,":$1").replace("react"===t?n?".tsx":".jsx":".vue","");function Re(n){e.existsSync(n)||e.mkdirSync(n,{recursive:!0})}function Pe(t,o){Re(n.dirname(t)),e.writeFileSync(t,o,"utf-8")}async function ye(t,o){const r=n.dirname(t);await e.promises.mkdir(r,{recursive:!0}),await e.promises.writeFile(t,o,"utf-8")}var $e="index.ts",je="index.js";export{p as C,a as D,i as E,o as O,h as S,c as T,te as _,Pe as a,m as b,fe as c,ue as d,ie as f,oe as g,re as h,ye as i,he as l,se as m,$e as n,me as o,ae as p,Re as r,de as s,je as t,pe 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,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=>{const t=O[e];return t||("/notfound"===e.toLowerCase()||"/404"===e?"/*":e)},v=(e,t)=>e.endsWith(".config."+(t?"ts":"js"))?"index"===w(e,".config."+(t?"ts":"js"))?e.replace("index.config."+(t?"ts":"js"),"index."+(t?"ts":"js")):e.slice(0,-10)+"."+(t?"tsx":"jsx"):e.replace("index.config."+(t?"ts":"js"),"index."+(t?"ts":"js")),S=(e,t,n)=>{if(e.endsWith(".config."+(n?"ts":"js"))){const o=w(e,".config."+(n?"ts":"js")),r=(e=>{const t=e.split("/");return t.pop(),t.join("/")})(e).replace(t,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(t,"").replace("/index.config."+(n?"ts":"js"),"")||"/"},T=async(e,t,n,o)=>{const r=[];for(const[s,a]of((e,t,n)=>Object.keys(e).map(e=>{const o=((e,t)=>e.endsWith(t?".tsx":".jsx")?e.slice(0,-4)+".config."+(t?"ts":"js"):e.replace("index."+(t?"ts":"js"),"index.config."+(t?"ts":"js")))(e,n);return[o,t[o]||{}]}))(e,t,o)){const t=v(s,o);if(!e[t])continue;const i=xe(S(s,`/${n}`,o)||"/",o,"react"),c=M(i);r.push({...a,path:c,type:a?.type,isRoot:"/root"===i,element:e[t]})}return r},E=e=>{if(e.index)return e;if("wrap"!==e.type){const{path:t,children:n,...o}=e;if(Object.keys(o).length>0)return{path:t,children:[{path:"",index:!0,...o},...(n||[]).map(E)]}}return e.children?{...e,children:e.children.map(E)}:e},k=e=>(e=>e.map(E))((e=>{const t=new Map,n=[],o=new Map,r=e=>{let t=o.get(e);return void 0===t&&(t="/"===e?[]:e.split("/").filter(Boolean),o.set(e,t)),t},s=e.slice().sort((e,t)=>e.path.length-t.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(t.set(e,s),o.length<=1){n.push(s);continue}const i="/"+o.slice(0,-1).join("/"),c=t.get(i);c?(s.path=o[o.length-1],c.children.push(s)):n.push(s)}return n})(e)),N=e=>{const{isRoot:t,type:n,children:o,...r}=e;return o?.length?{...r,children:o.map(N)}:r},F=e=>{const{children:t}=e;if(!t?.length){const{children:t,...n}=e;return n}const n=t.map(F);if("wrap"===e.type)return{...e,children:n};const{path:o,element:r,type:s,children:a,...i}=e;return r?{path:o,children:[{index:!0,element:r,...i},...n]}:{path:o,...i,children:n}},W=e=>N(F(e)),B=e=>k(e).map(W),L=e=>{if(e.some(e=>e.isRoot))return(e=>{let t,n,o;const r=[];for(const i of e)if(i.isRoot){if(t)throw new Error("There cannot be multiple root routes in a route");t=i}else"/"===i.path?n=i:"/*"===i.path?o=i:r.push(i);if($e(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[n&&{...n,index:!0},...B(r)].filter(e=>Boolean(e)),a=[];return t&&a.push(N({...t,children:s})),o&&a.push(N(o)),a})(e);if($e(e,"path"))throw new Error("There cannot be duplicate paths in a route");return B(e)},z=(e,t)=>({import:`import ${e} from './${t}'`,component:`<start><${e} /></end>`,lazy:`const ${e} = lazy(() => import('${t}'))`,lazyComponent:`<start><Suspense><${e} /></Suspense></end>`});var D="index.tsx",A="index.jsx",I=(e,t,n,o,r,s,a)=>{const i=((e,t)=>e.includes(t?D:A)?e.replace(t?D:A,t?Me:ve):e)(Pe(e,t),a),c=me(de(n,e)),u=he(C(c),s),p=`element(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},_=(e,t,n,o)=>{const r=Pe(e,t);n[`/${r}`]=g(r,fe(e),o)};function K(e,t,n,o,r,s,a,i,c){const p={},l=e.replace(/^\/+/,""),h=u.default.sync(l,{cwd:t,absolute:!0,onlyFiles:!0}).filter(ye);for(const u of h)if("component"===r){if(u.includes(".config."))continue;I(u,n,o,p,s,a,c)}else _(u,n,p,i);return p}var H=async(e,t,n,o,r,s)=>{const a=new Map,i=new Set,c=new Map;we(o,((e,t,n,o)=>{let r=e;for(const[s,a]of t){const e=z(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of n)r=r.replace(s,a);return be(r)})(function(e,t,n,o){const r=n.length>0?`\n${n.join("\n")}\n`:"";return`// Auto-generated by ono-auto-router\n${o?"import type { RouteObject } from 'react-router-dom'\n":""}${t.join("\n")}${o?"\n\ntype PageConfig = Partial<\n Omit<RouteObject, 'path' | 'Component' | 'element' | 'children'> & {\n type?: 'single' | 'wrap'\n }\n>\n":""}${o?"\nexport const defineConfig = (config: PageConfig) => config":""}\n${r}\nexport const routes${o?": RouteObject[]":""} = ${JSON.stringify(e,null,2)}\n`}(L(await T(K("/**/*.{jsx,tsx}",t,n,o,"component",a,i,c,s),K("/**/*.config.{js,ts,jsx,tsx}",t,n,o,"config",a,i,c,s),e,s)),((e,t)=>{if(e)return["import { lazy, Suspense } from 'react'"];const n=[];for(const o of t.values())n.push(z(o.componentName,o.path).import);return n})(r,a),((e,t)=>{if(!e)return[];const n=[];for(const o of t.values())n.push(z(o.componentName,o.path).lazy);return n})(r,a),s),a,c,r))},U=(e,t,n,o)=>{const r=t.split(".")[0],s=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(o),a=n?((e,t)=>`\nconst PATH_REPLACEMENTS${t?": Record<string, string>":""} = {\n '/home': '/',\n '/root': '/'\n}\n\nconst cachedLazyComponents${t?": Record<\n string,\n LazyExoticComponent<ComponentType<unknown>>\n>":""} = {}\n\nconst getConfigFileName = ${t?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${t?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${t?"ts":"js"}'\n }\n return pagePath.replace('index.${t?"ts":"js"}', 'index.config.${t?"ts":"js"}')\n}\n\nconst formatPageModule = (${t?"\n pagesComponent: Record<string, ComponentType<unknown>>,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${t?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${t?"(pathStr: string): string":"(pathStr)"} => {\n if (PATH_REPLACEMENTS[pathStr]) {\n return PATH_REPLACEMENTS[pathStr]\n }\n\n const lowerPath = pathStr.toLowerCase()\n if (lowerPath === '/notfound' || pathStr === '/404') {\n return '/*'\n }\n\n return pathStr\n}\n\nconst getBasename = ${t?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1]\n if (ext && lastPart.endsWith(ext)) {\n return lastPart.slice(0, -ext.length)\n }\n return lastPart\n}\n\nconst getDirname = ${t?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${t?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${t?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${t?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n if (fileName === 'index') {\n return dirPath || '/'\n }\n return dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n return (\n configPath.replace('/${e}', '').replace('/index.config.${t?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${t?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${t?": Record<string, unknown>":""} = {}\n\n for (const [path, module] of Object.entries(modules)) {\n if ('default' in module) {\n result[path] = module.default\n }\n }\n\n return result\n}\n\nconst filterUnComponent = ${t?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${t?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${t?"tsx":"jsx"}')) {\n result[key] = pagesComponent[key]\n }\n }\n\n return result\n}\n\nconst LazyComponent = ({\n Element\n}${t?": {\n Element: LazyExoticComponent<ComponentType<unknown>>\n}":""}) => {\n return (\n <Suspense>\n <Element />\n </Suspense>\n )\n}\n\nconst createBaseRoutes = () => {\n const pagesComponent = filterUnComponent({\n ...import.meta.glob('/${e}/**/*.${t?"tsx":"jsx"}')${t?" as PagesComponentType":""}\n })\n\n const pagesString = getFileDefault({\n ...import.meta.glob('/${e}/**/*.${t?"tsx":"jsx"}', {\n eager: true\n })\n })${t?" as Record<string, ComponentType<unknown>>":""}\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${t?"ts":"js"}', {\n eager: true\n })\n })${t?" as Record<string, PageConfig>":""}\n\n const result${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const [pagePath, page] of formatPageModule(pagesString, pagesModule)) {\n const compPath = getCompPathFromConfig(pagePath)\n\n if (!pagesComponent[compPath]) continue\n\n const rawPath = getRawPathFromConfig(pagePath) || '/'\n const processedPath = replaceBracketsWithColon(rawPath)\n const routePath = normalizePath(processedPath)\n\n let Component${t?": MyRouteObject['element']":""}\n if (!cachedLazyComponents[compPath]) {\n cachedLazyComponents[compPath] = lazy(pagesComponent[compPath])\n }\n Component = <LazyComponent Element={cachedLazyComponents[compPath]} />\n\n result.push({\n ...page,\n path: routePath,\n type: page?.type,\n isRoot: processedPath === '/root',\n element: Component\n })\n }\n\n return result\n}`)(e,o):((e,t)=>`\nconst PATH_REPLACEMENTS${t?": Record<string, string>":""} = {\n '/home': '/',\n '/root': '/'\n}\n\nconst getConfigFileName = ${t?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${t?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${t?"ts":"js"}'\n }\n return pagePath.replace('index.${t?"ts":"js"}', 'index.config.${t?"ts":"js"}')\n}\n\nconst formatPageModule = (${t?"\n pagesComponent: PagesComponentType,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${t?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${t?"(pathStr: string): string":"(pathStr)"} => {\n if (PATH_REPLACEMENTS[pathStr]) {\n return PATH_REPLACEMENTS[pathStr]\n }\n\n const lowerPath = pathStr.toLowerCase()\n if (lowerPath === '/notfound' || pathStr === '/404') {\n return '/*'\n }\n\n return pathStr\n}\n\nconst getBasename = ${t?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1]\n if (ext && lastPart.endsWith(ext)) {\n return lastPart.slice(0, -ext.length)\n }\n return lastPart\n}\n\nconst getDirname = ${t?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${t?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${t?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${t?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n if (fileName === 'index') {\n return dirPath || '/'\n }\n return dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n return (\n configPath.replace('/${e}', '').replace('/index.config.${t?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${t?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${t?": PagesComponentType | Record<string, PageConfig>":""} = {}\n\n for (const [path, module] of Object.entries(modules)) {\n if ('default' in module) {\n result[path] = module.default${t?" as ComponentType<unknown> | PageConfig":""}\n }\n }\n\n return result\n}\n\nconst filterUnComponent = ${t?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${t?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${t?"tsx":"jsx"}')) {\n result[key] = pagesComponent[key]\n }\n }\n\n return result\n}\n\nconst createBaseRoutes = () => {\n const pagesComponent = filterUnComponent(\n getFileDefault({\n ...import.meta.glob('/${e}/**/*.${t?"tsx":"jsx"}', { eager: true })\n })${t?" as PagesComponentType":""}\n )\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${t?"ts":"js"}', {\n eager: true\n })\n })${t?" as Record<string, PageConfig>":""}\n\n const result${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const [pagePath, page] of formatPageModule(pagesComponent, pagesModule)) {\n const compPath = getCompPathFromConfig(pagePath)\n\n if (!pagesComponent[compPath]) continue\n\n const rawPath = getRawPathFromConfig(pagePath) || '/'\n const processedPath = replaceBracketsWithColon(rawPath)\n const routePath = normalizePath(processedPath)\n\n const Component = pagesComponent[compPath]\n result.push({\n ...page,\n path: routePath,\n type: page?.type,\n isRoot: processedPath === '/root',\n element: <Component />\n })\n }\n\n return result\n}`)(e,o),i=(e=>`\nconst processRoute = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} =>\n cleanIsRoot(removeEmptyChildren(route))\n\nconst processRoutes = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} =>\n buildRouteTree(routes).map(processRoute)\n\nconst handleRootRoute = ${e?"(routes: (MyRouteObject & { isRoot?: boolean })[])":"(routes)"} => {\n let rootRoute${e?": MyRouteObject | undefined":" = undefined"}\n let homeRoute${e?": MyRouteObject | undefined":" = undefined"}\n let notFoundRoute${e?": MyRouteObject | undefined":" = undefined"}\n const filteredRoutes${e?": MyRouteObject[]":""} = []\n\n for (const route of routes) {\n if (route.isRoot) {\n if (rootRoute)\n throw new Error('There cannot be multiple root routes in a route')\n rootRoute = route\n } else if (route.path === '/') {\n homeRoute = route\n } else if (route.path === '/*') {\n notFoundRoute = route\n } else {\n filteredRoutes.push(route)\n }\n }\n\n if (hasDuplicateProperty(filteredRoutes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n const children = [\n homeRoute && { ...homeRoute, index: true },\n ...processRoutes(filteredRoutes)\n ].filter(${e?"(route): route is NonNullable<typeof route> => Boolean(route)":"Boolean"})\n\n const result${e?": MyRouteObject[]":""} = []\n\n if (rootRoute) {\n result.push(cleanIsRoot({ ...rootRoute, children }))\n }\n\n if (notFoundRoute) {\n result.push(cleanIsRoot(notFoundRoute))\n }\n\n return result\n}\n\nconst formatRoutes = (\n routes${e?": (MyRouteObject & { isRoot?: boolean })[]":""}\n) => {\n if (routes.some(r => r.isRoot)) return handleRootRoute(routes)\n\n if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return processRoutes(routes)\n}`)(o),u=(e=>`\nconst processSingleRoute = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n if (route.index) {\n return route\n }\n\n if (route.type !== 'wrap') {\n const { path: routePath, children, ...extraProps } = route\n const hasExtraProps = Object.keys(extraProps).length > 0\n\n if (hasExtraProps) {\n const indexRoute${e?": MyRouteObject":""} = {\n path: '',\n index: true,\n ...extraProps\n }\n\n return {\n path: routePath,\n children: [indexRoute, ...(children || []).map(processSingleRoute)]\n }\n }\n }\n\n if (route.children) {\n return {\n ...route,\n children: route.children.map(processSingleRoute)\n }\n }\n\n return route\n}\n\nconst formatRouteTree = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n return routes.map(processSingleRoute)\n}\n\nconst buildTreeStructure = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n const routeMap = new Map${e?"<string, MyRouteObject>":""}()\n const rootRoutes${e?": MyRouteObject[]":""} = []\n const pathPartsCache = new Map${e?"<string, string[]>":""}()\n\n const getPathParts = ${e?"(pathStr: string): string[]":"(pathStr)"} => {\n let parts = pathPartsCache.get(pathStr)\n if (parts === undefined) {\n parts = pathStr === '/' ? [] : pathStr.split('/').filter(Boolean)\n pathPartsCache.set(pathStr, parts)\n }\n return parts\n }\n\n const sortedRoutes = routes\n .slice()\n .sort((a, b) => a.path.length - b.path.length)\n\n for (const route of sortedRoutes) {\n const routePath = route.path\n const pathParts = getPathParts(routePath)\n const currentRoute = { ...route, children: [] }\n routeMap.set(routePath, currentRoute)\n\n if (pathParts.length <= 1) {\n rootRoutes.push(currentRoute)\n continue\n }\n\n const parentPath = '/' + pathParts.slice(0, -1).join('/')\n const parentRoute = routeMap.get(parentPath)\n\n if (parentRoute) {\n currentRoute.path = pathParts[pathParts.length - 1]\n parentRoute.children${e?"!":""}.push(currentRoute)\n } else {\n rootRoutes.push(currentRoute)\n }\n }\n\n return rootRoutes\n}\n\nconst buildRouteTree = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n const treeStructure = buildTreeStructure(routes)\n return formatRouteTree(treeStructure)\n}`)(o),p=(e=>`\nconst cleanIsRoot = ${e?"(route: RouteWithIsRoot): MyRouteObject":"(route)"} => {\n const { isRoot, type, children, ...rest } = route${e?" as RouteWithIsRoot & {\n type?: unknown\n }":""}\n\n if (!children?.length) {\n return rest\n }\n\n return {\n ...rest,\n children: children.map(cleanIsRoot)\n }\n}`)(o),l=(e=>`\nconst removeEmptyChildren = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n const { children } = route\n\n if (!children?.length) {\n const { children: _, ...rest } = route\n return rest\n }\n\n const processedChildren = children.map(removeEmptyChildren)\n\n if (route.type === 'wrap') {\n return { ...route, children: processedChildren }\n }\n\n const { path, element, type, children: _, ...rest } = route\n\n if (!element) {\n return { path, ...rest, children: processedChildren }\n }\n\n return {\n path,\n children: [\n { index: true, element, ...rest }${e?" as MyRouteObject":""},\n ...processedChildren\n ]\n }\n}`)(o),h=o?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",f=(e=>`\nconst getRoutes = () => {\n const baseRoutes = createBaseRoutes()\n const formattedRoutes = formatRoutes(baseRoutes)${e?" as RouteObject[]":""}\n return formattedRoutes\n}\n\nexport const routes = getRoutes()`)(o),d=((e,t,n,o,r,s,a,i)=>`// Auto-generated by ono-auto-router${e}${t}${n}${o}${r}${s}${a}${i}\n`)(((e,t)=>e?`\n${t?"import {\n lazy,\n Suspense,\n type ComponentType,\n type LazyExoticComponent\n} from 'react'":"import type { ComponentType } from 'react'"}\nimport type { RouteObject } from 'react-router-dom'\n\n${t?"type PagesComponentType = Record<\n string,\n () => Promise<{ default: ComponentType<unknown> }>\n>":"type PagesComponentType = Record<string, ComponentType<unknown>>"}\n\ninterface MyRouteObject extends Omit<RouteObject, 'path' | 'children'> {\n path: string\n type?: 'single' | 'wrap'\n children?: MyRouteObject[]\n}\n\ntype RouteWithIsRoot = MyRouteObject & { isRoot?: boolean }\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'Component' | 'element' | 'children' | 'path'>\n>`:t?"\nimport { lazy, Suspense } from 'react'\n":"")(o,n),(e=>`\nconst hasDuplicateProperty = ${e?"<T, K extends keyof T>(items: T[], propName: K)":"(items, propName)"} => {\n const seenValues = new Set()\n return items.some(item => {\n if (seenValues.has(item[propName])) {\n return true\n }\n seenValues.add(item[propName])\n return false\n })\n}\n\nconst replaceBracketsWithColon = ${e?"(str: string)":"(str)"} => {\n return str.replace(/\\[([^\\]]+)\\]/g, ':$1').replace('.tsx', '')\n}`)(o),l,p,u,i,a,f);o?(we(c.default.resolve(r,"./index.ts"),s),we(c.default.resolve(r,"./autoRouter.tsx"),d),we(c.default.resolve(r,"./defineConfig.ts"),h)):we(t,d)},V={"/home":"/","/root":"/"},X=(e,t)=>{const n=e.split("/"),o=n[n.length-1];return t&&o.endsWith(t)?o.slice(0,-t.length):o},q=e=>{const t=V[e];return t||("/notfound"===e.toLowerCase()||"/404"===e?"/:pathMatch(.*)*":e)},J=(e,t)=>e.endsWith(".config."+(t?"ts":"js"))?"index"===X(e,".config."+(t?"ts":"js"))?e.replace("index.config."+(t?"ts":"js"),"index."+(t?"ts":"js")):e.slice(0,-10)+".vue":e.replace("index.config."+(t?"ts":"js"),"index."+(t?"ts":"js")),Z=(e,t,n)=>{if(e.endsWith(".config."+(n?"ts":"js"))){const o=X(e,".config."+(n?"ts":"js")),r=(e=>{const t=e.split("/");return t.pop(),t.join("/")})(e).replace(t,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(t,"").replace("/index.config."+(n?"ts":"js"),"")||"/"},G=async(e,t,n,o)=>{const r=[];for(const[s,a]of((e,t,n)=>Object.keys(e).map(e=>{const o=((e,t)=>e.replace("index."+(t?"ts":"js"),"index.config."+(t?"ts":"js")))(e,n);return[o,t[o]||{}]}))(e,t,o)){const t=J(s,o),i=xe(Z(s,`/${n}`,o)||"/",o,"vue"),c=q(i);r.push({...a,path:c,type:a?.type,isRoot:"/root"===i,component:e[t]})}return r},Q=e=>{if(!e.path)return e;if("wrap"!==e.type){const{path:t,children:n,...o}=e;if(Object.keys(o).length>0)return{path:t,children:[{path:"",...o},...(n||[]).map(Q)]}}return e.children?{...e,children:e.children.map(Q)}:e},Y=e=>(e=>e.map(Q))((e=>{const t=new Map,n=[],o=new Map,r=e=>{let t=o.get(e);return void 0===t&&(t="/"===e?[]:e.split("/").filter(Boolean),o.set(e,t)),t},s=e.slice().sort((e,t)=>e.path.length-t.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(t.set(e,s),o.length<=1){n.push(s);continue}const i="/"+o.slice(0,-1).join("/"),c=t.get(i);c?(s.path=o[o.length-1],c.children.push(s)):n.push(s)}return n})(e)),ee=e=>{const{isRoot:t,type:n,children:o,...r}=e;return o?.length?{...r,children:o.map(ee)}:r},te=e=>{const{children:t}=e;if(!t?.length){const{children:t,...n}=e;return n}const n=t.map(te);if("wrap"===e.type)return{...e,children:n};const{path:o,component:r,type:s,children:a,...i}=e;return r?{path:o,children:[{path:"",component:r,...i},...n]}:{path:o,...i,children:n}},ne=e=>ee(te(e)),oe=e=>Y(e).map(ne),re=e=>{if(e.some(e=>e.isRoot))return(e=>{let t,n,o;const r=[];for(const i of e)if(i.isRoot){if(t)throw new Error("There cannot be multiple root routes in a route");t=i}else"/"===i.path?n=i:"/:pathMatch(.*)*"===i.path?o=i:r.push(i);if($e(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[n&&{...n,index:!0},...oe(r)].filter(e=>Boolean(e)),a=[];return t&&a.push(ee({...t,children:s})),o&&a.push(ee(o)),a})(e);if($e(e,"path"))throw new Error("There cannot be duplicate paths in a route");return oe(e)},se=(e,t)=>({import:`import ${e} from './${t}'`,component:`<start>${e}</end>`,lazyComponent:`<start>() => import('${t}')</end>`});var ae=(e,t,n,o,r,s,a)=>{const i=((e,t)=>e.replace("index.vue",t?Me:ve))(Pe(e,t),a),c=me(de(n,e)),u=he(C(c),s),p=`component(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},ie=(e,t,n,o)=>{const r=Pe(e,t);n[`/${r}`]=g(r,fe(e),o)};function ce(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(ye);for(const u of f)if("component"===r){if(u.includes(".config."))continue;ae(u,n,o,p,s,a,c)}else ie(u,n,p,i);return p}var ue=async(e,t,n,o,r,s)=>{const a=new Map,i=new Set,c=new Map;we(o,((e,t,n,o)=>{let r=e;for(const[s,a]of t){const e=se(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of n)r=r.replace(s,a);return be(r)})(function(e,t,n,o){return`// Auto-generated by ono-auto-router${n?"\nimport type { RouteRecordRaw } from 'vue-router'":""}${o?"":`\n${t.join("\n")}${n?"":"\n"}`}${n?"\n\ntype PageConfig = Partial<\n Omit<RouteRecordRaw, 'path' | 'component' | 'children'> & {\n type?: 'single' | 'wrap'\n }\n>\n":""}${n?"\nexport const defineConfig = (config: PageConfig) => config\n":""}\nexport const routes${n?": RouteRecordRaw[]":""} = ${JSON.stringify(e,null,2)}\n`}(re(await G(ce("/**/*.vue",t,n,o,"component",a,i,c,s),ce("/**/*.config.{js,ts}",t,n,o,"config",a,i,c,s),e,s)),((e,t)=>{if(e)return[];const n=[];for(const o of t.values())n.push(se(o.componentName,o.path).import);return n})(r,a),s,r),a,c,r))},pe=(e,t,n,o)=>{const r=t.split(".")[0],s=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(n),a=((e,t,n)=>`\nconst pathCache = new Map${t?"<string, { compPath: string; basePath: string }>":""}()\nconst basenameCache = new Map${t?"<string, string>":""}()\n\nconst normalizePagePath = ${t?"(key: string): string":"(key)"} => {\n if (key.includes('index.vue')) return key.replace('index.vue', 'index.${t?"ts":"js"}')\n if (key.includes('root.vue')) return key.replace('root.vue', 'root/index.${t?"ts":"js"}')\n if (key.includes('404.vue')) return key.replace('404.vue', '404/index.${t?"ts":"js"}')\n if (key.toLowerCase().includes('notfound.vue'))\n return key.toLowerCase().replace('notfound.vue', 'notfound/index.${t?"ts":"js"}')\n return key\n}\n\nconst getBasename = ${t?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const cacheKey = ext ? filePath + ':' + ext : filePath\n if (basenameCache.has(cacheKey)) {\n return basenameCache.get(cacheKey)${t?"!":""}\n }\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1] || ''\n let result = lastPart\n if (ext && lastPart.endsWith(ext)) {\n result = lastPart.slice(0, -ext.length)\n }\n basenameCache.set(cacheKey, result)\n return result\n}\n\nconst getDirname = ${t?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getPathsFromConfig = ${t?"(configPath: string)":"(configPath)"} => {\n const cacheKey = configPath\n if (pathCache.has(cacheKey)) {\n return pathCache.get(cacheKey)${t?"!":""}\n }\n\n let compPath${t?": string":" = ''"}\n let basePath${t?": string":" = ''"}\n\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n\n if (fileName === 'index') {\n compPath = configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"ts":"js"}')\n basePath = dirPath || '/'\n } else {\n compPath = configPath.slice(0, -10) + '.vue'\n basePath = dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n } else {\n compPath = configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"ts":"js"}')\n basePath =\n configPath.replace('/${e}', '').replace('/index.config.${t?"ts":"js"}', '') ||\n '/'\n }\n\n const result = { compPath, basePath }\n pathCache.set(cacheKey, result)\n return result\n}\n\nconst formatPath = ${t?"(path: string): string":"(path)"} => {\n const lowerPath = path.toLowerCase()\n if (lowerPath === '/home') return '/'\n if (lowerPath === '/notfound' || path === '/404') return '/:pathMatch(.*)*'\n return path.replace('/index.${t?"ts":"js"}', '') || '/'\n}\n\nconst getConfigFileName = ${t?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.vue')) {\n return pagePath.slice(0, -4) + '.config.${t?"ts":"js"}'\n }\n return pagePath.replace('index.${t?"ts":"js"}', 'index.config.${t?"ts":"js"}')\n}\n\nconst createBaseRoutes = ()${t?": MyRouteObject[]":""} => {\n const pagesComponent = Object.fromEntries(\n Object.entries({\n ...import.meta.glob('/${e}/**/index.vue'${n?"":", { eager: true, import: 'default' }"}),\n ...import.meta.glob('/${e}/*.vue'${n?"":", { eager: true, import: 'default' }"})\n }${t?" as PagesComponentType":""}).map(([key, value]) => [\n normalizePagePath(key),\n value\n ])\n )\n\n const pagesModule${t?": Record<string, PageConfig>":""} = import.meta.glob(\n '/${e}/**/*.config.${t?"ts":"js"}',\n { eager: true, import: 'default' }\n )\n\n const result${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const pagePath of Object.keys(pagesComponent)) {\n const configPath = getConfigFileName(pagePath)\n const content = pagesModule[configPath] || {}\n const { compPath, basePath } = getPathsFromConfig(configPath)\n const path = replaceBracketsWithColon(basePath || '/')\n const name = path.split('/').filter(Boolean).join('-') || 'index'\n\n result.push({\n path: formatPath(path),\n name,\n component: pagesComponent[compPath],\n isRoot: path === '/root',\n ...content${t?"!":""}\n })\n }\n\n return result\n}\n\nconst processRoutes = ${t?"(\n routes: MyRouteObject[],\n removeLeadingSlash = false\n): MyRouteObject[]":"(routes, removeLeadingSlash)"} =>\n buildRouteTree(routes, removeLeadingSlash)\n .map(removeEmptyChildren)\n .map(cleanIsRoot)\n\nconst handleRootRoute = ${t?"(\n routes: (MyRouteObject & { isRoot?: boolean })[]\n): MyRouteObject[]":"(routes)"} => {\n let rootRoute${t?": (MyRouteObject & { isRoot?: boolean }) | undefined":" = undefined"}\n let homeRoute${t?": MyRouteObject | undefined":" = undefined"}\n let notFoundRoute${t?": MyRouteObject | undefined":" = undefined"}\n const filteredRoutes${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const route of routes) {\n if (route.isRoot) {\n if (rootRoute)\n throw new Error('There cannot be multiple root routes in a route')\n rootRoute = route\n } else if (route.path === '/') {\n homeRoute = route\n } else if (route.path === '/:pathMatch(.*)*') {\n notFoundRoute = route\n } else {\n filteredRoutes.push(route)\n }\n }\n\n if (hasDuplicateProperty(filteredRoutes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n const processedRoutes${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n if (rootRoute) {\n const children = [\n homeRoute && { ...homeRoute, path: '' },\n ...processRoutes(filteredRoutes, true)\n ].filter(Boolean)${t?" as MyRouteObject[]":""}\n processedRoutes.push({ ...rootRoute, path: '/', children })\n }\n\n if (notFoundRoute) processedRoutes.push(notFoundRoute)\n\n return processedRoutes.map(cleanIsRoot)\n}\n\nconst createRoutes = ()${t?": RouteRecordRaw[]":""} => {\n const routes = createBaseRoutes()\n\n if (routes.some((r${t?": MyRouteObject & { isRoot?: boolean }":""}) => r.isRoot))\n return handleRootRoute(routes)${t?" as RouteRecordRaw[]":""}\n\n if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return processRoutes(routes)${t?" as RouteRecordRaw[]":""}\n}\n`)(e,n,o),i=(e=>`\nconst buildRouteTree = ${e?"(\n routes: MyRouteObject[],\n removeLeadingSlash: boolean = false\n)":"(routes, removeLeadingSlash)"} => {\n const routeMap = new Map${e?"<string, MyRouteObject & { isRoot?: boolean }>":""}()\n const rootRoutes${e?": MyRouteObject[]":""} = []\n\n const sortedRoutes = [...routes].sort((a, b) => a.path.length - b.path.length)\n\n for (const route of sortedRoutes) {\n let path = route.path\n if (removeLeadingSlash && path.startsWith('/')) {\n path = path.slice(1)\n }\n routeMap.set(path, { ...route, path, children: [] })\n }\n\n for (const [path, route] of routeMap) {\n const slashIndex = path.lastIndexOf('/')\n\n if (slashIndex <= 0) {\n const { isRoot, ...rest } = route\n rootRoutes.push(rest)\n continue\n }\n\n const parentPath = path.slice(0, slashIndex)\n const parentRoute = routeMap.get(parentPath)\n\n if (parentRoute) {\n const relativePath = path.slice(slashIndex + 1)\n const childRoute = { ...route, path: relativePath }\n parentRoute.children${e?"!":""}.push(childRoute)\n } else {\n const { isRoot, ...rest } = route\n rootRoutes.push(rest)\n }\n }\n\n return rootRoutes\n}\n`)(n),u=(e=>`\nconst cleanIsRoot = ${e?"(\n route: MyRouteObject & { isRoot?: boolean }\n): MyRouteObject":"(route)"} => {\n const { isRoot, type, children, ...rest } = route\n const result${e?": MyRouteObject":""} = { ...rest }\n\n if (children?.length) {\n result.children = children.map(cleanIsRoot)\n }\n\n return result\n}\n`)(n),p=(e=>`\nconst removeEmptyChildren = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n if (!route.children?.length) {\n const { children, ...rest } = route\n return rest\n }\n\n const hasIndexRoute = route.children.some(\n child => child.path === '' || child.path === '/'\n )\n\n const routeType = route.type || 'single'\n\n if (routeType === 'wrap') {\n const { children, ...rest } = route\n return { ...rest, children: children.map(removeEmptyChildren) }\n }\n\n if (routeType === 'single' || (!hasIndexRoute && route.component)) {\n const { path, component, type, ...rest } = route\n return {\n path,\n children: [\n { path: '', component, ...rest }${e?" as MyRouteObject":""},\n ...route.children.map(removeEmptyChildren)\n ]\n }\n }\n\n if (hasIndexRoute) {\n const { path, ...rest } = route\n const updatedChildren = route.children.map(child =>\n child.path === '' || child.path === '/' ? { ...rest, ...child } : child\n )\n return { path, children: updatedChildren.map(removeEmptyChildren) }\n }\n\n return { ...route, children: route.children.map(removeEmptyChildren) }\n}\n`)(n),l=n?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",h=((e,t,n,o,r,s,a)=>`// Auto-generated by ono-auto-router${e}${t}${n}${o}${r}${s}${a}\n`)(n?"\nimport type { RouteRecordRaw } from 'vue-router'\n\ntype PagesComponentType = Record<string, () => Promise<unknown>>\n\ninterface MyRouteObject extends Omit<RouteRecordRaw, 'children'> {\n type?: 'single' | 'wrap'\n children?: MyRouteObject[]\n}\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'component' | 'children' | 'path'>\n>\n":"",(e=>`\nconst hasDuplicateProperty = ${e?"<T>(items: T[], propName: keyof T)":"(items, propName)"} => {\n const seenValues = new Set()\n return items.some(item => {\n if (seenValues.has(item[propName])) {\n return true\n }\n seenValues.add(item[propName])\n return false\n })\n}\n\nconst replaceBracketsWithColon = ${e?"(str: string)":"(str)"} => {\n return str.replace(/\\[([^\\]]+)\\]/g, ':$1').replace('.tsx', '')\n}\n`)(n),p,u,i,a,"\nexport const routes = createRoutes()");n?(we(c.default.resolve(r,"./index.ts"),s),we(c.default.resolve(r,"./autoRouter.ts"),h),we(c.default.resolve(r,"./defineConfig.ts"),l)):we(t,h)},le=(e,t,n,o,r,s)=>{const a=c.default.resolve(n,t);if(!i.default.existsSync(a))throw new Error(`Pages directory not found: ${a}`);const u=y(e,n,o),p=P(n),l=u.split(".")[0];f(l+".js"),f(l+".ts"),f(l+".jsx"),f(l+".tsx"),d(l),"react"===e?s?U(t,u,r,p):H(t,a,n,u,r,p):s?pe(t,u,p,r):ue(t,a,n,u,r,p),console.log(`[ono-auto-router] Routes file generated: ${u}`)},he=(e,t)=>{if(!t.has(e))return t.add(e),e;let n=1;for(;t.has(`${e}_${n}`);)n++;return`${e}_${n}`};function fe(e){try{const n=i.default.readFileSync(e,"utf-8").match(/export\s+default\s+([\s\S]*?)(?=\n\w|$)/);if(!n)return console.warn("No export default found in:",e),null;const o=n[1].trim();try{if(o.startsWith("{"))return new Function(`return ${o}`)();if(o.includes("defineConfig(")){const e=o.match(/defineConfig([\s\S]*)$/);if(e)return new Function(`return ${e[1]}`)()}return null}catch(t){return console.error("Error parsing export default content:",t),null}}catch(n){return console.error("Error reading file:",n),null}}function de(e,t){let n=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 ge=/\\/g,me=e=>e.replace(ge,"/"),Pe=(e,t)=>me(c.default.relative(t,e)),Re=/export\s+default\s+[\w(\[\]\{\})]+/;function ye(e){try{if(!i.default.existsSync(e))return console.warn(`File not found: ${e}`),!1;const t=i.default.readFileSync(e,"utf-8");return Re.test(t)}catch(t){return console.error("Read error:",t),!1}}var $e=(e,t)=>{const n=new Set;return e.some(e=>!!n.has(e[t])||(n.add(e[t]),!1))};function je(e){return e.replace(/"<start>([\s\S]*?)<\/end>"/g,"$1")}function be(e){let t=e;for(;;){const e=je(t);if(e===t)break;t=e}return t}var xe=(e,t,n)=>e.replace(/\[([^\]]+)\]/g,":$1").replace("react"===n?t?".tsx":".jsx":".vue","");function Ce(e){i.default.existsSync(e)||i.default.mkdirSync(e,{recursive:!0})}function Oe(e,t){Ce(c.default.dirname(e)),i.default.writeFileSync(e,t,"utf-8")}async function we(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 Me="index.ts",ve="index.js";Object.defineProperty(exports,"INDEX_JS_SUFFIX",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"INDEX_TS_SUFFIX",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,"capitalize",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"convertFunctionToArrow",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"deleteDir",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"deleteFile",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"ensureDirSync",{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,"formatFunction",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"formatPagesDir",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"formatRoutesFile",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"generateComponentName",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"generateReactRoutes",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"generateReactRoutesHMR",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"generateRoutesTemplate",{enumerable:!0,get:function(){return le}}),Object.defineProperty(exports,"generateUniqueComponentName",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"generateVueRoutes",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(exports,"generateVueRoutesHMR",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,"getDefaultExportContent",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,"getRelativePath",{enumerable:!0,get:function(){return de}}),Object.defineProperty(exports,"getRelativeProjectPath",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,"hasDefaultExport",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,"hasDuplicateProperty",{enumerable:!0,get:function(){return $e}}),Object.defineProperty(exports,"normalizePathWithWindows",{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,"removeCustomTagFunctionFromJSXAll",{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,"replaceBracketsWithColon",{enumerable:!0,get:function(){return xe}}),Object.defineProperty(exports,"useTs",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"writeFile",{enumerable:!0,get:function(){return we}}),Object.defineProperty(exports,"writeFileSync",{enumerable:!0,get:function(){return Oe}});
1
+ 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,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=>{const t=O[e];return t||("/notfound"===e.toLowerCase()||"/404"===e?"/*":e)},v=(e,t)=>e.endsWith(".config."+(t?"ts":"js"))?"index"===w(e,".config."+(t?"ts":"js"))?e.replace("index.config."+(t?"ts":"js"),"index."+(t?"ts":"js")):e.slice(0,-10)+"."+(t?"tsx":"jsx"):e.replace("index.config."+(t?"ts":"js"),"index."+(t?"ts":"js")),S=(e,t,n)=>{if(e.endsWith(".config."+(n?"ts":"js"))){const o=w(e,".config."+(n?"ts":"js")),r=(e=>{const t=e.split("/");return t.pop(),t.join("/")})(e).replace(t,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(t,"").replace("/index.config."+(n?"ts":"js"),"")||"/"},T=async(e,t,n,o)=>{const r=[];for(const[s,a]of((e,t,n)=>Object.keys(e).map(e=>{const o=((e,t)=>e.endsWith(t?".tsx":".jsx")?e.slice(0,-4)+".config."+(t?"ts":"js"):e.replace("index."+(t?"ts":"js"),"index.config."+(t?"ts":"js")))(e,n);return[o,t[o]||{}]}))(e,t,o)){const t=v(s,o);if(!e[t])continue;const i=xe(S(s,`/${n}`,o)||"/",o,"react"),c=M(i);r.push({...a,path:c,type:a?.type,isRoot:"/root"===i,element:e[t]})}return r},E=e=>{if(e.index)return e;if("wrap"!==e.type){const{path:t,children:n,...o}=e;if(Object.keys(o).length>0)return{path:t,children:[{path:"",index:!0,...o},...(n||[]).map(E)]}}return e.children?{...e,children:e.children.map(E)}:e},k=e=>(e=>e.map(E))((e=>{const t=new Map,n=[],o=new Map,r=e=>{let t=o.get(e);return void 0===t&&(t="/"===e?[]:e.split("/").filter(Boolean),o.set(e,t)),t},s=e.slice().sort((e,t)=>e.path.length-t.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(t.set(e,s),o.length<=1){n.push(s);continue}const i="/"+o.slice(0,-1).join("/"),c=t.get(i);c?(s.path=o[o.length-1],c.children.push(s)):n.push(s)}return n})(e)),N=e=>{const{isRoot:t,type:n,children:o,...r}=e;return o?.length?{...r,children:o.map(N)}:r},F=e=>{const{children:t}=e;if(!t?.length){const{children:t,...n}=e;return n}const n=t.map(F);if("wrap"===e.type)return{...e,children:n};const{path:o,element:r,type:s,children:a,...i}=e;return r?{path:o,children:[{index:!0,element:r,...i},...n]}:{path:o,...i,children:n}},W=e=>N(F(e)),B=e=>k(e).map(W),L=e=>{if(e.some(e=>e.isRoot))return(e=>{let t,n,o;const r=[];for(const i of e)if(i.isRoot){if(t)throw new Error("There cannot be multiple root routes in a route");t=i}else"/"===i.path?n=i:"/*"===i.path?o=i:r.push(i);if($e(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[n&&{...n,index:!0},...B(r)].filter(e=>Boolean(e)),a=[];return t&&a.push(N({...t,children:s})),o&&a.push(N(o)),a})(e);if($e(e,"path"))throw new Error("There cannot be duplicate paths in a route");return B(e)},z=(e,t)=>({import:`import ${e} from './${t}'`,component:`<start><${e} /></end>`,lazy:`const ${e} = lazy(() => import('${t}'))`,lazyComponent:`<start><Suspense><${e} /></Suspense></end>`});var D="index.tsx",A="index.jsx",I=(e,t,n,o,r,s,a)=>{const i=((e,t)=>e.includes(t?D:A)?e.replace(t?D:A,t?Me:ve):e)(Pe(e,t),a),c=me(de(n,e)),u=he(C(c),s),p=`element(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},_=(e,t,n,o)=>{const r=Pe(e,t);n[`/${r}`]=g(r,fe(e),o)};function K(e,t,n,o,r,s,a,i,c){const p={},l=e.replace(/^\/+/,""),h=u.default.sync(l,{cwd:t,absolute:!0,onlyFiles:!0}).filter(ye);for(const u of h)if("component"===r){if(u.includes(".config."))continue;I(u,n,o,p,s,a,c)}else _(u,n,p,i);return p}var H=async(e,t,n,o,r,s)=>{const a=new Map,i=new Set,c=new Map;we(o,((e,t,n,o)=>{let r=e;for(const[s,a]of t){const e=z(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of n)r=r.replace(s,a);return be(r)})(function(e,t,n,o){const r=n.length>0?`\n${n.join("\n")}\n`:"";return`// Auto-generated by ono-auto-router\n${o?"import type { RouteObject } from 'react-router-dom'\n":""}${t.join("\n")}${o?"\n\ntype PageConfig = Partial<\n Omit<RouteObject, 'path' | 'Component' | 'element' | 'children'> & {\n type?: 'single' | 'wrap'\n }\n>\n":""}${o?"\nexport const defineConfig = (config: PageConfig) => config":""}\n${r}\nexport const routes${o?": RouteObject[]":""} = ${JSON.stringify(e,null,2)}\n`}(L(await T(K("/**/*.{jsx,tsx}",t,n,o,"component",a,i,c,s),K("/**/*.config.{js,ts,jsx,tsx}",t,n,o,"config",a,i,c,s),e,s)),((e,t)=>{if(e)return["import { lazy, Suspense } from 'react'"];const n=[];for(const o of t.values())n.push(z(o.componentName,o.path).import);return n})(r,a),((e,t)=>{if(!e)return[];const n=[];for(const o of t.values())n.push(z(o.componentName,o.path).lazy);return n})(r,a),s),a,c,r))},U=(e,t,n,o)=>{const r=t.split(".")[0],s=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(o),a=n?((e,t)=>`\nconst PATH_REPLACEMENTS${t?": Record<string, string>":""} = {\n '/home': '/',\n '/root': '/'\n}\n\nconst cachedLazyComponents${t?": Record<\n string,\n LazyExoticComponent<ComponentType<unknown>>\n>":""} = {}\n\nconst getConfigFileName = ${t?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${t?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${t?"ts":"js"}'\n }\n return pagePath.replace('index.${t?"ts":"js"}', 'index.config.${t?"ts":"js"}')\n}\n\nconst formatPageModule = (${t?"\n pagesComponent: Record<string, ComponentType<unknown>>,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${t?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${t?"(pathStr: string): string":"(pathStr)"} => {\n if (PATH_REPLACEMENTS[pathStr]) {\n return PATH_REPLACEMENTS[pathStr]\n }\n\n const lowerPath = pathStr.toLowerCase()\n if (lowerPath === '/notfound' || pathStr === '/404') {\n return '/*'\n }\n\n return pathStr\n}\n\nconst getBasename = ${t?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1]\n if (ext && lastPart.endsWith(ext)) {\n return lastPart.slice(0, -ext.length)\n }\n return lastPart\n}\n\nconst getDirname = ${t?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${t?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${t?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${t?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n if (fileName === 'index') {\n return dirPath || '/'\n }\n return dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n return (\n configPath.replace('/${e}', '').replace('/index.config.${t?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${t?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${t?": Record<string, unknown>":""} = {}\n\n for (const [path, module] of Object.entries(modules)) {\n if ('default' in module) {\n result[path] = module.default\n }\n }\n\n return result\n}\n\nconst filterUnComponent = ${t?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${t?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${t?"tsx":"jsx"}')) {\n result[key] = pagesComponent[key]\n }\n }\n\n return result\n}\n\nconst LazyComponent = ({\n Element\n}${t?": {\n Element: LazyExoticComponent<ComponentType<unknown>>\n}":""}) => {\n return (\n <Suspense>\n <Element />\n </Suspense>\n )\n}\n\nconst createBaseRoutes = () => {\n const pagesComponent = filterUnComponent({\n ...import.meta.glob('/${e}/**/*.${t?"tsx":"jsx"}')${t?" as PagesComponentType":""}\n })\n\n const pagesString = getFileDefault({\n ...import.meta.glob('/${e}/**/*.${t?"tsx":"jsx"}', {\n eager: true\n })\n })${t?" as Record<string, ComponentType<unknown>>":""}\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${t?"ts":"js"}', {\n eager: true\n })\n })${t?" as Record<string, PageConfig>":""}\n\n const result${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const [pagePath, page] of formatPageModule(pagesString, pagesModule)) {\n const compPath = getCompPathFromConfig(pagePath)\n\n if (!pagesComponent[compPath]) continue\n\n const rawPath = getRawPathFromConfig(pagePath) || '/'\n const processedPath = replaceBracketsWithColon(rawPath)\n const routePath = normalizePath(processedPath)\n\n let Component${t?": MyRouteObject['element']":""}\n if (!cachedLazyComponents[compPath]) {\n cachedLazyComponents[compPath] = lazy(pagesComponent[compPath])\n }\n Component = <LazyComponent Element={cachedLazyComponents[compPath]} />\n\n result.push({\n ...page,\n path: routePath,\n type: page?.type,\n isRoot: processedPath === '/root',\n element: Component\n })\n }\n\n return result\n}`)(e,o):((e,t)=>`\nconst PATH_REPLACEMENTS${t?": Record<string, string>":""} = {\n '/home': '/',\n '/root': '/'\n}\n\nconst getConfigFileName = ${t?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.${t?"tsx":"jsx"}')) {\n return pagePath.slice(0, -4) + '.config.${t?"ts":"js"}'\n }\n return pagePath.replace('index.${t?"ts":"js"}', 'index.config.${t?"ts":"js"}')\n}\n\nconst formatPageModule = (${t?"\n pagesComponent: PagesComponentType,\n pagesModule: Record<string, PageConfig>\n":"pagesComponent, pagesModule"})${t?": [string, PageConfig][]":""} => {\n return Object.keys(pagesComponent).map(page => {\n const configKey = getConfigFileName(page)\n return [configKey, pagesModule[configKey] || {}]\n })\n}\n\nconst normalizePath = ${t?"(pathStr: string): string":"(pathStr)"} => {\n if (PATH_REPLACEMENTS[pathStr]) {\n return PATH_REPLACEMENTS[pathStr]\n }\n\n const lowerPath = pathStr.toLowerCase()\n if (lowerPath === '/notfound' || pathStr === '/404') {\n return '/*'\n }\n\n return pathStr\n}\n\nconst getBasename = ${t?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1]\n if (ext && lastPart.endsWith(ext)) {\n return lastPart.slice(0, -ext.length)\n }\n return lastPart\n}\n\nconst getDirname = ${t?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getCompPathFromConfig = ${t?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n if (fileName === 'index') {\n return configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"tsx":"jsx"}')\n }\n return configPath.slice(0, -10) + '.${t?"tsx":"jsx"}'\n }\n return configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"tsx":"jsx"}')\n}\n\nconst getRawPathFromConfig = ${t?"(configPath: string): string":"(configPath)"} => {\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n if (fileName === 'index') {\n return dirPath || '/'\n }\n return dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n return (\n configPath.replace('/${e}', '').replace('/index.config.${t?"ts":"js"}', '') || '/'\n )\n}\n\nconst getFileDefault = ${t?"(modules: Record<string, { default: unknown }>)":"(modules)"} => {\n const result${t?": PagesComponentType | Record<string, PageConfig>":""} = {}\n\n for (const [path, module] of Object.entries(modules)) {\n if ('default' in module) {\n result[path] = module.default${t?" as ComponentType<unknown> | PageConfig":""}\n }\n }\n\n return result\n}\n\nconst filterUnComponent = ${t?"(pagesComponent: PagesComponentType)":"(pagesComponent)"} => {\n const result${t?": PagesComponentType":""} = {}\n\n for (const key of Object.keys(pagesComponent)) {\n if (!key.includes('.config.${t?"tsx":"jsx"}')) {\n result[key] = pagesComponent[key]\n }\n }\n\n return result\n}\n\nconst createBaseRoutes = () => {\n const pagesComponent = filterUnComponent(\n getFileDefault({\n ...import.meta.glob('/${e}/**/*.${t?"tsx":"jsx"}', { eager: true })\n })${t?" as PagesComponentType":""}\n )\n\n const pagesModule = getFileDefault({\n ...import.meta.glob('/${e}/**/*.config.${t?"ts":"js"}', {\n eager: true\n })\n })${t?" as Record<string, PageConfig>":""}\n\n const result${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const [pagePath, page] of formatPageModule(pagesComponent, pagesModule)) {\n const compPath = getCompPathFromConfig(pagePath)\n\n if (!pagesComponent[compPath]) continue\n\n const rawPath = getRawPathFromConfig(pagePath) || '/'\n const processedPath = replaceBracketsWithColon(rawPath)\n const routePath = normalizePath(processedPath)\n\n const Component = pagesComponent[compPath]\n result.push({\n ...page,\n path: routePath,\n type: page?.type,\n isRoot: processedPath === '/root',\n element: <Component />\n })\n }\n\n return result\n}`)(e,o),i=(e=>`\nconst processRoute = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} =>\n cleanIsRoot(removeEmptyChildren(route))\n\nconst processRoutes = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} =>\n buildRouteTree(routes).map(processRoute)\n\nconst handleRootRoute = ${e?"(routes: (MyRouteObject & { isRoot?: boolean })[])":"(routes)"} => {\n let rootRoute${e?": MyRouteObject | undefined":" = undefined"}\n let homeRoute${e?": MyRouteObject | undefined":" = undefined"}\n let notFoundRoute${e?": MyRouteObject | undefined":" = undefined"}\n const filteredRoutes${e?": MyRouteObject[]":""} = []\n\n for (const route of routes) {\n if (route.isRoot) {\n if (rootRoute)\n throw new Error('There cannot be multiple root routes in a route')\n rootRoute = route\n } else if (route.path === '/') {\n homeRoute = route\n } else if (route.path === '/*') {\n notFoundRoute = route\n } else {\n filteredRoutes.push(route)\n }\n }\n\n if (hasDuplicateProperty(filteredRoutes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n const children = [\n homeRoute && { ...homeRoute, index: true },\n ...processRoutes(filteredRoutes)\n ].filter(${e?"(route): route is NonNullable<typeof route> => Boolean(route)":"Boolean"})\n\n const result${e?": MyRouteObject[]":""} = []\n\n if (rootRoute) {\n result.push(cleanIsRoot({ ...rootRoute, children }))\n }\n\n if (notFoundRoute) {\n result.push(cleanIsRoot(notFoundRoute))\n }\n\n return result\n}\n\nconst formatRoutes = (\n routes${e?": (MyRouteObject & { isRoot?: boolean })[]":""}\n) => {\n if (routes.some(r => r.isRoot)) return handleRootRoute(routes)\n\n if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return processRoutes(routes)\n}`)(o),u=(e=>`\nconst processSingleRoute = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n if (route.index) {\n return route\n }\n\n if (route.type !== 'wrap') {\n const { path: routePath, children, ...extraProps } = route\n const hasExtraProps = Object.keys(extraProps).length > 0\n\n if (hasExtraProps) {\n const indexRoute${e?": MyRouteObject":""} = {\n path: '',\n index: true,\n ...extraProps\n }\n\n return {\n path: routePath,\n children: [indexRoute, ...(children || []).map(processSingleRoute)]\n }\n }\n }\n\n if (route.children) {\n return {\n ...route,\n children: route.children.map(processSingleRoute)\n }\n }\n\n return route\n}\n\nconst formatRouteTree = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n return routes.map(processSingleRoute)\n}\n\nconst buildTreeStructure = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n const routeMap = new Map${e?"<string, MyRouteObject>":""}()\n const rootRoutes${e?": MyRouteObject[]":""} = []\n const pathPartsCache = new Map${e?"<string, string[]>":""}()\n\n const getPathParts = ${e?"(pathStr: string): string[]":"(pathStr)"} => {\n let parts = pathPartsCache.get(pathStr)\n if (parts === undefined) {\n parts = pathStr === '/' ? [] : pathStr.split('/').filter(Boolean)\n pathPartsCache.set(pathStr, parts)\n }\n return parts\n }\n\n const sortedRoutes = routes\n .slice()\n .sort((a, b) => a.path.length - b.path.length)\n\n for (const route of sortedRoutes) {\n const routePath = route.path\n const pathParts = getPathParts(routePath)\n const currentRoute = { ...route, children: [] }\n routeMap.set(routePath, currentRoute)\n\n if (pathParts.length <= 1) {\n rootRoutes.push(currentRoute)\n continue\n }\n\n const parentPath = '/' + pathParts.slice(0, -1).join('/')\n const parentRoute = routeMap.get(parentPath)\n\n if (parentRoute) {\n currentRoute.path = pathParts[pathParts.length - 1]\n parentRoute.children${e?"!":""}.push(currentRoute)\n } else {\n rootRoutes.push(currentRoute)\n }\n }\n\n return rootRoutes\n}\n\nconst buildRouteTree = ${e?"(routes: MyRouteObject[]): MyRouteObject[]":"(routes)"} => {\n const treeStructure = buildTreeStructure(routes)\n return formatRouteTree(treeStructure)\n}`)(o),p=(e=>`\nconst cleanIsRoot = ${e?"(route: RouteWithIsRoot): MyRouteObject":"(route)"} => {\n const { isRoot, type, children, ...rest } = route${e?" as RouteWithIsRoot & {\n type?: unknown\n }":""}\n\n if (!children?.length) {\n return rest\n }\n\n return {\n ...rest,\n children: children.map(cleanIsRoot)\n }\n}`)(o),l=(e=>`\nconst removeEmptyChildren = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n const { children } = route\n\n if (!children?.length) {\n const { children: _, ...rest } = route\n return rest\n }\n\n const processedChildren = children.map(removeEmptyChildren)\n\n if (route.type === 'wrap') {\n return { ...route, children: processedChildren }\n }\n\n const { path, element, type, children: _, ...rest } = route\n\n if (!element) {\n return { path, ...rest, children: processedChildren }\n }\n\n return {\n path,\n children: [\n { index: true, element, ...rest }${e?" as MyRouteObject":""},\n ...processedChildren\n ]\n }\n}`)(o),h=o?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",f=(e=>`\nconst getRoutes = () => {\n const baseRoutes = createBaseRoutes()\n const formattedRoutes = formatRoutes(baseRoutes)${e?" as RouteObject[]":""}\n return formattedRoutes\n}\n\nexport const routes = getRoutes()`)(o),d=((e,t,n,o,r,s,a,i)=>`// Auto-generated by ono-auto-router${e}${t}${n}${o}${r}${s}${a}${i}\n`)(((e,t)=>e?`\n${t?"import {\n lazy,\n Suspense,\n type ComponentType,\n type LazyExoticComponent\n} from 'react'":"import type { ComponentType } from 'react'"}\nimport type { RouteObject } from 'react-router-dom'\n\n${t?"type PagesComponentType = Record<\n string,\n () => Promise<{ default: ComponentType<unknown> }>\n>":"type PagesComponentType = Record<string, ComponentType<unknown>>"}\n\ninterface MyRouteObject extends Omit<RouteObject, 'path' | 'children'> {\n path: string\n type?: 'single' | 'wrap'\n children?: MyRouteObject[]\n}\n\ntype RouteWithIsRoot = MyRouteObject & { isRoot?: boolean }\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'Component' | 'element' | 'children' | 'path'>\n>`:t?"\nimport { lazy, Suspense } from 'react'\n":"")(o,n),(e=>`\nconst hasDuplicateProperty = ${e?"<T, K extends keyof T>(items: T[], propName: K)":"(items, propName)"} => {\n const seenValues = new Set()\n return items.some(item => {\n if (seenValues.has(item[propName])) {\n return true\n }\n seenValues.add(item[propName])\n return false\n })\n}\n\nconst replaceBracketsWithColon = ${e?"(str: string)":"(str)"} => {\n return str.replace(/\\[([^\\]]+)\\]/g, ':$1').replace('.tsx', '')\n}`)(o),l,p,u,i,a,f);o?(we(c.default.resolve(r,"./index.ts"),s),we(c.default.resolve(r,"./autoRouter.tsx"),d),we(c.default.resolve(r,"./defineConfig.ts"),h)):we(t,d)},V={"/home":"/","/root":"/"},X=(e,t)=>{const n=e.split("/"),o=n[n.length-1];return t&&o.endsWith(t)?o.slice(0,-t.length):o},q=e=>{const t=V[e];return t||("/notfound"===e.toLowerCase()||"/404"===e?"/:pathMatch(.*)*":e)},J=(e,t)=>e.endsWith(".config."+(t?"ts":"js"))?"index"===X(e,".config."+(t?"ts":"js"))?e.replace("index.config."+(t?"ts":"js"),"index."+(t?"ts":"js")):e.slice(0,-10)+".vue":e.replace("index.config."+(t?"ts":"js"),"index."+(t?"ts":"js")),Z=(e,t,n)=>{if(e.endsWith(".config."+(n?"ts":"js"))){const o=X(e,".config."+(n?"ts":"js")),r=(e=>{const t=e.split("/");return t.pop(),t.join("/")})(e).replace(t,"");return"index"===o?r||"/":r?`${r}/${o}`:`/${o}`}return e.replace(t,"").replace("/index.config."+(n?"ts":"js"),"")||"/"},G=async(e,t,n,o)=>{const r=[];for(const[s,a]of((e,t,n)=>Object.keys(e).map(e=>{const o=((e,t)=>e.replace("index."+(t?"ts":"js"),"index.config."+(t?"ts":"js")))(e,n);return[o,t[o]||{}]}))(e,t,o)){const t=J(s,o),i=xe(Z(s,`/${n}`,o)||"/",o,"vue"),c=q(i);r.push({...a,path:c,type:a?.type,isRoot:"/root"===i,component:e[t]})}return r},Q=e=>{if(!e.path)return e;if("wrap"!==e.type){const{path:t,children:n,...o}=e;if(Object.keys(o).length>0)return{path:t,children:[{path:"",...o},...(n||[]).map(Q)]}}return e.children?{...e,children:e.children.map(Q)}:e},Y=e=>(e=>e.map(Q))((e=>{const t=new Map,n=[],o=new Map,r=e=>{let t=o.get(e);return void 0===t&&(t="/"===e?[]:e.split("/").filter(Boolean),o.set(e,t)),t},s=e.slice().sort((e,t)=>e.path.length-t.path.length);for(const a of s){const e=a.path,o=r(e),s={...a,children:[]};if(t.set(e,s),o.length<=1){n.push(s);continue}const i="/"+o.slice(0,-1).join("/"),c=t.get(i);c?(s.path=o[o.length-1],c.children.push(s)):n.push(s)}return n})(e)),ee=e=>{const{isRoot:t,type:n,children:o,...r}=e;return o?.length?{...r,children:o.map(ee)}:r},te=e=>{const{children:t}=e;if(!t?.length){const{children:t,...n}=e;return n}const n=t.map(te);if("wrap"===e.type)return{...e,children:n};const{path:o,component:r,type:s,children:a,...i}=e;return r?{path:o,children:[{path:"",component:r,...i},...n]}:{path:o,...i,children:n}},ne=e=>ee(te(e)),oe=e=>Y(e).map(ne),re=e=>{if(e.some(e=>e.isRoot))return(e=>{let t,n,o;const r=[];for(const i of e)if(i.isRoot){if(t)throw new Error("There cannot be multiple root routes in a route");t=i}else"/"===i.path?n=i:"/:pathMatch(.*)*"===i.path?o=i:r.push(i);if($e(r,"path"))throw new Error("There cannot be duplicate paths in a route");const s=[n&&{...n,index:!0},...oe(r)].filter(e=>Boolean(e)),a=[];return t&&a.push(ee({...t,children:s})),o&&a.push(ee(o)),a})(e);if($e(e,"path"))throw new Error("There cannot be duplicate paths in a route");return oe(e)},se=(e,t)=>({import:`import ${e} from './${t}'`,component:`<start>${e}</end>`,lazyComponent:`<start>() => import('${t}')</end>`});var ae=(e,t,n,o,r,s,a)=>{const i=((e,t)=>e.replace("index.vue",t?Me:ve))(Pe(e,t),a),c=me(de(n,e)),u=he(C(c),s),p=`component(${c})`;o[`/${i}`]=p,r.set(p,{path:c,componentName:u})},ie=(e,t,n,o)=>{const r=Pe(e,t);n[`/${r}`]=g(r,fe(e),o)};function ce(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(ye);for(const u of f)if("component"===r){if(u.includes(".config."))continue;ae(u,n,o,p,s,a,c)}else ie(u,n,p,i);return p}var ue=async(e,t,n,o,r,s)=>{const a=new Map,i=new Set,c=new Map;we(o,((e,t,n,o)=>{let r=e;for(const[s,a]of t){const e=se(a.componentName,a.path);r=r.replace(s,o?e.lazyComponent:e.component)}for(const[s,a]of n)r=r.replace(s,a);return be(r)})(function(e,t,n,o){return`// Auto-generated by ono-auto-router${n?"\nimport type { RouteRecordRaw } from 'vue-router'":""}${o?"":`\n${t.join("\n")}${n?"":"\n"}`}${n?"\n\ntype PageConfig = Partial<\n Omit<RouteRecordRaw, 'path' | 'component' | 'children'> & {\n type?: 'single' | 'wrap'\n }\n>\n":""}${n?"\nexport const defineConfig = (config: PageConfig) => config\n":""}\nexport const routes${n?": RouteRecordRaw[]":""} = ${JSON.stringify(e,null,2)}\n`}(re(await G(ce("/**/*.vue",t,n,o,"component",a,i,c,s),ce("/**/*.config.{js,ts}",t,n,o,"config",a,i,c,s),e,s)),((e,t)=>{if(e)return[];const n=[];for(const o of t.values())n.push(se(o.componentName,o.path).import);return n})(r,a),s,r),a,c,r))},pe=(e,t,n,o)=>{const r=t.split(".")[0],s=(e=>`// Auto-generated by ono-auto-router${e?"\nexport { defineConfig } from './defineConfig'":""}\nexport { routes } from './autoRouter'\n`)(n),a=((e,t,n)=>`\nconst pathCache = new Map${t?"<string, { compPath: string; basePath: string }>":""}()\nconst basenameCache = new Map${t?"<string, string>":""}()\n\nconst normalizePagePath = ${t?"(key: string): string":"(key)"} => {\n if (key.includes('index.vue')) return key.replace('index.vue', 'index.${t?"ts":"js"}')\n if (key.includes('root.vue')) return key.replace('root.vue', 'root/index.${t?"ts":"js"}')\n if (key.includes('404.vue')) return key.replace('404.vue', '404/index.${t?"ts":"js"}')\n if (key.toLowerCase().includes('notfound.vue'))\n return key.toLowerCase().replace('notfound.vue', 'notfound/index.${t?"ts":"js"}')\n return key\n}\n\nconst getBasename = ${t?"(filePath: string, ext?: string): string":"(filePath, ext)"} => {\n const cacheKey = ext ? filePath + ':' + ext : filePath\n if (basenameCache.has(cacheKey)) {\n return basenameCache.get(cacheKey)${t?"!":""}\n }\n const parts = filePath.split('/')\n const lastPart = parts[parts.length - 1] || ''\n let result = lastPart\n if (ext && lastPart.endsWith(ext)) {\n result = lastPart.slice(0, -ext.length)\n }\n basenameCache.set(cacheKey, result)\n return result\n}\n\nconst getDirname = ${t?"(filePath: string): string":"(filePath)"} => {\n const parts = filePath.split('/')\n parts.pop()\n return parts.join('/')\n}\n\nconst getPathsFromConfig = ${t?"(configPath: string)":"(configPath)"} => {\n const cacheKey = configPath\n if (pathCache.has(cacheKey)) {\n return pathCache.get(cacheKey)${t?"!":""}\n }\n\n let compPath${t?": string":" = ''"}\n let basePath${t?": string":" = ''"}\n\n if (configPath.endsWith('.config.${t?"ts":"js"}')) {\n const fileName = getBasename(configPath, '.config.${t?"ts":"js"}')\n const dirPath = getDirname(configPath).replace('/${e}', '')\n\n if (fileName === 'index') {\n compPath = configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"ts":"js"}')\n basePath = dirPath || '/'\n } else {\n compPath = configPath.slice(0, -10) + '.vue'\n basePath = dirPath ? dirPath + '/' + fileName : '/' + fileName\n }\n } else {\n compPath = configPath.replace('index.config.${t?"ts":"js"}', 'index.${t?"ts":"js"}')\n basePath =\n configPath.replace('/${e}', '').replace('/index.config.${t?"ts":"js"}', '') ||\n '/'\n }\n\n const result = { compPath, basePath }\n pathCache.set(cacheKey, result)\n return result\n}\n\nconst formatPath = ${t?"(path: string): string":"(path)"} => {\n const lowerPath = path.toLowerCase()\n if (lowerPath === '/home') return '/'\n if (lowerPath === '/notfound' || path === '/404') return '/:pathMatch(.*)*'\n return path.replace('/index.${t?"ts":"js"}', '') || '/'\n}\n\nconst getConfigFileName = ${t?"(pagePath: string): string":"(pagePath)"} => {\n if (pagePath.endsWith('.vue')) {\n return pagePath.slice(0, -4) + '.config.${t?"ts":"js"}'\n }\n return pagePath.replace('index.${t?"ts":"js"}', 'index.config.${t?"ts":"js"}')\n}\n\nconst createBaseRoutes = ()${t?": MyRouteObject[]":""} => {\n const pagesComponent = Object.fromEntries(\n Object.entries({\n ...import.meta.glob('/${e}/**/index.vue'${n?"":", { eager: true, import: 'default' }"}),\n ...import.meta.glob('/${e}/*.vue'${n?"":", { eager: true, import: 'default' }"})\n }${t?" as PagesComponentType":""}).map(([key, value]) => [\n normalizePagePath(key),\n value\n ])\n )\n\n const pagesModule${t?": Record<string, PageConfig>":""} = import.meta.glob(\n '/${e}/**/*.config.${t?"ts":"js"}',\n { eager: true, import: 'default' }\n )\n\n const result${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const pagePath of Object.keys(pagesComponent)) {\n const configPath = getConfigFileName(pagePath)\n const content = pagesModule[configPath] || {}\n const { compPath, basePath } = getPathsFromConfig(configPath)\n const path = replaceBracketsWithColon(basePath || '/')\n const name = path.split('/').filter(Boolean).join('-') || 'index'\n\n result.push({\n path: formatPath(path),\n name,\n component: pagesComponent[compPath],\n isRoot: path === '/root',\n ...content${t?"!":""}\n })\n }\n\n return result\n}\n\nconst processRoutes = ${t?"(\n routes: MyRouteObject[],\n removeLeadingSlash = false\n): MyRouteObject[]":"(routes, removeLeadingSlash)"} =>\n buildRouteTree(routes, removeLeadingSlash)\n .map(removeEmptyChildren)\n .map(cleanIsRoot)\n\nconst handleRootRoute = ${t?"(\n routes: (MyRouteObject & { isRoot?: boolean })[]\n): MyRouteObject[]":"(routes)"} => {\n let rootRoute${t?": (MyRouteObject & { isRoot?: boolean }) | undefined":" = undefined"}\n let homeRoute${t?": MyRouteObject | undefined":" = undefined"}\n let notFoundRoute${t?": MyRouteObject | undefined":" = undefined"}\n const filteredRoutes${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n for (const route of routes) {\n if (route.isRoot) {\n if (rootRoute)\n throw new Error('There cannot be multiple root routes in a route')\n rootRoute = route\n } else if (route.path === '/') {\n homeRoute = route\n } else if (route.path === '/:pathMatch(.*)*') {\n notFoundRoute = route\n } else {\n filteredRoutes.push(route)\n }\n }\n\n if (hasDuplicateProperty(filteredRoutes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n const processedRoutes${t?": (MyRouteObject & { isRoot?: boolean })[]":""} = []\n\n if (rootRoute) {\n const children = [\n homeRoute && { ...homeRoute, path: '' },\n ...processRoutes(filteredRoutes, true)\n ].filter(Boolean)${t?" as MyRouteObject[]":""}\n processedRoutes.push({ ...rootRoute, path: '/', children })\n }\n\n if (notFoundRoute) processedRoutes.push(notFoundRoute)\n\n return processedRoutes.map(cleanIsRoot)\n}\n\nconst createRoutes = ()${t?": RouteRecordRaw[]":""} => {\n const routes = createBaseRoutes()\n\n if (routes.some((r${t?": MyRouteObject & { isRoot?: boolean }":""}) => r.isRoot))\n return handleRootRoute(routes)${t?" as RouteRecordRaw[]":""}\n\n if (hasDuplicateProperty(routes, 'path'))\n throw new Error('There cannot be duplicate paths in a route')\n\n return processRoutes(routes)${t?" as RouteRecordRaw[]":""}\n}\n`)(e,n,o),i=(e=>`\nconst buildRouteTree = ${e?"(\n routes: MyRouteObject[],\n removeLeadingSlash: boolean = false\n)":"(routes, removeLeadingSlash)"} => {\n const routeMap = new Map${e?"<string, MyRouteObject & { isRoot?: boolean }>":""}()\n const rootRoutes${e?": MyRouteObject[]":""} = []\n\n const sortedRoutes = [...routes].sort((a, b) => a.path.length - b.path.length)\n\n for (const route of sortedRoutes) {\n let path = route.path\n if (removeLeadingSlash && path.startsWith('/')) {\n path = path.slice(1)\n }\n routeMap.set(path, { ...route, path, children: [] })\n }\n\n for (const [path, route] of routeMap) {\n const slashIndex = path.lastIndexOf('/')\n\n if (slashIndex <= 0) {\n const { isRoot, ...rest } = route\n rootRoutes.push(rest)\n continue\n }\n\n const parentPath = path.slice(0, slashIndex)\n const parentRoute = routeMap.get(parentPath)\n\n if (parentRoute) {\n const relativePath = path.slice(slashIndex + 1)\n const childRoute = { ...route, path: relativePath }\n parentRoute.children${e?"!":""}.push(childRoute)\n } else {\n const { isRoot, ...rest } = route\n rootRoutes.push(rest)\n }\n }\n\n return rootRoutes\n}\n`)(n),u=(e=>`\nconst cleanIsRoot = ${e?"(\n route: MyRouteObject & { isRoot?: boolean }\n): MyRouteObject":"(route)"} => {\n const { isRoot, type, children, ...rest } = route\n const result${e?": MyRouteObject":""} = { ...rest }\n\n if (children?.length) {\n result.children = children.map(cleanIsRoot)\n }\n\n return result\n}\n`)(n),p=(e=>`\nconst removeEmptyChildren = ${e?"(route: MyRouteObject): MyRouteObject":"(route)"} => {\n if (!route.children?.length) {\n const { children, ...rest } = route\n return rest\n }\n\n const hasIndexRoute = route.children.some(\n child => child.path === '' || child.path === '/'\n )\n\n const routeType = route.type || 'single'\n\n if (routeType === 'wrap') {\n const { children, ...rest } = route\n return { ...rest, children: children.map(removeEmptyChildren) }\n }\n\n if (routeType === 'single' || (!hasIndexRoute && route.component)) {\n const { path, component, type, ...rest } = route\n return {\n path,\n children: [\n { path: '', component, ...rest }${e?" as MyRouteObject":""},\n ...route.children.map(removeEmptyChildren)\n ]\n }\n }\n\n if (hasIndexRoute) {\n const { path, ...rest } = route\n const updatedChildren = route.children.map(child =>\n child.path === '' || child.path === '/' ? { ...rest, ...child } : child\n )\n return { path, children: updatedChildren.map(removeEmptyChildren) }\n }\n\n return { ...route, children: route.children.map(removeEmptyChildren) }\n}\n`)(n),l=n?"// Auto-generated by ono-auto-router\nimport type { PageConfig } from './autoRouter'\nexport const defineConfig = (config: PageConfig) => config\n":"",h=((e,t,n,o,r,s,a)=>`// Auto-generated by ono-auto-router${e}${t}${n}${o}${r}${s}${a}\n`)(n?"\nimport type { RouteRecordRaw } from 'vue-router'\n\ntype PagesComponentType = Record<string, () => Promise<unknown>>\n\ninterface MyRouteObject extends Omit<RouteRecordRaw, 'children'> {\n type?: 'single' | 'wrap'\n children?: MyRouteObject[]\n}\n\nexport type PageConfig = Partial<\n Omit<MyRouteObject, 'component' | 'children' | 'path'>\n>\n":"",(e=>`\nconst hasDuplicateProperty = ${e?"<T>(items: T[], propName: keyof T)":"(items, propName)"} => {\n const seenValues = new Set()\n return items.some(item => {\n if (seenValues.has(item[propName])) {\n return true\n }\n seenValues.add(item[propName])\n return false\n })\n}\n\nconst replaceBracketsWithColon = ${e?"(str: string)":"(str)"} => {\n return str.replace(/\\[([^\\]]+)\\]/g, ':$1').replace('.tsx', '')\n}\n`)(n),p,u,i,a,"\nexport const routes = createRoutes()");n?(we(c.default.resolve(r,"./index.ts"),s),we(c.default.resolve(r,"./autoRouter.ts"),h),we(c.default.resolve(r,"./defineConfig.ts"),l)):we(t,h)},le=(e,t,n,o,r,s)=>{const a=c.default.resolve(n,t);if(!i.default.existsSync(a))throw new Error(`Pages directory not found: ${a}`);const u=y(e,n,o),p=P(n),l=u.split(".")[0];f(l+".js"),f(l+".ts"),f(l+".jsx"),f(l+".tsx"),d(l),"react"===e?s?U(t,u,r,p):H(t,a,n,u,r,p):s?pe(t,u,p,r):ue(t,a,n,u,r,p),console.log(`[ono-auto-router] Routes file generated: ${s?u.replace(".tsx","").replace(".ts",""):u}`)},he=(e,t)=>{if(!t.has(e))return t.add(e),e;let n=1;for(;t.has(`${e}_${n}`);)n++;return`${e}_${n}`};function fe(e){try{const n=i.default.readFileSync(e,"utf-8").match(/export\s+default\s+([\s\S]*?)(?=\n\w|$)/);if(!n)return console.warn("No export default found in:",e),null;const o=n[1].trim();try{if(o.startsWith("{"))return new Function(`return ${o}`)();if(o.includes("defineConfig(")){const e=o.match(/defineConfig([\s\S]*)$/);if(e)return new Function(`return ${e[1]}`)()}return null}catch(t){return console.error("Error parsing export default content:",t),null}}catch(n){return console.error("Error reading file:",n),null}}function de(e,t){let n=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 ge=/\\/g,me=e=>e.replace(ge,"/"),Pe=(e,t)=>me(c.default.relative(t,e)),Re=/export\s+default\s+[\w(\[\]\{\})]+/;function ye(e){try{if(!i.default.existsSync(e))return console.warn(`File not found: ${e}`),!1;const t=i.default.readFileSync(e,"utf-8");return Re.test(t)}catch(t){return console.error("Read error:",t),!1}}var $e=(e,t)=>{const n=new Set;return e.some(e=>!!n.has(e[t])||(n.add(e[t]),!1))};function je(e){return e.replace(/"<start>([\s\S]*?)<\/end>"/g,"$1")}function be(e){let t=e;for(;;){const e=je(t);if(e===t)break;t=e}return t}var xe=(e,t,n)=>e.replace(/\[([^\]]+)\]/g,":$1").replace("react"===n?t?".tsx":".jsx":".vue","");function Ce(e){i.default.existsSync(e)||i.default.mkdirSync(e,{recursive:!0})}function Oe(e,t){Ce(c.default.dirname(e)),i.default.writeFileSync(e,t,"utf-8")}async function we(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 Me="index.ts",ve="index.js";Object.defineProperty(exports,"INDEX_JS_SUFFIX",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"INDEX_TS_SUFFIX",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,"capitalize",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"convertFunctionToArrow",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"deleteDir",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"deleteFile",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"ensureDirSync",{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,"formatFunction",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"formatPagesDir",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"formatRoutesFile",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"generateComponentName",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"generateReactRoutes",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"generateReactRoutesHMR",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"generateRoutesTemplate",{enumerable:!0,get:function(){return le}}),Object.defineProperty(exports,"generateUniqueComponentName",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"generateVueRoutes",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(exports,"generateVueRoutesHMR",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,"getDefaultExportContent",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,"getRelativePath",{enumerable:!0,get:function(){return de}}),Object.defineProperty(exports,"getRelativeProjectPath",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,"hasDefaultExport",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,"hasDuplicateProperty",{enumerable:!0,get:function(){return $e}}),Object.defineProperty(exports,"normalizePathWithWindows",{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,"removeCustomTagFunctionFromJSXAll",{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,"replaceBracketsWithColon",{enumerable:!0,get:function(){return xe}}),Object.defineProperty(exports,"useTs",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"writeFile",{enumerable:!0,get:function(){return we}}),Object.defineProperty(exports,"writeFileSync",{enumerable:!0,get:function(){return Oe}});
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-Nna-MKEw.js");exports.generateReactRoutesHMR=e.generateReactRoutesHMR;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-wPeKAJfw.js");exports.generateReactRoutesHMR=e.generateReactRoutesHMR;
@@ -1 +1 @@
1
- import{v as o}from"./core-DIY62STE.js";export{o as generateReactRoutesHMR};
1
+ import{v as o}from"./core-DJR8BtMK.js";export{o as generateReactRoutesHMR};
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-Nna-MKEw.js");exports.generateReactRoutes=e.generateReactRoutes;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-wPeKAJfw.js");exports.generateReactRoutes=e.generateReactRoutes;
@@ -1 +1 @@
1
- import{y as o}from"./core-DIY62STE.js";export{o as generateReactRoutes};
1
+ import{y as o}from"./core-DJR8BtMK.js";export{o as generateReactRoutes};
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-Nna-MKEw.js");exports.generateVueRoutesHMR=e.generateVueRoutesHMR;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-wPeKAJfw.js");exports.generateVueRoutesHMR=e.generateVueRoutesHMR;
@@ -1 +1 @@
1
- import{g as o}from"./core-DIY62STE.js";export{o as generateVueRoutesHMR};
1
+ import{g as o}from"./core-DJR8BtMK.js";export{o as generateVueRoutesHMR};
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-Nna-MKEw.js");exports.generateVueRoutes=e.generateVueRoutes;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-wPeKAJfw.js");exports.generateVueRoutes=e.generateVueRoutes;
@@ -1 +1 @@
1
- import{_ as o}from"./core-DIY62STE.js";export{o as generateVueRoutes};
1
+ import{_ as o}from"./core-DJR8BtMK.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-Nna-MKEw.js");exports.default=function(o){const{framework:r="react",pagesDir:t="src/pages",routesFile:a,lazy:s=!0,hmr:u=!1}=o||{};let l,n;return{name:"ono-vite-plugin-auto-router",configResolved:o=>{l=o,n=l.root,e.generateRoutesTemplate(r,e.formatPagesDir(t),n,a,s,u)}}};
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core-wPeKAJfw.js");exports.default=function(o){const{framework:r="react",pagesDir:t="src/pages",routesFile:a,lazy:s=!0,hmr:u=!1}=o||{};let l,n;return{name:"ono-vite-plugin-auto-router",configResolved:o=>{l=o,n=l.root,e.generateRoutesTemplate(r,e.formatPagesDir(t),n,a,s,u)}}};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{h as e,w as o}from"./core-DIY62STE.js";function r(r){const{framework:t="react",pagesDir:a="src/pages",routesFile:s,lazy:n=!0,hmr:i=!1}=r||{};let u,c;return{name:"ono-vite-plugin-auto-router",configResolved:r=>{u=r,c=u.root,e(t,o(a),c,s,n,i)}}}export{r as default};
1
+ import{h as e,w as o}from"./core-DJR8BtMK.js";function r(r){const{framework:t="react",pagesDir:a="src/pages",routesFile:s,lazy:n=!0,hmr:i=!1}=r||{};let u,c;return{name:"ono-vite-plugin-auto-router",configResolved:r=>{u=r,c=u.root,e(t,o(a),c,s,n,i)}}}export{r as default};
package/dist/react.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core-Nna-MKEw.js");exports.default=function(t){const{pagesDir:o="src/pages",routesFile:r,lazy:a=!0,hmr:s=!1}=t||{};let n,u;return{name:"ono-vite-plugin-auto-router-react",configResolved:async t=>{n=t,u=n.root,e.generateRoutesTemplate("react",e.formatPagesDir(o),u,r,a,s)}}};
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core-wPeKAJfw.js");exports.default=function(t){const{pagesDir:o="src/pages",routesFile:r,lazy:a=!0,hmr:s=!1}=t||{};let n,u;return{name:"ono-vite-plugin-auto-router-react",configResolved:async t=>{n=t,u=n.root,e.generateRoutesTemplate("react",e.formatPagesDir(o),u,r,a,s)}}};
package/dist/react.js CHANGED
@@ -1 +1 @@
1
- import{h as e,w as o}from"./core-DIY62STE.js";function r(r){const{pagesDir:t="src/pages",routesFile:a,lazy:s=!0,hmr:n=!1}=r||{};let c,i;return{name:"ono-vite-plugin-auto-router-react",configResolved:async r=>{c=r,i=c.root,e("react",o(t),i,a,s,n)}}}export{r as default};
1
+ import{h as e,w as o}from"./core-DJR8BtMK.js";function r(r){const{pagesDir:t="src/pages",routesFile:a,lazy:s=!0,hmr:n=!1}=r||{};let c,i;return{name:"ono-vite-plugin-auto-router-react",configResolved:async r=>{c=r,i=c.root,e("react",o(t),i,a,s,n)}}}export{r as default};
package/dist/utils.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-Nna-MKEw.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-wPeKAJfw.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-DIY62STE.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-DJR8BtMK.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-Nna-MKEw.js");exports.default=function(o){const{pagesDir:t="src/pages",routesFile:r,lazy:s=!0,hmr:u=!1}=o||{};let a,n;return{name:"ono-vite-plugin-auto-router-vue",configResolved:async o=>{a=o,n=a.root,e.generateRoutesTemplate("vue",e.formatPagesDir(t),n,r,s,u)}}};
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core-wPeKAJfw.js");exports.default=function(o){const{pagesDir:t="src/pages",routesFile:r,lazy:s=!0,hmr:u=!1}=o||{};let a,n;return{name:"ono-vite-plugin-auto-router-vue",configResolved:async o=>{a=o,n=a.root,e.generateRoutesTemplate("vue",e.formatPagesDir(t),n,r,s,u)}}};
package/dist/vue.js CHANGED
@@ -1 +1 @@
1
- import{h as e,w as o}from"./core-DIY62STE.js";function r(r){const{pagesDir:t="src/pages",routesFile:s,lazy:a=!0,hmr:n=!1}=r||{};let u,i;return{name:"ono-vite-plugin-auto-router-vue",configResolved:async r=>{u=r,i=u.root,e("vue",o(t),i,s,a,n)}}}export{r as default};
1
+ import{h as e,w as o}from"./core-DJR8BtMK.js";function r(r){const{pagesDir:t="src/pages",routesFile:s,lazy:a=!0,hmr:n=!1}=r||{};let u,i;return{name:"ono-vite-plugin-auto-router-vue",configResolved:async r=>{u=r,i=u.root,e("vue",o(t),i,s,a,n)}}}export{r as default};
package/package.json CHANGED
@@ -1,7 +1,17 @@
1
1
  {
2
2
  "name": "@onoxm/vite-plugin-auto-router",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "a vite plugin for automatically generating react or vue route files",
5
+ "keywords": [
6
+ "auto-router",
7
+ "plugin",
8
+ "vite"
9
+ ],
10
+ "license": "MIT",
11
+ "author": "ono",
12
+ "files": [
13
+ "dist"
14
+ ],
5
15
  "type": "module",
6
16
  "main": "dist/index.cjs",
7
17
  "module": "dist/index.js",
@@ -23,12 +33,9 @@
23
33
  "types": "./dist/vue.d.ts"
24
34
  }
25
35
  },
26
- "keywords": [],
27
- "author": "ono",
28
- "license": "MIT",
29
- "files": [
30
- "dist"
31
- ],
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
32
39
  "dependencies": {
33
40
  "fast-glob": "^3.3.3"
34
41
  },
@@ -45,9 +52,6 @@
45
52
  "optional": true
46
53
  }
47
54
  },
48
- "publishConfig": {
49
- "access": "public"
50
- },
51
55
  "scripts": {
52
56
  "build": "rimraf dist && vite build"
53
57
  }