when-am-i / files / scripts / screenshot-calendar.mts
screenshot-calendar.mts
| 1 | // Screenshot one calendar data file across its eras, for inclusion in a |
| 2 | // calendar PR (so reviewers can see geometry/era/conversion issues visually). |
| 3 | // |
| 4 | // npm run screenshot:calendar -- src/data/calendars/massachusett.json |
| 5 | // |
| 6 | // For each era it pins a point inside the region and a representative date in |
| 7 | // that era, then captures the answer panel + shaded map. Output: |
| 8 | // screenshots/calendars/<file>/ |
| 9 | // |
| 10 | // To regenerate shots for every calendar at once, use `npm run screenshot:calendars`. |
| 11 | |
| 12 | import { chromium } from 'playwright'; |
| 13 | import path from 'node:path'; |
| 14 | import { startDevServer } from './lib/server.mts'; |
| 15 | import { screenshotCalendar } from './lib/calendar-shots.mts'; |
| 16 | |
| 17 | async function run() { |
| 18 | const fileArg = process.argv[2]; |
| 19 | if (!fileArg) { |
| 20 | console.error('usage: npm run screenshot:calendar -- <path/to/calendar.json>'); |
| 21 | process.exit(1); |
| 22 | } |
| 23 | |
| 24 | const server = await startDevServer(); |
| 25 | try { |
| 26 | const browser = await chromium.launch(); |
| 27 | const page = await browser.newPage({ viewport: { width: 1100, height: 920 }, deviceScaleFactor: 2 }); |
| 28 | await screenshotCalendar(page, fileArg); |
| 29 | await browser.close(); |
| 30 | console.log(`\n✨ Done — screenshots/calendars/${path.basename(fileArg, '.json')}/\n`); |
| 31 | } finally { |
| 32 | server.stop(); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | run().catch((err) => { |
| 37 | console.error(err); |
| 38 | process.exit(1); |
| 39 | }); |