MCPcopy
hub / github.com/blitz-js/blitz / createPagesMapping

Function createPagesMapping

packages/blitz/src/cli/utils/routes-manifest.ts:246–282  ·  view source on GitHub ↗
(pagePaths: string[], config: any)

Source from the content-addressed store, hash-verified

244 )
245}
246export function createPagesMapping(pagePaths: string[], config: any) {
247 const {pageExtensions, blitz} = config
248 const resolverType = blitz?.resolverPath || "queries|mutations"
249
250 const previousPages: PagesMapping = {}
251 const pages = pagePaths.reduce<PagesMapping>((result, pagePath) => {
252 let page = `${convertPageFilePathToRoutePath(pagePath, pageExtensions).replace(
253 /\\/g,
254 "/",
255 )}`.replace(/\/index$/, "")
256 const isResolver = pagePath.includes("/queries/") || pagePath.includes("/mutations/")
257 if (isResolver) {
258 if (typeof resolverType === "function") {
259 page = `/api/rpc${resolverType(pagePath)}`
260 } else if (resolverType === "root") {
261 page = `/api/rpc${stripExtension(pagePath, pageExtensions)}`
262 }
263 }
264
265 let pageKey = page === "" ? "/" : page
266 if (pageKey in result) {
267 console.warn(
268 `Duplicate page detected. ${previousPages[pageKey]} and ${pagePath} both resolve to ${pageKey}.`,
269 )
270 } else {
271 previousPages[pageKey] = pagePath
272 }
273 result[pageKey] = join(PAGES_DIR_ALIAS, pagePath).replace(/\\/g, "/")
274 return result
275 }, {})
276
277 pages["/_app"] = pages["/_app"] || "next/dist/pages/_app"
278 pages["/_error"] = pages["/_error"] || "next/dist/pages/_error"
279 pages["/_document"] = pages["/_document"] || "next/dist/pages/_document"
280
281 return pages
282}
283export function collectPages(directory: string, pageExtensions: string[]): Promise<string[]> {
284 return recursiveFindPages(directory, buildPageExtensionRegex(pageExtensions))
285}

Callers 1

collectAllRoutesFunction · 0.85

Calls 3

stripExtensionFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected