// Writes app/crafted-link.js with an arewehuman replay link for recipe.md. // The link carries the whole recording in its URL fragment (gzip + base64url), // which the viewer accepts as-is, so nothing needs to be hosted. import { readdirSync, readFileSync, writeFileSync } from 'node:fs'; import { gzipSync } from 'node:zlib'; const dir = '.arewehuman/recipe.md'; const logs = readdirSync(dir).filter((f) => f.endsWith('.awh.jsonl')); if (logs.length !== 1) { throw new Error(`Expected one recording in ${dir}, found ${logs.length}`); } const recording = readFileSync(`${dir}/${logs[0]}`); const z = gzipSync(recording, { level: 9 }).toString('base64url'); const url = `https://magland.github.io/arewehuman/#/view?z=${z}`; writeFileSync('app/crafted-link.js', `// Generated by scripts/crafted-link.mjs; do not edit.\nwindow.CRAFTED_LINK = ${JSON.stringify(url)};\n`); console.log(`app/crafted-link.js: replay link for ${logs[0]} (${url.length} characters)`);