From d12b850a7552a16b409c44b795b546352086c385 Mon Sep 17 00:00:00 2001 From: Rizky Date: Fri, 20 Dec 2024 12:56:27 +0700 Subject: [PATCH] checkpoint --- internal/content/content.ts | 5 +++++ internal/content/deploy/load.ts | 2 +- internal/server/server.ts | 24 +++++++++++++++++++++--- internal/supervisor.ts | 2 ++ internal/utils/global.ts | 5 ++++- 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 internal/content/content.ts diff --git a/internal/content/content.ts b/internal/content/content.ts new file mode 100644 index 0000000..a7ac73d --- /dev/null +++ b/internal/content/content.ts @@ -0,0 +1,5 @@ +import { g } from "utils/global"; + +export const PrasiContent = () => { + return g.mode === "site" ? g.content : null; +}; diff --git a/internal/content/deploy/load.ts b/internal/content/deploy/load.ts index 95be840..9d82d66 100644 --- a/internal/content/deploy/load.ts +++ b/internal/content/deploy/load.ts @@ -7,7 +7,7 @@ import { fs } from "utils/fs"; import { g } from "utils/global"; export const loadCurrentDeploy = async (ts: number) => { - if (fs.exists(`site:deploy/current/${ts}.gz`)) { + if (fs.exists(`site:deploy/current/${ts}.gz`) && g.mode === "site") { await removeAsync(fs.path(`site:deploy/current/files`)); const content = decode( diff --git a/internal/server/server.ts b/internal/server/server.ts index 9a88b17..4b54844 100644 --- a/internal/server/server.ts +++ b/internal/server/server.ts @@ -1,10 +1,28 @@ import { config } from "utils/config"; import { g, startup } from "utils/global"; +import { prasi_content_ipc } from "../content/content-ipc"; +import { prasi_content_deploy } from "../content/content-deploy"; +import { loadCurrentDeploy } from "../content/deploy/load"; startup("site", async () => { await config.init("site:site.json"); - const ts = config.current?.deploy.current; - if (ts) { - // g.server = process.argv.includes("--ipc") ? "ipc" : "gz"; + if (g.mode === "site") { + g.content = g.ipc ? prasi_content_ipc : prasi_content_deploy; + + if (g.ipc) { + } else { + const ts = config.current?.deploy.current; + if (ts) { + await loadCurrentDeploy(ts); + } + } + + g.server = Bun.serve({ + fetch(request, server) {}, + websocket: { message(ws, message) {} }, + }); + + if (g.ipc) { + } } }); diff --git a/internal/supervisor.ts b/internal/supervisor.ts index 970fc47..1314d42 100644 --- a/internal/supervisor.ts +++ b/internal/supervisor.ts @@ -30,6 +30,8 @@ startup("supervisor", async () => { if (is_ipc) { g.mode = "site"; if (g.mode === "site") g.ipc = true; + } else { + } startServer({ diff --git a/internal/utils/global.ts b/internal/utils/global.ts index 1a2673e..556bd42 100644 --- a/internal/utils/global.ts +++ b/internal/utils/global.ts @@ -3,6 +3,8 @@ import { join, resolve } from "path"; import type { SiteConfig } from "./config"; import { fs } from "./fs"; import type { PrasiSpawn, spawn } from "./spawn"; +import type { prasi_content_ipc } from "../content/content-ipc"; +import type { prasi_content_deploy } from "../content/content-deploy"; if (!(globalThis as any).prasi) { (globalThis as any).prasi = {}; @@ -15,7 +17,8 @@ export const g = (globalThis as any).prasi as unknown as { mode: "site"; server: Server; ipc: boolean; - site: { + content: typeof prasi_content_ipc & typeof prasi_content_deploy; + site?: { db?: SiteConfig["db"]; layouts: { id: string;