import { access, stat } from 'fs/promises'; import { resolve, dirname } from 'path'; import { fileURLToPath } from 'url'; import { execFile } from 'child_process'; import { promisify } from 'util'; const execFileAsync = promisify(execFile); const __dir = dirname(fileURLToPath(import.meta.url)); const root = resolve(__dir, '..'); const pdfPath = resolve(root, 'output', 'cover.pdf'); const outPath = resolve(root, 'output', 'cover-300dpi.png'); try { await access(pdfPath); } catch { console.error('output/cover.pdf not found — run `pnpm cover` first'); process.exit(1); } console.log('Rendering cover to PNG at 300 DPI…'); await execFileAsync('gs', [ '-dBATCH', '-dNOPAUSE', '-dQUIET', '-sDEVICE=png16m', '-r300', `-sOutputFile=${outPath}`, pdfPath, ]); const { size } = await stat(outPath); console.log(`Cover image: output/cover-300dpi.png (${(size / 1_048_576).toFixed(1)} MB)`);