|
| 1 | +/** |
| 2 | + * One-shot patch for foundation.html: removes the top-right "Console →" pill |
| 3 | + * from the bundled JSX module so the standalone brand sheet stops cross-linking |
| 4 | + * to the Console doc. |
| 5 | + * |
| 6 | + * Re-run if you ever re-export the foundation HTML from Penpot. |
| 7 | + */ |
| 8 | +import { readFileSync, writeFileSync } from 'fs'; |
| 9 | +import { gunzipSync, gzipSync } from 'zlib'; |
| 10 | + |
| 11 | +const TARGET_UUID = '0779aa1d-eb15-4e5c-8f25-e0ee165f5cbb'; |
| 12 | +const HEADER_BLOCK_START = ' <div style={{ display: "flex", alignItems: "center", gap: 8 }}>'; |
| 13 | +const HEADER_BLOCK_END = ' </a>\n </div>'; |
| 14 | + |
| 15 | +const path = process.argv[2]; |
| 16 | +if (!path) { |
| 17 | + console.error('usage: bun _patch.ts <foundation.html>'); |
| 18 | + process.exit(1); |
| 19 | +} |
| 20 | + |
| 21 | +const file = readFileSync(path, 'utf8'); |
| 22 | +const lines = file.split('\n'); |
| 23 | +const manifestLineIdx = lines.findIndex((l, i) => i >= 180 && l.startsWith('{"')); |
| 24 | +if (manifestLineIdx < 0) throw new Error('manifest line not found'); |
| 25 | +const manifest = JSON.parse(lines[manifestLineIdx]) as Record< |
| 26 | + string, |
| 27 | + { mime: string; compressed: boolean; data: string } |
| 28 | +>; |
| 29 | + |
| 30 | +const entry = manifest[TARGET_UUID]; |
| 31 | +if (!entry) throw new Error(`uuid ${TARGET_UUID} not in manifest`); |
| 32 | + |
| 33 | +const raw = Buffer.from(entry.data, 'base64'); |
| 34 | +const original = entry.compressed ? gunzipSync(raw).toString('utf8') : raw.toString('utf8'); |
| 35 | + |
| 36 | +const startIdx = original.indexOf(HEADER_BLOCK_START); |
| 37 | +if (startIdx < 0) throw new Error('header block start not found — already patched?'); |
| 38 | +const endIdx = original.indexOf(HEADER_BLOCK_END, startIdx); |
| 39 | +if (endIdx < 0) throw new Error('header block end not found'); |
| 40 | + |
| 41 | +const patched = |
| 42 | + original.slice(0, startIdx) + |
| 43 | + original.slice(endIdx + HEADER_BLOCK_END.length).replace(/^\n/, ''); |
| 44 | + |
| 45 | +const verify = patched.match(/Console →/g) ?? []; |
| 46 | +console.log(`Console → occurrences: ${verify.length} (was 2, should be 1 after patch)`); |
| 47 | + |
| 48 | +const reEncoded = entry.compressed |
| 49 | + ? gzipSync(Buffer.from(patched, 'utf8')).toString('base64') |
| 50 | + : Buffer.from(patched, 'utf8').toString('base64'); |
| 51 | + |
| 52 | +manifest[TARGET_UUID] = { ...entry, data: reEncoded }; |
| 53 | +lines[manifestLineIdx] = JSON.stringify(manifest); |
| 54 | + |
| 55 | +writeFileSync(path, lines.join('\n')); |
| 56 | +console.log(`patched ${path} (entry shrank from ${original.length} to ${patched.length} chars)`); |
0 commit comments