mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-19 16:16:45 +00:00
15 lines
585 B
JavaScript
15 lines
585 B
JavaScript
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
import { dirname } from "node:path";
|
|
|
|
export async function writeContributorSnapshot(outputPath, snapshot) {
|
|
try {
|
|
const previous = JSON.parse(await readFile(outputPath, "utf8"));
|
|
if (JSON.stringify({ ...previous, generatedAt: snapshot.generatedAt }) === JSON.stringify(snapshot)) return false;
|
|
} catch (error) {
|
|
if (error.code !== "ENOENT") throw error;
|
|
}
|
|
await mkdir(dirname(outputPath), { recursive: true });
|
|
await writeFile(outputPath, `${JSON.stringify(snapshot, null, 2)}\n`);
|
|
return true;
|
|
}
|