From d428f1ae295ff219ee7b9776445fd136817949a9 Mon Sep 17 00:00:00 2001 From: Beer van der Drift Date: Sun, 30 Jun 2019 22:23:22 +0200 Subject: [PATCH] fix: won't crash if pdf output folder doesn't exist --- scripts/export.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/export.js b/scripts/export.js index c4fc33d..fc64f6d 100755 --- a/scripts/export.js +++ b/scripts/export.js @@ -52,6 +52,7 @@ const convert = async () => { console.log('Connected to server ...'); console.log('Exporting ...'); try { + const relativePdfDirectoryPath = '../pdf/'; const directories = getResumesFromDirectories(); directories.forEach(async (dir) => { const browser = await puppeteer.launch({ @@ -61,8 +62,17 @@ const convert = async () => { await page.goto(`http://localhost:${config.dev.port}/#/resume/` + dir.name, { waitUntil: 'networkidle2' }); + + if ( + !fs.existsSync(path.join(__dirname, relativePdfDirectoryPath)) + ) { + fs.mkdirSync(path.join(__dirname, relativePdfDirectoryPath)); + } await page.pdf({ - path: path.join(__dirname, '../pdf/' + dir.name + '.pdf'), + path: path.join( + __dirname, + relativePdfDirectoryPath + dir.name + '.pdf' + ), format: 'A4' }); await browser.close();