|
@@ -7,12 +7,12 @@ const yaml = require("yaml");
|
|
|
const puppeteer = require("puppeteer");
|
|
const puppeteer = require("puppeteer");
|
|
|
const pug = require("pug");
|
|
const pug = require("pug");
|
|
|
|
|
|
|
|
-function parseResume(resumePath) {
|
|
|
|
|
- return yaml.parse(fs.readFileSync(resumePath, { encoding: "utf8" }));
|
|
|
|
|
|
|
+function parseData(dataFilePath) {
|
|
|
|
|
+ return yaml.parse(fs.readFileSync(dataFilePath, { encoding: "utf8" }));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function createHtml(pugFile, resumeData, outputPath) {
|
|
|
|
|
- const rendered = pug.renderFile(pugFile, resumeData);
|
|
|
|
|
|
|
+function createHtml(pugFile, data, outputPath) {
|
|
|
|
|
+ const rendered = pug.renderFile(pugFile, data);
|
|
|
|
|
|
|
|
fs.writeFile(outputPath, rendered, (err) => {
|
|
fs.writeFile(outputPath, rendered, (err) => {
|
|
|
if (err) throw err;
|
|
if (err) throw err;
|
|
@@ -39,8 +39,8 @@ function exportToPdf(htmlFile, pdfPath) {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function exportResumeToPdf(resumeDataPath, localPugPath, assetsPath, outputPath, outputBasename) {
|
|
|
|
|
- const resumeData = parseResume(resumeDataPath);
|
|
|
|
|
|
|
+function exportRenderToPdf(dataFilePath, templatePath, assetsPath, outputPath, outputBasename) {
|
|
|
|
|
+ const data = parseData(dataFilePath);
|
|
|
const htmlPath = path.join(outputPath, `${outputBasename}.html`);
|
|
const htmlPath = path.join(outputPath, `${outputBasename}.html`);
|
|
|
const pdfPath = path.join(outputPath, `${outputBasename}.pdf`);
|
|
const pdfPath = path.join(outputPath, `${outputBasename}.pdf`);
|
|
|
const newAssetsPath = path.join(outputPath, "assets");
|
|
const newAssetsPath = path.join(outputPath, "assets");
|
|
@@ -49,19 +49,19 @@ function exportResumeToPdf(resumeDataPath, localPugPath, assetsPath, outputPath,
|
|
|
fs.mkdirSync(newAssetsPath, { recursive: true });
|
|
fs.mkdirSync(newAssetsPath, { recursive: true });
|
|
|
fs.cpSync(assetsPath, newAssetsPath, { recursive: true });
|
|
fs.cpSync(assetsPath, newAssetsPath, { recursive: true });
|
|
|
|
|
|
|
|
- createHtml(localPugPath, resumeData, htmlPath);
|
|
|
|
|
|
|
+ createHtml(templatePath, data, htmlPath);
|
|
|
console.log(`Wrote HTML file to ${htmlPath}`);
|
|
console.log(`Wrote HTML file to ${htmlPath}`);
|
|
|
|
|
|
|
|
exportToPdf(htmlPath, pdfPath);
|
|
exportToPdf(htmlPath, pdfPath);
|
|
|
console.log(`Wrote PDF file to ${pdfPath}`);
|
|
console.log(`Wrote PDF file to ${pdfPath}`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const [resumeDataPath, resumeTemplatePath, assetsPath, outputPath] = process.argv.slice(2);
|
|
|
|
|
-if (!resumeDataPath || !resumeTemplatePath || !assetsPath || !outputPath) {
|
|
|
|
|
|
|
+const [dataFilePath, templatePath, assetsPath, outputPath] = process.argv.slice(2);
|
|
|
|
|
+if (!dataFilePath || !templatePath || !assetsPath || !outputPath) {
|
|
|
console.error(
|
|
console.error(
|
|
|
`The script should be called like :\n${process.argv[1]} resume_path template_path assets_dir output_dir`
|
|
`The script should be called like :\n${process.argv[1]} resume_path template_path assets_dir output_dir`
|
|
|
);
|
|
);
|
|
|
process.exit(1);
|
|
process.exit(1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-exportResumeToPdf(resumeDataPath, resumeTemplatePath, assetsPath, outputPath, "resume");
|
|
|
|
|
|
|
+exportRenderToPdf(dataFilePath, templatePath, assetsPath, outputPath, "resume");
|