-
Notifications
You must be signed in to change notification settings - Fork 377
/
index.js
55 lines (48 loc) 路 1.64 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var themeServer = process.env.THEME_SERVER || 'https://themes.jsonresume.org/theme/';
var fs = require('fs');
var request = require('superagent');
var chalk = require('chalk');
var renderHtml = require("../render-html");
function sendExportHTML(resumeJson, theme, callback) {
console.log(resumeJson, theme);
console.log('Requesting theme from server...');
request
.post(themeServer + theme)
.send({
resume: resumeJson
})
.set('Accept', 'application/json')
.end(function(err, response) {
if (err) {
callback('There was an error downloading your generated html resume from our server: ' + err);
} else if (response.text) {
callback(null, response.text);
} else {
callback('There was an error downloading your generated html resume from our server.');
}
});
}
module.exports = function resumeBuilder(theme, dir, resumeFilename, cb) {
fs.readFile(resumeFilename, async function(err, resumeJson) {
if (err) {
console.log(chalk.yellow('Could not find:'), resumeFilename);
console.log(chalk.cyan('Using example resume.json from resume-schema instead...'));
resumeJson = require('resume-schema').resumeJson;
} else {
try {
// todo: test resume schema
resumeJson = JSON.parse(resumeJson);
} catch (e) {
err = 'Parse error: ' + resumeFilename;
return cb(err);
}
}
try {
const html = await renderHtml(resumeJson, theme);
cb(null, html);
} catch (err) {
console.log(chalk.yellow('Could not run the render function from local theme.'));
sendExportHTML(resumeJson, theme, cb);
}
});
};