@whimco/chisel-cli
Version:
23 lines (19 loc) • 789 B
JavaScript
// lib/emitSentinel.js
const fs = require("fs");
const path = require("path");
const crypto = require("crypto");
function writeIfChanged(file, content) {
if (fs.existsSync(file) && fs.readFileSync(file, "utf8") === content) return false;
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, content);
return true;
}
function emit(manifestJson, sentinelRel = "src/chisel/__generated__/manifest-hash.ts") {
const hash = crypto.createHash("sha1").update(JSON.stringify(manifestJson)).digest("hex").slice(0, 8);
const file = path.join(process.cwd(), sentinelRel);
const content = `// Auto-generated by Chisel. Do not edit.
export const CHISEL_MANIFEST_HASH = "${hash}" as const;
`;
return writeIfChanged(file, content);
}
module.exports = { emit };