Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented support for YAML Fresh resumes #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions src/core/resume-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ module.exports = {
if (info.fluenterror) { return info; }

// Determine the resume format: FRESH or JRS
let { json } = info;
const orgFormat = resumeDetect(json);
let { data } = info;
const orgFormat = resumeDetect(data);
if (orgFormat === 'unk') {
info.fluenterror = HMS.unknownSchema;
return info;
}

// Convert between formats if necessary
if (toFormat && ( orgFormat !== toFormat )) {
json = ResumeConverter[ `to${toFormat.toUpperCase()}` ](json);
data = ResumeConverter[ `to${toFormat.toUpperCase()}` ](data);
}

// Objectify the resume, that is, convert it from JSON to a FRESHResume
Expand All @@ -83,18 +83,34 @@ module.exports = {
if (opts.objectify) {
const reqLib = `../core/${toFormat || orgFormat}-resume`;
const ResumeClass = require(reqLib);
rez = new ResumeClass().parseJSON( json, opts.inner );
rez = new ResumeClass().parseJSON( data, opts.inner );
rez.i().file = src;
}

return {
file: src,
json: info.json,
json: info.data,
rez
};
}
};

var _parseJSON = function( rawData ) {
let ret = JSON.parse( rawData );
return ret.json;
};

var _parseYAML = function( rawData ) {
const yaml = require('js-yaml');
let ret = yaml.safeLoad(rawData);
return ret;
};

const parsers = {
'json': _parseJSON,
'yml': _parseYAML,
'yaml': _parseYAML,
};

var _parse = function( fileName, opts, eve ) {

Expand All @@ -105,16 +121,17 @@ var _parse = function( fileName, opts, eve ) {
eve && eve.stat( HME.beforeRead, { file: fileName });
rawData = FS.readFileSync( fileName, 'utf8' );
eve && eve.stat( HME.afterRead, { file: fileName, data: rawData });
let extension = fileName.split('.').pop();

// Parse the file
eve && eve.stat(HME.beforeParse, { data: rawData });
const ret = { json: JSON.parse( rawData ) };
let ret = parsers[extension](rawData);
const orgFormat =
ret.json.meta && ret.json.meta.format && ret.json.meta.format.startsWith('FRESH@')
ret.meta && ret.meta.format && ret.meta.format.startsWith('FRESH@')
? 'fresh' : 'jrs';

eve && eve.stat(HME.afterParse, { file: fileName, data: ret.json, fmt: orgFormat });
return ret;
eve && eve.stat(HME.afterParse, { file: fileName, data: ret, fmt: orgFormat });
return { data: ret };
} catch (err) {
// Can be ENOENT, EACCES, SyntaxError, etc.
return {
Expand Down