import { promises as fs } from "node:fs"; export interface ChecksumEntry { key: string; checksum: string; } export async function updateChecksums( filePath: string, checksumEntries: ChecksumEntry[], ): Promise { await fs.rm(filePath); await fs.appendFile( filePath, "// AUTOGENERATED_DO_NOT_EDIT\nexport const KNOWN_CHECKSUMS: { [key: string]: string } = {\n", ); let firstLine = true; for (const entry of checksumEntries) { if (!firstLine) { await fs.appendFile(filePath, ",\n"); } await fs.appendFile(filePath, ` "${entry.key}":\n "${entry.checksum}"`); firstLine = false; } await fs.appendFile(filePath, ",\n};\n"); }