import { promises as fs } from "node:fs"; import path from "node:path"; import { DEFAULT_REMOTE_CONFIG, mergeRemoteConfig, type NomadroRemoteConfig, } from "~/lib/remote-config"; const FILE = path.join(process.cwd(), "data", "remote-config.json"); export async function readRemoteConfigFile(): Promise { try { const raw = await fs.readFile(FILE, "utf8"); return mergeRemoteConfig(JSON.parse(raw) as Partial); } catch { return structuredClone(DEFAULT_REMOTE_CONFIG); } } export async function writeRemoteConfigFile( next: NomadroRemoteConfig, ): Promise { const merged = mergeRemoteConfig({ ...next, updatedAt: new Date().toISOString(), version: Math.max(1, Number(next.version) || 1), }); await fs.mkdir(path.dirname(FILE), { recursive: true }); await fs.writeFile(FILE, JSON.stringify(merged, null, 2), "utf8"); return merged; }