2025-01-29 21:39:42 +00:00
|
|
|
import { $ } from 'bun'
|
2024-01-08 23:09:06 +00:00
|
|
|
import * as Fs from 'fs'
|
|
|
|
import * as Path from 'path'
|
|
|
|
import * as Stream from 'stream/promises'
|
|
|
|
import * as Puppeteer from 'puppeteer'
|
|
|
|
|
|
|
|
/** @type {import('puppeteer').PDFOptions} */
|
|
|
|
const PDF_OPTIONS = {
|
|
|
|
printBackground: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
const DEBUG = !!process.env['DEBUG']
|
|
|
|
|
|
|
|
const root = 'file://' + Path.resolve(import.meta.dir, './dist')
|
|
|
|
console.log(root)
|
|
|
|
|
|
|
|
await $`bun bundle --public-url ${root}`
|
|
|
|
|
|
|
|
const pup = await Puppeteer.launch({ headless: DEBUG ? false : 'new' })
|
|
|
|
const page = await pup.newPage()
|
2025-01-29 21:39:42 +00:00
|
|
|
await page.goto(root + '/index.html')
|
2024-01-08 23:09:06 +00:00
|
|
|
await page.waitForNetworkIdle()
|
|
|
|
const pdf = await page.createPDFStream(PDF_OPTIONS)
|
|
|
|
const out = Fs.createWriteStream('./resume.pdf', { flags: 'w+' })
|
|
|
|
await Stream.pipeline(pdf, out)
|
|
|
|
if (!DEBUG) await pup.close()
|
|
|
|
console.log('wrote ./resume.pdf')
|
|
|
|
|
|
|
|
process.on('SIGINT', () => {
|
|
|
|
pup.close()
|
|
|
|
})
|
|
|
|
|
|
|
|
process.on('SIGHUP', () => {
|
|
|
|
pup.close()
|
|
|
|
})
|
|
|
|
|
|
|
|
process.on('exit', () => {
|
|
|
|
pup.close()
|
|
|
|
})
|