// Builds one fully self-contained Reveal.js page from src/deck.html + src/slides/*.html (file-name // order). Reveal.js and its notes plugin come from the pinned npm package and are inlined with the // fonts, images, CSS and JS. Writes dist/index.html (the offline build) and app/assets.generated.ts // (served by the Kody app). import { readdirSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs' import { join, extname } from 'node:path' import { createHash } from 'node:crypto' import QRCode from 'qrcode' import { buildDemo } from './build-demo.mjs' const root = new URL('..', import.meta.url).pathname const src = join(root, 'src') const types = { '.png': 'image/png', '.svg': 'image/svg+xml', '.woff2': 'font/woff2', '.ico': 'image/x-icon', '.webp': 'image/webp', '.jpg': 'image/jpeg', '.html': 'text/html; charset=utf-8' } const dataUri = (rel) => { const file = join(src, 'c', rel) const type = types[extname(file)] if (!type) throw new Error(`No content type for ${rel}`) return `data:${type};base64,${readFileSync(file).toString('base64')}` } // Rewrites `@scope { a, b { ... } }` into rules prefixed with the slide's selector. function scopeCss(css, sel) { // Drop comments first: commas inside a comment would otherwise split into bogus selectors. css = css.replace(/\/\*[\s\S]*?\*\//g, '') return css.replace(/@scope\s*\{([\s\S]*)\}\s*$/m, (_, body) => body.replace(/([^{}]+)\{([^{}]*)\}/g, (_, selectors, decls) => { const out = selectors.split(',').map((s) => s.trim()).filter(Boolean).map((s) => s.includes(':scope') ? s.replace(':scope', sel) : `${sel} ${s}`, ) return `\n${out.join(', ')} {${decls}}` }), ) } // House style for everything we write: no em or en dashes and ASCII quotes only. { const files = [ ...readdirSync(join(src, 'slides')).filter((f) => f.endsWith('.html')).map((f) => join(src, 'slides', f)), ...['README.md', 'AGENTS.md', 'BEATS.md', 'src/deck.html', 'src/c/deck.css', 'src/c/deck.js', 'src/c/demo.js', 'src/c/scenes.js', 'src/sw.js'].map((f) => join(root, f)), ] const bad = [] for (const file of files) { let text try { text = readFileSync(file, 'utf8') } catch { continue } text.split('\n').forEach((line, i) => { const m = line.match(/[–—‘’“”]/) if (m) bad.push(`${file.slice(root.length)}:${i + 1}: ${JSON.stringify(m[0])}`) }) } if (bad.length) throw new Error(`house style (no em/en dashes, ASCII quotes):\n${bad.join('\n')}`) } // Brand marks and Kody Iconic glyphs, inlined so they follow the theme via currentColor. const snippets = { KODY_MARK: readFileSync(join(src, 'c/kody-mark.svg.html'), 'utf8').trim(), TREND_JSON: readFileSync(join(src, 'c/data-trend.json'), 'utf8').trim(), QR_DECK: (await QRCode.toString('https://invisible-software-slides.kentcdodds.com/', { type: 'svg', margin: 0, errorCorrectionLevel: 'M' })).replace('