Problem router vite

This commit is contained in:
2026-03-17 14:44:58 +01:00
parent 2abeaedfb2
commit abf549c05f
2 changed files with 23 additions and 31 deletions

View File

@@ -1 +1 @@
import fs from"fs";import path from"path";export default function sigproRouter(){const e="virtual:sigpro-routes",t="\0"+e;function r(e){let t=[];if(!fs.existsSync(e))return t;return fs.readdirSync(e).forEach((o=>{const s=path.resolve(e,o),n=fs.statSync(s);n&&n.isDirectory()?t=t.concat(r(s)):(o.endsWith(".js")||o.endsWith(".jsx"))&&t.push(s)})),t}return{name:"sigpro-router",resolveId(r){if(r===e)return t},load(e){if(e===t){const e=path.resolve(process.cwd(),"src/pages");let t=r(e);t=t.sort(((t,r)=>{const o=path.relative(e,t),s=path.relative(e,r),n=o.split(path.sep).length,c=s.split(path.sep).length;if(n!==c)return c-n;const a=o.includes("[");return a!==s.includes("[")?a?1:-1:o.localeCompare(s)}));let o="",s="export const routes = [\n";return console.log("\n🚀 [SigPro Router] Routes generated:"),t.forEach(((t,r)=>{const n=path.relative(e,t).replace(/\\/g,"/"),c=`Page_${r}`;let a=function(e){let t=e.replace(/\.jsx?$/,"");return t=t.replace(/\[([^\]]+)\]/g,":$1"),t.endsWith("/index")&&(t=t.slice(0,-6)),"/"+t.toLowerCase()}(n);const i=a.includes(":");o+=`import ${c} from '${t}';\n`,console.log(` ${i?"🔗":"📄"} ${a.padEnd(30)} -> ${n}`),s+=` { path: '${a}', component: ${c} },\n`})),s+="];",`${o}\n${s}`}}}}
import fs from"fs";import path from"path";export default function sigproRouter(){const e="virtual:sigpro-routes",t="\0"+e;function r(e){let t=[];if(!fs.existsSync(e))return t;return fs.readdirSync(e).forEach((n=>{const o=path.resolve(e,n),s=fs.statSync(o);s&&s.isDirectory()?t=t.concat(r(o)):(n.endsWith(".js")||n.endsWith(".jsx"))&&t.push(o)})),t}return{name:"sigpro-router",resolveId(r){if(r===e)return t},load(e){if(e===t){const e=path.resolve(process.cwd(),"src/pages");let t=r(e);t=t.sort(((t,r)=>{const n=path.relative(e,t).replace(/\\/g,"/"),o=path.relative(e,r).replace(/\\/g,"/"),s=n.includes("[")||n.includes(":");return s!==(o.includes("[")||o.includes(":"))?s?1:-1:o.length-n.length}));let n="",o="export const routes = [\n";return console.log("\n🚀 [SigPro Router] Routes generated:"),t.forEach(((t,r)=>{const s=t.replace(/\\/g,"/"),c=path.relative(e,t).replace(/\\/g,"/"),l=`Page_${r}`;let a=function(e){let t=e.replace(/\\/g,"/").replace(/\.jsx?$/,"");return"index"===t?"/":(t.endsWith("/index")&&(t=t.slice(0,-6)),t=t.replace(/\[([^\]]+)\]/g,":$1"),("/"+t.toLowerCase()).replace(/\/+/g,"/").replace(/\/$/,"")||"/")}(c);const i=a.includes(":");n+=`import ${l} from '${s}';\n`,console.log(` ${i?"🔗":"📄"} ${a.padEnd(30)} -> ${c}`),o+=` { path: '${a}', component: ${l} },\n`})),o+="];",`${n}\n${o}`}}}}