Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
(fix): Fix nested routes in the cli projects (#2189)
Jaya Krishna Namburu9fc3026bfa35
diff --git a/apps/cli/src/prebuild.ts b/apps/cli/src/prebuild.tsindex a53d090aff..7329114ba9 100644--- a/apps/cli/src/prebuild.ts+++ b/apps/cli/src/prebuild.ts@@ -1,5 +1,5 @@-import { join, relative, dirname } from "node:path";-import { createWriteStream, writeFileSync } from "node:fs";+import { join } from "node:path";+import { createWriteStream } from "node:fs";import { rm, mkdir, access, mkdtemp, rename } from "node:fs/promises";import { tmpdir } from "node:os";import {@@ -220,7 +220,6 @@ export const prebuild = async () => {spinner.text = "Generating routes and pages";for (const [pathName, pageComponents] of Object.entries(componentsByPage)) {- let relativePath = "../__generated__";const statements = Array.from(pageComponents).join(", ");const pageData = siteDataByPage[pathName];@@ -249,71 +248,23 @@ export const prebuild = async () => {${utilsExport}`;- /* Changing the pathName to index for the index page, so that remix will use the index.tsx file as index:true in the manifest file.+ const fileName =+ pathName === "main" || pathName === "index"+ ? "_index.tsx"+ : `${pathName.split("/").join(".")}._index.tsx`;- It is generated by @remix-run/cloudflare somewhere here (https://github.com/remix-run/remix/blob/8851599c47f5d372fb537026a9ee0931a8753262/packages/remix-react/routes.tsx#L50). If there was no index.ts file, the manifest file containing all the routing was incorrect and nothing responded to root (/) requests. That is why the main file is renamed to index so Remix will use it as /.+ let routeFile = getRouteTemplate();- */- pathName === "main" ? "index" : pathName;-- const fileLocationGeneratedDir = join(generatedDir, pathName);- const fileLocationRoutesDir = join(routesDir, pathName);-- if (pathName !== "index") {- // If the pathName is not index, we need to create the directory structure for the generated files, set the relative path to the generated directory- if (!pathName.includes("/")) {- await ensureFolderExists(fileLocationRoutesDir);- await ensureFolderExists(fileLocationGeneratedDir);-- relativePath = relative(fileLocationRoutesDir, generatedDir);- } else {- const dirnameRoutesDir = dirname(fileLocationRoutesDir);- relativePath = relative(dirnameRoutesDir, generatedDir);- }- }- if (!pathName.includes("/") && pathName !== "index") {- // As there could be pages with /blog and with /blog/post1, we need to create the index.tsx file for the /blog directory, and not blog.tsx in the parent directory- writeFileSync(- join(fileLocationGeneratedDir, `index.ts`),- pageExports,- "utf8"- );-- let routeIndexFile = getRouteTemplate();-- routeIndexFile = routeIndexFile.replace(- "../__generated__/index",- `${relativePath}/${pathName}/index`- );- routeIndexFile = routeIndexFile.replace(- "../__generated__/index.css",- `${relativePath}/index.css`- );-- writeFileSync(- join(fileLocationRoutesDir, `index.tsx`),- routeIndexFile,- "utf8"- );- } else {- writeFileSync(join(generatedDir, `${pathName}.ts`), pageExports, "utf8");-- let routeFile = getRouteTemplate();-- routeFile = routeFile.replace(- "../__generated__/index",- `${relativePath}/${pathName}`- );- routeFile = routeFile.replace(- "../__generated__/index.css",- `${relativePath}/index.css`- );+ routeFile = routeFile.replace(+ "../__generated__/index",+ join("../__generated__", fileName)+ );- writeFileSync(join(routesDir, `_${pathName}.tsx`), routeFile, "utf8");- }+ await ensureFileInPath(join(routesDir, fileName), routeFile);+ await ensureFileInPath(join(generatedDir, fileName), pageExports);}- spinner.text = "Generating css files";+ spinner.text = "Generating css file";const cssText = generateCssText({assets: siteData.assets,@@ -326,7 +277,6 @@ export const prebuild = async () => {assetBaseUrl: ASSETS_BASE,});-await ensureFileInPath(join(generatedDir, "index.css"), cssText);spinner.text = "Downloading fonts and images";