Repository navigation
Chore/UI #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore/UI #36
Changes from all commits
343f207
049c364
8b7bba7
4e3b43e
c399989
80a1baa
c1667ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { describe, test, expect } from "bun:test"; | ||
| import { generateDynamicRailpackJson } from "../railpack-config-utils"; | ||
| import { mkdtempSync, mkdirSync, writeFileSync, rmSync, readFileSync, existsSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { tmpdir } from "node:os"; | ||
|
|
||
| const setupWorkspace = () => { | ||
| const dir = mkdtempSync(join(tmpdir(), "dequel-railpack-config-")); | ||
| mkdirSync(join(dir, "client"), { recursive: true }); | ||
| return { dir, cleanup: () => rmSync(dir, { recursive: true, force: true }) }; | ||
| }; | ||
|
|
||
| describe("generateDynamicRailpackJson static subdirectory detection", () => { | ||
| test("configures dequel-serve.js when index.html exists without package.json", async () => { | ||
| const { dir, cleanup } = setupWorkspace(); | ||
| try { | ||
| writeFileSync(join(dir, "client", "index.html"), "<html></html>"); | ||
| const logs: string[] = []; | ||
| await generateDynamicRailpackJson( | ||
| dir, | ||
| "client", | ||
| "static", | ||
| null, | ||
| null, | ||
| async (line) => logs.push(line), | ||
| ); | ||
| const serveScript = join(dir, "dequel-serve.js"); | ||
| const railpackJson = join(dir, "railpack.json"); | ||
| expect(existsSync(serveScript)).toBe(true); | ||
| expect(existsSync(railpackJson)).toBe(true); | ||
| const parsedConfig = JSON.parse(readFileSync(railpackJson, "utf8")); | ||
| expect(parsedConfig.deploy?.startCommand).toBe("bun dequel-serve.js"); | ||
| } finally { | ||
| cleanup(); | ||
| } | ||
| }); | ||
|
|
||
| test("does not overwrite a user-provided Staticfile", async () => { | ||
| const { dir, cleanup } = setupWorkspace(); | ||
| try { | ||
| writeFileSync(join(dir, "client", "index.html"), "<html></html>"); | ||
| writeFileSync(join(dir, "Staticfile"), "root: public\n"); | ||
| await generateDynamicRailpackJson( | ||
| dir, | ||
| "client", | ||
| "railpack", | ||
| null, | ||
| null, | ||
| async () => {}, | ||
| ); | ||
| expect(readFileSync(join(dir, "Staticfile"), "utf8")).toBe("root: public\n"); | ||
| } finally { | ||
| cleanup(); | ||
| } | ||
| }); | ||
|
|
||
| test("does not emit Staticfile when package.json exists in source dir", async () => { | ||
| const { dir, cleanup } = setupWorkspace(); | ||
| try { | ||
| writeFileSync(join(dir, "client", "index.html"), "<html></html>"); | ||
| writeFileSync(join(dir, "client", "package.json"), JSON.stringify({ name: "app", scripts: { start: "node dist/index.js" } })); | ||
| const logs: string[] = []; | ||
| await generateDynamicRailpackJson( | ||
| dir, | ||
| "client", | ||
| "railpack", | ||
| null, | ||
| null, | ||
| async (line) => logs.push(line), | ||
| ); | ||
| expect(existsSync(join(dir, "Staticfile"))).toBe(false); | ||
| expect(logs.some((l) => l.includes("Detected static site"))).toBe(false); | ||
| } finally { | ||
| cleanup(); | ||
| } | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,39 +140,21 @@ export const generateDynamicRailpackJson = async ( | |
|
|
||
| let configured = false; | ||
|
|
||
| // 1. Check if user provided manual build / start / install command overrides | ||
| if (buildCommandOverride || startCommandOverride || installCommandOverride) { | ||
| await onLog("Applying custom build/start/install settings"); | ||
| if (installCommandOverride) { | ||
| config.steps.install = { | ||
| commands: [ | ||
| cleanSourceDir | ||
| ? `cd ${cleanSourceDir} && ${installCommandOverride}` | ||
| : installCommandOverride, | ||
| ], | ||
| }; | ||
| } | ||
| if (buildCommandOverride) { | ||
| config.steps.build = { | ||
| commands: [ | ||
| cleanSourceDir | ||
| ? `cd ${cleanSourceDir} && ${buildCommandOverride}` | ||
| : buildCommandOverride, | ||
| ], | ||
| }; | ||
| if (cleanSourceDir && !(await Bun.file(join(workspace, "package.json")).exists())) { | ||
| const sourcePkgExists = await Bun.file(join(workspace, cleanSourceDir, "package.json")).exists(); | ||
| if (sourcePkgExists) { | ||
| await Bun.write(join(workspace, "package.json"), JSON.stringify({ | ||
| name: "dequel-monorepo-root", | ||
| private: true, | ||
| workspaces: [cleanSourceDir] | ||
| }, null, 2)); | ||
| } | ||
| if (startCommandOverride) { | ||
| config.deploy.startCommand = cleanSourceDir | ||
| ? `cd ${cleanSourceDir} && ${startCommandOverride}` | ||
| : startCommandOverride; | ||
| } | ||
| configured = true; | ||
| } | ||
|
|
||
| const hasPackageJson = await Bun.file( | ||
| join(buildDir, "package.json"), | ||
| ).exists(); | ||
| if (hasPackageJson && !configured) { | ||
| if (hasPackageJson) { | ||
| try { | ||
| const packageJson = await Bun.file( | ||
| join(buildDir, "package.json"), | ||
|
|
@@ -238,7 +220,7 @@ export const generateDynamicRailpackJson = async ( | |
| if (scripts.build) { | ||
| const buildCmds = [ | ||
| cleanSourceDir | ||
| ? `cd ${cleanSourceDir} && ${pm} run build` | ||
| ? `[ -d "${cleanSourceDir}" ] && cd -- "${cleanSourceDir}" && ${pm} run build` | ||
| : `${pm} run build`, | ||
| ]; | ||
| if (hasNext) { | ||
|
|
@@ -260,81 +242,7 @@ export const generateDynamicRailpackJson = async ( | |
| } | ||
| } | ||
|
|
||
| const hasServerScript = !!scripts.server; | ||
| const isStatic = projectType === "static" || (!scripts.start && !hasServerScript && (scripts.build || hasPackageJson)); | ||
|
|
||
| if (isStatic) { | ||
| const serveScript = ` | ||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
| const PORT = Number(process.env.PORT || 3000); | ||
| const cleanSourceDir = "${cleanSourceDir}"; | ||
| const cleanOutputDir = "${cleanOutputDir}"; | ||
| let staticDir = "."; | ||
| const candidates = [ | ||
| ...(cleanOutputDir ? [path.join(cleanSourceDir, cleanOutputDir), cleanOutputDir] : []), | ||
| path.join(cleanSourceDir, "dist"), | ||
| path.join(cleanSourceDir, "build"), | ||
| path.join(cleanSourceDir, "out"), | ||
| path.join(cleanSourceDir, ".next/server/app"), | ||
| path.join(cleanSourceDir, ".next/server/pages"), | ||
| path.join(cleanSourceDir, "public"), | ||
| "dist", | ||
| "build", | ||
| "out", | ||
| ".next/server/app", | ||
| ".next/server/pages", | ||
| "public", | ||
| "." | ||
| ]; | ||
| for (const dir of candidates) { | ||
| const fullPath = path.join(process.cwd(), dir); | ||
| if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) { | ||
| if (fs.existsSync(path.join(fullPath, "index.html"))) { | ||
| staticDir = dir; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| console.log("Serving static directory:", staticDir, "on port", PORT); | ||
| Bun.serve({ | ||
| port: PORT, | ||
| async fetch(req) { | ||
| const url = new URL(req.url); | ||
| let decodedPathname = "/"; | ||
| try { | ||
| decodedPathname = decodeURIComponent(url.pathname); | ||
| } catch { | ||
| decodedPathname = url.pathname; | ||
| } | ||
| let filePath = path.join(staticDir, decodedPathname); | ||
| if (decodedPathname.endsWith("/")) { | ||
| filePath = path.join(filePath, "index.html"); | ||
| } | ||
| let file = Bun.file(filePath); | ||
| if (await file.exists()) { | ||
| return new Response(file, { | ||
| headers: { | ||
| "content-type": file.type || "application/octet-stream" | ||
| } | ||
| }); | ||
| } | ||
| const fallbackPath = path.join(staticDir, "index.html"); | ||
| const fallbackFile = Bun.file(fallbackPath); | ||
| if (await fallbackFile.exists()) { | ||
| return new Response(fallbackFile, { | ||
| headers: { | ||
| "content-type": fallbackFile.type || "text/html" | ||
| } | ||
| }); | ||
| } | ||
| return new Response("Not Found", { status: 404 }); | ||
| } | ||
| }); | ||
| `; | ||
| await Bun.write(join(workspace, "dequel-serve.js"), serveScript); | ||
| config.deploy.startCommand = "bun dequel-serve.js"; | ||
| } else if (scripts.start) { | ||
| if (scripts.start) { | ||
| config.deploy.startCommand = | ||
| cleanSourceDir | ||
| ? `cd ${cleanSourceDir} && ${pm} run start` | ||
|
|
@@ -359,6 +267,8 @@ Bun.serve({ | |
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| const hasCargoToml = await Bun.file( | ||
| join(buildDir, "Cargo.toml"), | ||
| ).exists(); | ||
|
|
@@ -606,18 +516,23 @@ Bun.serve({ | |
| configured = true; | ||
| } | ||
|
|
||
| if (!configured && projectType === "static") { | ||
| if (projectType === "static" || (!configured && ((await Bun.file(join(buildDir, "index.html")).exists()) || (await Bun.file(join(workspace, "index.html")).exists())))) { | ||
| const serveScript = ` | ||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
| const PORT = Number(process.env.PORT || 3000); | ||
| const cleanSourceDir = "${cleanSourceDir}"; | ||
| const cleanOutputDir = "${cleanOutputDir}"; | ||
| let staticDir = "."; | ||
| const candidates = [ | ||
| ...(cleanOutputDir ? [path.join(cleanSourceDir, cleanOutputDir), cleanOutputDir] : []), | ||
| path.join(cleanSourceDir, "dist"), | ||
| path.join(cleanSourceDir, "build"), | ||
| path.join(cleanSourceDir, "out"), | ||
| path.join(cleanSourceDir, ".next/server/app"), | ||
| path.join(cleanSourceDir, ".next/server/pages"), | ||
| path.join(cleanSourceDir, "public"), | ||
| cleanSourceDir || ".", | ||
| "dist", | ||
| "build", | ||
| "out", | ||
|
|
@@ -670,6 +585,17 @@ Bun.serve({ | |
| }); | ||
| `; | ||
| await Bun.write(join(workspace, "dequel-serve.js"), serveScript); | ||
| const rootPkgPath = join(workspace, "package.json"); | ||
| if (!(await Bun.file(rootPkgPath).exists())) { | ||
| await Bun.write(rootPkgPath, JSON.stringify({ | ||
| name: "dequel-static-app", | ||
| private: true, | ||
| scripts: { | ||
| start: "bun dequel-serve.js" | ||
| } | ||
| }, null, 2)); | ||
| } | ||
| config.steps.build = config.steps.build || { commands: [] }; | ||
| config.deploy.startCommand = "bun dequel-serve.js"; | ||
| configured = true; | ||
| } | ||
|
|
@@ -680,6 +606,30 @@ Bun.serve({ | |
| ); | ||
| } | ||
|
|
||
| if (buildCommandOverride || startCommandOverride || installCommandOverride) { | ||
| await onLog("Applying custom build/start/install settings"); | ||
| if (installCommandOverride) { | ||
| const hasCustomInstall = installCommandOverride !== "npm install" && installCommandOverride !== "npm ci" && installCommandOverride !== "pnpm install" && installCommandOverride !== "yarn install" && installCommandOverride !== "bun install"; | ||
| if (hasCustomInstall) { | ||
| config.steps.install = config.steps.install || {}; | ||
| config.steps.install.commands = [installCommandOverride]; | ||
| } | ||
| } | ||
| if (buildCommandOverride) { | ||
| config.steps.build = config.steps.build || {}; | ||
| config.steps.build.commands = [ | ||
| cleanSourceDir | ||
| ? `cd ${cleanSourceDir} && ${buildCommandOverride}` | ||
| : buildCommandOverride, | ||
| ]; | ||
| } | ||
| if (startCommandOverride) { | ||
| config.deploy.startCommand = cleanSourceDir | ||
| ? `cd ${cleanSourceDir} && ${startCommandOverride}` | ||
| : startCommandOverride; | ||
| } | ||
| } | ||
|
Comment on lines
+609
to
+631
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift Split the TypeScript files that exceed the repository size limit.
As per coding guidelines, “No file should be above 500 lines of code; if it is, refactor and split into smaller files with proper feature grouping in a folder rather than scattered across the codebase”. 📍 Affects 2 files
🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| await Bun.write( | ||
| configPath, | ||
| JSON.stringify(config, null, 2), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.