import fs from "node:fs"; import path from "node:path"; export function ensureDirForFile(filePath: string): void { const dir = path.dirname(filePath); fs.mkdirSync(dir, { recursive: true }); } export function readJsonFile(filePath: string, fallback: T): T { if (!fs.existsSync(filePath)) return fallback; const raw = fs.readFileSync(filePath, "utf8"); return JSON.parse(raw) as T; } export function writeJsonFile(filePath: string, data: unknown): void { ensureDirForFile(filePath); fs.writeFileSync(filePath, JSON.stringify(data, null, 2), "utf8"); }