Raw
1 import { normalizePath, VALID_FILE_EXTENSIONS } from "../utils"
2
3 export function getRoute(file: string): string {
4 const importPath = normalizePath(file)
5 return importPath
6 .replace(/.*\/admin\/(routes)/, "")
7 .replace("[[*]]", "*?") // optional splat
8 .replace("[*]", "*") // splat
9 .replace(/\(([^\[\]\)]+)\)/g, "$1?") // optional static, (foo)
10 .replace(/\[\[([^\]]+)\]\]/g, ":$1?") // optional dynamic, [[foo]]
11 .replace(/\[([^\]]+)\]/g, ":$1") // dynamic, [foo]
12 .replace(
13 new RegExp(
14 `/page\\.(${VALID_FILE_EXTENSIONS.map((ext) => ext.slice(1)).join(
15 "|"
16 )})$`
17 ),
18 ""
19 )
20 }