use postMessage

This commit is contained in:
Rami Bitar
2026-05-02 09:53:48 -04:00
parent e17fefe025
commit 82809b17b4
4 changed files with 9 additions and 76 deletions

View File

@@ -1,39 +1,7 @@
import fs from "node:fs/promises";
import path from "node:path";
export const SCHEMA_PATH = path.join(process.cwd(), "app.schema.json");
import schemaJson from "../app.schema.json";
export type Schema = Record<string, { root: any; content: any[] }>;
const FALLBACK: Schema = {
"/": { root: { props: { title: "Untitled" } }, content: [] },
};
export async function readSchema(): Promise<Schema> {
try {
const raw = await fs.readFile(SCHEMA_PATH, "utf8");
const parsed = JSON.parse(raw);
if (parsed && typeof parsed === "object") return parsed as Schema;
return FALLBACK;
} catch {
return FALLBACK;
}
}
export async function writeSchema(schema: Schema): Promise<void> {
await fs.writeFile(
SCHEMA_PATH,
JSON.stringify(schema, null, 2) + "\n",
"utf8",
);
}
export async function patchRoute(
route: string,
data: { root: any; content: any[] },
): Promise<Schema> {
const current = await readSchema();
const next: Schema = { ...current, [route]: data };
await writeSchema(next);
return next;
return schemaJson as Schema;
}