Files
resume/utils/generatePdf.ts
Art Rosnovsky 12adecfeeb chore: add basic tests (#4)
* chore: add basic tests
* chore: address feedback
2024-02-05 19:55:58 -08:00

26 lines
823 B
TypeScript

import path from 'node:path';
import fs from 'node:fs';
import { checkFileExists, checkFolderExists } from './fsChecks';
import { markdownToPdf } from './markdownToPdf';
export async function generatePdf(inputFilePath: string, outputFilePath: string) {
if (!checkFileExists(inputFilePath)) {
throw new Error(`File ${inputFilePath} does not exist. How am I supposed to build you a resume, mate?`);
}
if (!checkFolderExists(outputFilePath)) {
fs.mkdirSync(outputFilePath.split('/').slice(0, -1).join("/"), { recursive: true });
}
try {
const pdf = await markdownToPdf(inputFilePath);
if (pdf) {
fs.writeFileSync(path.resolve(__dirname, outputFilePath), pdf.content);
return;
}
} catch (error: any) {
console.error(`Error occurred: ${error.message}`);
throw error;
}
}