Branchwell

PulseCanvas / app · pulsecanvas.ai / assets / app-store / mobile-marketing-1.1.5 / render.mjs

1// Renders layouts.html to App Store PNGs and contact sheets.
2// Usage: PLAYWRIGHT=/path/to/node_modules/playwright/index.mjs node render.mjs
3import { fileURLToPath, pathToFileURL } from 'node:url';
4import { dirname, join } from 'node:path';
5import { mkdirSync } from 'node:fs';
6
7const { chromium } = await import(process.env.PLAYWRIGHT ?? 'playwright');
8const here = dirname(fileURLToPath(import.meta.url));
9const page_url = pathToFileURL(join(here, 'layouts.html')).href;
10const devices = { iphone: [1320, 2868], ipad: [2752, 2064] };
11const names = ['music', 'studio', 'style', 'radio', 'export', 'free'];
12const out = join(here, 'release', 'en-US');
13mkdirSync(out, { recursive: true });
14
15const browser = await chromium.launch();
16for (const [device, [width, height]] of Object.entries(devices)) {
17 const page = await browser.newPage({ viewport: { width, height }, deviceScaleFactor: 1 });
18 for (const [index, name] of names.entries()) {
19 await page.goto(`${page_url}?device=${device}&slide=${index + 1}`);
20 await page.evaluate(() => Promise.all([...document.images].map(i => i.decode())));
21 const file = join(out, `${device}-${String(index + 1).padStart(2, '0')}-${name}.png`);
22 await page.screenshot({ path: file, clip: { x: 0, y: 0, width, height }, omitBackground: false });
23 console.log(file);
24 }
25 await page.setViewportSize({ width: 2400, height: 1800 });
26 await page.goto(`${page_url}?device=${device}&review=1`);
27 await page.evaluate(() => Promise.all([...document.images].map(i => i.decode())));
28 await page.locator('#overview').screenshot({ path: join(here, `${device}-contact-sheet.png`) });
29 await page.close();
30}
31await browser.close();