const puppeteer = require('puppeteer'); const fs = require('fs'); const Epub = require('epub-gen'); const css = fs.readFileSync('./src/epub.css', 'utf-8'); module.exports = { html: function ({ html, path }) { return new Promise((resolve, reject) => { fs.writeFile(path, html, (e) => { if (e) { reject(e); } else { resolve(); } }); }); }, pdf: async function ({ path, html }) { const browser = await puppeteer.launch({ headless: true }); const page = await browser.newPage(); await page.setContent(html, { waitUntil: 'load' }); const pdf = await page.pdf({ path, preferCSSPageSize: true, printBackground: true }); await browser.close(); }, epub: function ({ lang, l10n, structure, path }) { const epubData = { title: l10n.title, author: l10n.author, css, tocTitle: l10n.toc, appendChapterTitles: false, content: structure.sections.reduce((content, section) => { content.push({ title: section.title.toUpperCase(), data: `