checkpoint

This commit is contained in:
Rizky 2024-12-20 14:31:50 +07:00
parent d12b850a75
commit fa9cbf5f12
4 changed files with 36 additions and 29 deletions

View File

@ -0,0 +1,3 @@
export const ipcSend = (
msg: { type: "init" } | { type: "ready"; port: number }
) => {};

View File

@ -3,6 +3,7 @@ import { g, startup } from "utils/global";
import { prasi_content_ipc } from "../content/content-ipc"; import { prasi_content_ipc } from "../content/content-ipc";
import { prasi_content_deploy } from "../content/content-deploy"; import { prasi_content_deploy } from "../content/content-deploy";
import { loadCurrentDeploy } from "../content/deploy/load"; import { loadCurrentDeploy } from "../content/deploy/load";
import { ipcSend } from "../content/ipc/send";
startup("site", async () => { startup("site", async () => {
await config.init("site:site.json"); await config.init("site:site.json");
@ -10,19 +11,27 @@ startup("site", async () => {
g.content = g.ipc ? prasi_content_ipc : prasi_content_deploy; g.content = g.ipc ? prasi_content_ipc : prasi_content_deploy;
if (g.ipc) { if (g.ipc) {
ipcSend({ type: "init" });
process.on("message", (msg: { type: "start" }) => {
if (g.mode === "site") {
if (msg.type === "start") {
g.server = Bun.serve({
fetch(request, server) {},
websocket: { message(ws, message) {} },
});
}
}
});
} else { } else {
const ts = config.current?.deploy.current; const ts = config.current?.deploy.current;
if (ts) { if (ts) {
await loadCurrentDeploy(ts); await loadCurrentDeploy(ts);
} }
}
g.server = Bun.serve({ g.server = Bun.serve({
fetch(request, server) {}, fetch(request, server) {},
websocket: { message(ws, message) {} }, websocket: { message(ws, message) {} },
}); });
if (g.ipc) {
} }
} }
}); });

View File

@ -2,7 +2,7 @@ import { fs } from "utils/fs";
import { g } from "utils/global"; import { g } from "utils/global";
import { spawn } from "utils/spawn"; import { spawn } from "utils/spawn";
export const startServer = (arg: { site_id: string; mode: "dev" | "prod" }) => { export const startServer = (arg: { mode: "dev" | "prod" }) => {
if (g.mode === "supervisor") { if (g.mode === "supervisor") {
g.supervisor = { g.supervisor = {
process: spawn({ process: spawn({

View File

@ -14,29 +14,24 @@ startup("supervisor", async () => {
console.log(`${c.green}Prasi Server:${c.esc} ${fs.path("site:")}`); console.log(`${c.green}Prasi Server:${c.esc} ${fs.path("site:")}`);
await config.init("site:site.json"); await config.init("site:site.json");
if (!is_ipc) {
const site_id = config.get("site_id") as string; const site_id = config.get("site_id") as string;
await prasi_content_deploy.prepare(site_id);
if (!site_id) { if (!site_id) {
siteLog("No Site Loaded"); siteLog("No Site Loaded");
} else { } else {
siteLog(`Site ID: ${site_id}`); siteLog(`Site ID: ${site_id}`);
}
if (!is_ipc) { await ensureDBReady();
await prasi_content_deploy.prepare(site_id); } else {
g.mode = "site";
if (g.mode === "site") g.ipc = true;
} }
await ensureServerReady(is_dev); await ensureServerReady(is_dev);
await ensureDBReady();
if (is_ipc) {
g.mode = "site";
if (g.mode === "site") g.ipc = true;
} else {
}
startServer({ startServer({
site_id,
mode: is_dev ? "dev" : "prod", mode: is_dev ? "dev" : "prod",
}); });
}
}); });