|
@@ -7,22 +7,16 @@ const yaml = require("yaml");
|
|
|
const puppeteer = require("puppeteer");
|
|
const puppeteer = require("puppeteer");
|
|
|
const pug = require("pug");
|
|
const pug = require("pug");
|
|
|
|
|
|
|
|
-const cv = yaml.parse(fs.readFileSync("./cv.yaml", { encoding: "utf8" }));
|
|
|
|
|
-
|
|
|
|
|
-function changeExt(filePath, new_) {
|
|
|
|
|
- parsed = path.parse(filePath);
|
|
|
|
|
- return path.join(parsed.dir, `${path.basename(parsed.name)}.${new_}`);
|
|
|
|
|
|
|
+function parseResume(resumePath) {
|
|
|
|
|
+ return yaml.parse(fs.readFileSync(resumePath, { encoding: "utf8" }));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function createHtml(pug_file) {
|
|
|
|
|
- const rendered = pug.renderFile(pug_file, cv);
|
|
|
|
|
- const html_path = changeExt(pug_file, "html");
|
|
|
|
|
|
|
+function createHtml(pugFile, resumeData, outputPath) {
|
|
|
|
|
+ const rendered = pug.renderFile(pugFile, resumeData);
|
|
|
|
|
|
|
|
- fs.writeFile(html_path, rendered, (err) => {
|
|
|
|
|
|
|
+ fs.writeFile(outputPath, rendered, (err) => {
|
|
|
if (err) throw err;
|
|
if (err) throw err;
|
|
|
});
|
|
});
|
|
|
- console.log(`Wrote HTML file to ${html_path}`);
|
|
|
|
|
- return html_path;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function printPDF(url) {
|
|
async function printPDF(url) {
|
|
@@ -35,20 +29,39 @@ async function printPDF(url) {
|
|
|
return pdf;
|
|
return pdf;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function exportToPdf(htmlFile) {
|
|
|
|
|
|
|
+function exportToPdf(htmlFile, pdfPath) {
|
|
|
url = `file://${path.resolve(htmlFile)}`;
|
|
url = `file://${path.resolve(htmlFile)}`;
|
|
|
- pdf_path = changeExt(htmlFile, "pdf");
|
|
|
|
|
|
|
|
|
|
printPDF(url).then((pdf) => {
|
|
printPDF(url).then((pdf) => {
|
|
|
- fs.writeFile(pdf_path, pdf, (err) => {
|
|
|
|
|
|
|
+ fs.writeFile(pdfPath, pdf, (err) => {
|
|
|
if (err) throw err;
|
|
if (err) throw err;
|
|
|
});
|
|
});
|
|
|
- console.log(`Wrote PDF file to ${pdf_path}`);
|
|
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-local_pug_path = "./resume.pug";
|
|
|
|
|
-local_pdf_path = changeExt(local_pug_path, "pdf");
|
|
|
|
|
|
|
+function exportResumeToPdf(resumeDataPath, localPugPath, assetsPath, outputPath) {
|
|
|
|
|
+ const resumeData = parseResume(resumeDataPath);
|
|
|
|
|
+ const htmlPath = path.join(outputPath, "resume.html");
|
|
|
|
|
+ const pdfPath = path.join(outputPath, "resume.pdf");
|
|
|
|
|
+ const newAssetsPath = path.join(outputPath, "assets");
|
|
|
|
|
+
|
|
|
|
|
+ fs.mkdirSync(outputPath, { recursive: true });
|
|
|
|
|
+ fs.mkdirSync(newAssetsPath, { recursive: true });
|
|
|
|
|
+ fs.cpSync(assetsPath, newAssetsPath, { recursive: true });
|
|
|
|
|
+
|
|
|
|
|
+ createHtml(localPugPath, resumeData, htmlPath);
|
|
|
|
|
+ console.log(`Wrote HTML file to ${htmlPath}`);
|
|
|
|
|
+
|
|
|
|
|
+ exportToPdf(htmlPath, pdfPath);
|
|
|
|
|
+ console.log(`Wrote PDF file to ${pdfPath}`);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const [resumeDataPath, resumeTemplatePath, assetsPath, outputPath] = process.argv.slice(2);
|
|
|
|
|
+if (!resumeDataPath || !resumeTemplatePath || !assetsPath || !outputPath) {
|
|
|
|
|
+ console.error(
|
|
|
|
|
+ `The script should be called like :\n${process.argv[1]} resume_path template_path assets_dir output_dir`
|
|
|
|
|
+ );
|
|
|
|
|
+ process.exit(1);
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-local_html_path = createHtml(local_pug_path);
|
|
|
|
|
-exportToPdf(local_html_path);
|
|
|
|
|
|
|
+exportResumeToPdf(resumeDataPath, resumeTemplatePath, assetsPath, outputPath);
|