Passed
Pull Request — master (#5)
by Vitor
02:29
created

export-pdf-resume.js ➔ exportResumeAsPdf   A

Complexity

Conditions 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 16
c 0
b 0
f 0
rs 9.9
cc 1
1
// this script assumes you have puppeteer installed, but its not in the list of dependencies
2
// so you have to install it globally with `npm i -g puppeteer` and link it with `npm link puppeteer`
3
import puppeteer from 'puppeteer';
4
import path from 'path';
5
6
const rootDir = process.cwd();
7
const sourceHtmlFile = path.join('public', 'resume', 'index.html');
8
const targetPdf = path.join('static', 'vitor-mello-resume.pdf');
9
10
async function exportResumeAsPdf() {
11
  console.log('Starting PDF export.', '\n');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
introduced by
Unexpected console statement.
Loading history...
12
  const browser = await puppeteer.launch({ headless: true });
13
  const page = await browser.newPage();
14
15
  console.log(`Opening "/${sourceHtmlFile}"...`);
0 ignored issues
show
introduced by
Unexpected console statement.
Loading history...
16
17
  await page.goto(`file://${path.join(rootDir, sourceHtmlFile)}`, { waitUntil: 'networkidle0' });
18
19
  await page.pdf({ format: 'A4', path: targetPdf, margin: { top: 0, right: 0, bottom: 0, left: 0 } });
20
21
  await page.close();
22
  await browser.close();
23
24
  console.log('\n', `✅  All done! PDF exported to "/${targetPdf}".`);
0 ignored issues
show
introduced by
Unexpected console statement.
Loading history...
25
}
26
27
exportResumeAsPdf();
28