import { mkdir, readFile, writeFile } from "node:fs/promises";
import { dirname } from "node:path";
export async function writeGeneratedFile(filePath, content, options = {}) {
    const { checkOnly = false } = options;
    let currentContent = null;
    try {
        currentContent = await readFile(filePath, "utf-8");
    }
    catch {
        currentContent = null;
    }
    if (currentContent === content) {
        return { filePath, status: "unchanged" };
    }
    if (checkOnly) {
        return { filePath, status: "stale" };
    }
    await mkdir(dirname(filePath), { recursive: true });
    await writeFile(filePath, content, "utf-8");
    return { filePath, status: "written" };
}
