// Renders the App Store screenshots from real simulator captures of a fictional demo workspace. // node design/app-store/render.mjs /iphone /ipad // Captures: capture.sh with a demo workspace, then with connect (see README.md). Output stays outside Git. import { fileURLToPath, pathToFileURL } from 'node:url'; import { dirname, join, resolve } from 'node:path'; import { mkdirSync } from 'node:fs'; const { chromium } = await import(process.env.PLAYWRIGHT ?? 'playwright'); const here = dirname(fileURLToPath(import.meta.url)); const [phoneDir, padDir, outDir] = process.argv.slice(2).map(p => resolve(p)); const icon = pathToFileURL(resolve(here, '../../brand/graphley-icon-1024-opaque.png')).href; const browser = await chromium.launch(process.env.CHROMIUM_PATH ? { executablePath: process.env.CHROMIUM_PATH } : {}); const errors = []; for (const [device, [width, height], dir] of [['iphone', [1320, 2868], phoneDir], ['ipad', [2752, 2064], padDir]]) { const out = join(outDir, device); mkdirSync(out, { recursive: true }); const url = new URL(pathToFileURL(join(here, 'layouts.html'))); url.searchParams.set('device', device); url.searchParams.set('sources', pathToFileURL(dir).href); url.searchParams.set('icon', icon); const page = await browser.newPage({ viewport: { width, height }, deviceScaleFactor: 1 }); page.on('pageerror', e => errors.push(String(e))); await page.goto(url.href); const ids = await page.evaluate(() => window.SLIDES); for (const [i, id] of ids.entries()) { url.searchParams.set('slide', i + 1); await page.goto(url.href); await page.evaluate(() => Promise.all([...document.images].map(i => i.decode()))); await page.evaluate(() => document.fonts.ready); const file = join(out, `${device}-${String(i + 1).padStart(2, '0')}-${id}.png`); await page.screenshot({ path: file, clip: { x: 0, y: 0, width, height }, omitBackground: false }); console.log(file); } await page.close(); } await browser.close(); if (errors.length) throw Error(errors.join('\n'));