({ cwd, output })
| 5 | import { runTask } from '../lib/task.js'; |
| 6 | |
| 7 | async function handler ({ cwd, output }) { |
| 8 | if (!path.isAbsolute(output)) { |
| 9 | output = path.join(cwd, output); |
| 10 | } |
| 11 | |
| 12 | const executablePath = await ensureBrowser(); |
| 13 | |
| 14 | await runTask('Printing slides', async () => { |
| 15 | const browser = await puppeteer.launch({ executablePath }); |
| 16 | |
| 17 | try { |
| 18 | const page = await browser.newPage(); |
| 19 | |
| 20 | await page.goto(`file://${cwd}/index.html`, { |
| 21 | waitUntil: 'networkidle0', |
| 22 | }); |
| 23 | |
| 24 | const { width, height } = await page.evaluate(() => { |
| 25 | const slide = document.querySelector('.slide'); |
| 26 | |
| 27 | return { |
| 28 | width: slide.offsetWidth, |
| 29 | height: slide.offsetHeight, |
| 30 | }; |
| 31 | }); |
| 32 | |
| 33 | await page.pdf({ |
| 34 | path: output, |
| 35 | width: `${width}px`, |
| 36 | height: `${height}px`, |
| 37 | }); |
| 38 | } finally { |
| 39 | await browser.close(); |
| 40 | } |
| 41 | }); |
| 42 | } |
| 43 | |
| 44 | function builder (yargs) { |
| 45 | return yargs |
nothing calls this directly
no test coverage detected