Skip to content

Commit

Permalink
feat: fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdavis committed Nov 18, 2020
2 parents f807fdf + d7528ad commit 5c63a89
Show file tree
Hide file tree
Showing 6 changed files with 1,723 additions and 3,123 deletions.
31 changes: 6 additions & 25 deletions lib/builder/index.js
@@ -1,9 +1,9 @@
const themeServer =
process.env.THEME_SERVER || 'https://themes.jsonresume.org/theme/';
const path = require('path');
const fs = require('fs');
const request = require('superagent');
const chalk = require('chalk');
const renderHtml = require('../render-html');

const sendExportHTML = (resumeJson, theme, callback) => {
console.log(resumeJson, theme);
Expand All @@ -30,9 +30,8 @@ const sendExportHTML = (resumeJson, theme, callback) => {
}
});
};

module.exports = (theme, _dir, resumeFilename, cb) => {
fs.readFile(resumeFilename, (err, resumeJson) => {
module.exports = function resumeBuilder(theme, dir, resumeFilename, cb) {
fs.readFile(resumeFilename, async (err, resumeJson) => {
if (err) {
console.log(chalk.yellow('Could not find:'), resumeFilename);
console.log(
Expand All @@ -49,28 +48,10 @@ module.exports = (theme, _dir, resumeFilename, cb) => {
}
}

let render;
try {
if (theme[0] === '.') {
theme = path.join(process.cwd(), theme, 'index.js');
}
render = require(theme).render;
} catch (e) {
// The file does not exist.
console.log('The specified local theme failed with the error below');
console.log(chalk.red(e));
}

if (render && typeof render === 'function') {
try {
const rendered = render(resumeJson);
return typeof rendered.then === 'function' // check if it's a promise
? rendered.then(cb.bind(null, null), cb)
: cb(null, rendered);
} catch (e) {
return cb(e);
}
} else {
const html = await renderHtml(resumeJson, theme);
cb(null, html);
} catch (err) {
console.log(
chalk.yellow('Could not run the render function from local theme.'),
);
Expand Down
42 changes: 22 additions & 20 deletions lib/export-resume/index.js
Expand Up @@ -3,6 +3,8 @@ const path = require('path');
const puppeteer = require('puppeteer');
const btoa = require('btoa');

const renderHtml = require('../render-html');

module.exports = (resumeJson, fileName, theme, format, callback) => {
if (!fileName) {
console.error('Please enter a export destination.');
Expand Down Expand Up @@ -41,20 +43,6 @@ const extractFileFormat = (fileName) => {
return fileName.substring(dotPos + 1).toLowerCase();
};

const createHtml = (resumeJson, fileName, theme, format, callback) => {
const html = renderHtml(resumeJson, theme);
const stream = fs.createWriteStream(
path.resolve(process.cwd(), fileName + format),
);

stream.write(html, (error) => {
if (error) {
return callback(error);
}
stream.close(callback);
});
};

const getThemePkg = (theme) => {
if (theme[0] === '.') {
theme = path.join(process.cwd(), theme, 'index.js');
Expand All @@ -73,22 +61,36 @@ const getThemePkg = (theme) => {
}
};

const renderHtml = (resumeJson, theme) => {
const themePkg = getThemePkg(theme);
const contents = themePkg.render(resumeJson);
return contents;
};
async function createHtml(resumeJson, fileName, theme, format, callback) {
try {
const html = await renderHtml(resumeJson, theme);
const stream = fs.createWriteStream(
path.resolve(process.cwd(), fileName + format),
);

stream.write(html, () => {
stream.close(callback);
});
} catch (err) {
// Theme not installed
console.log(
'You have to install this theme globally to use it e.g. `npm install -g ' +
theme +
'`',
);
process.exit();
}
}
const createPdf = (resumeJson, fileName, theme, format, callback) => {
(async () => {
const html = renderHtml(resumeJson, theme);
const themePkg = getThemePkg(theme);
const puppeteerLaunchArgs = [];

if (process.env.RESUME_PUPPETEER_NO_SANDBOX) {
puppeteerLaunchArgs.push('--no-sandbox');
}

const html = await renderHtml(resumeJson, theme);
const browser = await puppeteer.launch({
args: puppeteerLaunchArgs,
});
Expand Down
24 changes: 24 additions & 0 deletions lib/render-html/index.js
@@ -0,0 +1,24 @@
const path = require('path');
const chalk = require('chalk');

module.exports = async function renderHtml(resumeJson, theme) {
if (!theme.match('jsonresume-theme-.*')) {
theme = 'jsonresume-theme-' + theme;
}
let themePath;
if (theme[0] === '.') {
themePath = path.join(process.cwd(), theme, 'index.js');
} else {
themePath = path.resolve(process.cwd(), 'node_modules', theme);
}
const render = require(themePath).render;

if (typeof render !== 'function') {
console.log(
chalk.yellow('Could not run the render function from local theme.'),
);
return Promise.reject(new Error(`Can't render with "${theme}"'s theme`));
}

return render(resumeJson);
};

0 comments on commit 5c63a89

Please sign in to comment.