mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 05:40:22 +08:00
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
import { createHash } from "node:crypto";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
const src = path.join(root, "lib", "default-prompt-inject.md");
|
|
const dest = path.join(root, "lib", "default-prompt-data.js");
|
|
|
|
if (!fs.existsSync(src)) {
|
|
throw new Error(`missing ${src} — keep the local markdown, then run this script`);
|
|
}
|
|
|
|
const text = fs.readFileSync(src, "utf8");
|
|
if (!text.trim()) {
|
|
throw new Error("default-prompt-inject.md is empty");
|
|
}
|
|
|
|
const normalized = text.replace(/\r\n/g, "\n").trim();
|
|
const hash = createHash("sha256").update(normalized, "utf8").digest("hex");
|
|
const b64 = Buffer.from(text, "utf8").toString("base64");
|
|
|
|
const out = `// Generated by scripts/embed-default-prompt.mjs. Do not edit.
|
|
// Local source lib/default-prompt-inject.md is gitignored and not published.
|
|
|
|
export const DEFAULT_PROMPT_INJECT_SHA256 = ${JSON.stringify(hash)};
|
|
|
|
const DEFAULT_PROMPT_INJECT_B64 = ${JSON.stringify(b64)};
|
|
|
|
export function defaultPromptInjectText() {
|
|
return Buffer.from(DEFAULT_PROMPT_INJECT_B64, "base64").toString("utf8");
|
|
}
|
|
`;
|
|
|
|
fs.writeFileSync(dest, out, "utf8");
|
|
process.stdout.write(`wrote ${path.relative(root, dest)} sha256=${hash} bytes=${text.length}\n`);
|