Passed
Pull Request — master (#5)
by Vitor
04:52 queued 01:53
created

cli/export-pdf-resume.js   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 25
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 16
mnd 0
bc 0
fnc 1
dl 0
loc 25
bpm 0
cpm 1
noi 4
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A export-pdf-resume.js ➔ exportResumeAsPdf 0 16 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', 'resume-html.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