// Builds the deck in three layers: // 1. composition/index.html: the HyperFrames composition (one scene per src/slides/*.html, // in file-name order, plus the slideshow island). Relative asset paths, so // `hyperframes lint composition` and `hyperframes present composition` work on it. // 2. dist/index.html + dist/composition.html: the slideshow wrapper and the composition with // every font, image and script inlined, so the deck makes no network requests. // 3. app/assets.generated.ts: those two pages and the favicon, served by app/router.ts. // Fails on an em dash (U+2014) anywhere we own or ship, on past-tense words in slide text, // and on any external or relative resource left in the shipped pages. import { copyFileSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs' import { extname, join, relative } from 'node:path' import QRCode from 'qrcode' const root = new URL('..', import.meta.url).pathname const src = join(root, 'src') const comp = join(root, 'composition') const EM_DASH = '\u2014' export const DECK_URL = 'https://cloudflare-connect-pse-hyperframes--kentcdodds.kody.run' const walk = (dir) => readdirSync(dir).flatMap((name) => { const p = join(dir, name) return statSync(p).isDirectory() ? walk(p) : [p] }) const textExt = new Set(['.html', '.css', '.js', '.mjs', '.ts', '.json', '.md', '.svg']) const owned = [...walk(src), ...walk(join(root, 'scripts')), join(root, 'app/router.ts'), join(root, 'README.md'), join(root, 'AGENTS.md'), join(root, 'package.json')] const dashHits = owned .filter((f) => textExt.has(extname(f))) .flatMap((f) => readFileSync(f, 'utf8').split('\n').flatMap((line, i) => (line.includes(EM_DASH) ? [`${relative(root, f)}:${i + 1}`] : []))) if (dashHits.length) throw new Error(`em dash (U+2014) found, use a comma, colon or period instead:\n${dashHits.join('\n')}`) // The QR code on the closing slides points at the hosted deck. mkdirSync(join(comp, 'assets/img'), { recursive: true }) writeFileSync(join(comp, 'assets/img/qr-deck.svg'), await QRCode.toString(DECK_URL, { type: 'svg', margin: 1, errorCorrectionLevel: 'M', color: { dark: '#111111', light: '#ffffff' } })) // Slides:
with an optional `) .replace('', () => islandTag) .replace('', () => `
\n${scenes.join('\n')}\n
`) .replace('/* flows.js */', () => readFileSync(join(src, 'flows.js'), 'utf8')) .replace('/* runtime.js */', () => readFileSync(join(src, 'runtime.js'), 'utf8')) writeFileSync(join(comp, 'index.html'), composition) // Layer 2: self-contained pages. const types = { '.png': 'image/png', '.svg': 'image/svg+xml', '.woff2': 'font/woff2', '.ico': 'image/x-icon', '.webp': 'image/webp' } const dataUri = (rel) => { const file = join(comp, rel) const type = types[extname(file)] if (!type) throw new Error(`No content type for ${rel}`) return `data:${type};base64,${readFileSync(file).toString('base64')}` } // Inlined JS must not close its `) const playerDist = join(root, 'node_modules/@hyperframes/player/dist') const wrapper = readFileSync(join(src, 'index.html'), 'utf8') .replace('/* player.js */', () => inlineJs(readFileSync(join(playerDist, 'hyperframes-player.global.js'), 'utf8'))) .replace('/* slideshow.js */', () => inlineJs(readFileSync(join(playerDist, 'slideshow/hyperframes-slideshow.global.js'), 'utf8'))) .replace('', () => islandTag) .replace('href="favicon.ico"', `href="data:image/png;base64,${readFileSync(join(src, 'icons/favicon-32x32.png')).toString('base64')}"`) for (const [name, page] of [['index.html', wrapper], ['composition.html', distComposition]]) { const markup = page.replace(/