12 lines
470 B
TypeScript
12 lines
470 B
TypeScript
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
|
/** Write generated UTF-8 output only when bytes changed, preserving mtimes on no-op builds. */
|
|
export function writeGeneratedFile(path: string, content: string): boolean {
|
|
const normalized = content.replace(/\r\n/g, "\n");
|
|
if (existsSync(path) && readFileSync(path, "utf8").replace(/\r\n/g, "\n") === normalized) {
|
|
return false;
|
|
}
|
|
writeFileSync(path, normalized, "utf8");
|
|
return true;
|
|
}
|