mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-02 20:37:08 +01:00
feat: convert: support multiple JRS versions
This commit is contained in:
4
dist/cli/error.js
vendored
4
dist/cli/error.js
vendored
@ -266,6 +266,10 @@ Error-handling routines for HackMyResume.
|
||||
case HMSTATUS.themeHelperLoad:
|
||||
msg = printf(M2C(this.msgs.themeHelperLoad.msg), ex.glob);
|
||||
etype = 'error';
|
||||
break;
|
||||
case HMSTATUS.invalidSchemaVersion:
|
||||
msg = printf(M2C(this.msgs.invalidSchemaVersion.msg), ex.data);
|
||||
etype = 'error';
|
||||
}
|
||||
return {
|
||||
msg: msg,
|
||||
|
2
dist/cli/main.js
vendored
2
dist/cli/main.js
vendored
@ -74,7 +74,7 @@ Definition of the `main` function.
|
||||
program.command('validate')["arguments"]('<sources...>').description('Validate a resume in FRESH or JSON RESUME format.').action(function(sources) {
|
||||
execute.call(this, sources, [], this.opts(), logMsg);
|
||||
});
|
||||
program.command('convert').description('Convert a resume to/from FRESH or JSON RESUME format.').action(function() {
|
||||
program.command('convert').description('Convert a resume to/from FRESH or JSON RESUME format.').option('-f --format <fmt>', 'FRESH or JRS format and optional version', void 0).action(function() {
|
||||
var x;
|
||||
x = splitSrcDest.call(this);
|
||||
execute.call(this, x.src, x.dst, this.opts(), logMsg);
|
||||
|
2
dist/cli/msg.yml
vendored
2
dist/cli/msg.yml
vendored
@ -137,3 +137,5 @@ errors:
|
||||
An error occurred while attempting to load the '%s' theme helper. Is the
|
||||
theme correctly installed?
|
||||
dummy: dontcare
|
||||
invalidSchemaVersion:
|
||||
msg: "'%s' is not recognized as a valid schema version."
|
||||
|
23
dist/core/fresh-resume.js
vendored
23
dist/core/fresh-resume.js
vendored
@ -109,14 +109,27 @@ Definition of the FRESHResume class.
|
||||
Save the sheet to disk in a specific format, either FRESH or JSON Resume.
|
||||
*/
|
||||
|
||||
FreshResume.prototype.saveAs = function(filename, format) {
|
||||
var newRep;
|
||||
if (format !== 'JRS') {
|
||||
FreshResume.prototype.saveAs = function(filename, format, version) {
|
||||
var freshVersionReg, newRep, parts, safeFormat, safeVersion;
|
||||
safeFormat = (format || 'FRESH').trim();
|
||||
safeVersion = version || "0";
|
||||
freshVersionReg = require('../utils/fresh-version-regex');
|
||||
if (!freshVersionReg().test(safeFormat)) {
|
||||
throw {
|
||||
badVer: safeFormat
|
||||
};
|
||||
}
|
||||
parts = safeFormat.split('@');
|
||||
if (parts[0] === 'FRESH') {
|
||||
this.imp.file = filename || this.imp.file;
|
||||
FS.writeFileSync(this.imp.file, this.stringify(), 'utf8');
|
||||
} else {
|
||||
newRep = CONVERTER.toJRS(this);
|
||||
} else if (parts[0] === 'JRS') {
|
||||
newRep = CONVERTER.toJRS(this, null, parts.length > 1 ? parts[1] : "1.0.0");
|
||||
FS.writeFileSync(filename, JRSResume.stringify(newRep), 'utf8');
|
||||
} else {
|
||||
throw {
|
||||
badVer: safeFormat
|
||||
};
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
3
dist/core/status-codes.js
vendored
3
dist/core/status-codes.js
vendored
@ -37,7 +37,8 @@ Status codes for HackMyResume.
|
||||
invalidOptionsFile: 27,
|
||||
optionsFileNotFound: 28,
|
||||
unknownSchema: 29,
|
||||
themeHelperLoad: 30
|
||||
themeHelperLoad: 30,
|
||||
invalidSchemaVersion: 31
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
37
dist/verbs/convert.js
vendored
37
dist/verbs/convert.js
vendored
@ -39,7 +39,7 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
*/
|
||||
|
||||
_convert = function(srcs, dst, opts) {
|
||||
var results;
|
||||
var fmtUp, freshVerRegex, matches, results, targetSchema, targetVer;
|
||||
if (!srcs || !srcs.length) {
|
||||
this.err(HMSTATUS.resumeNotFound, {
|
||||
quit: true
|
||||
@ -65,13 +65,27 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
quit: true
|
||||
});
|
||||
}
|
||||
targetVer = null;
|
||||
if (opts.format) {
|
||||
fmtUp = opts.format.trim().toUpperCase();
|
||||
freshVerRegex = require('../utils/fresh-version-regex');
|
||||
matches = fmtUp.match(freshVerRegex());
|
||||
if (!matches) {
|
||||
this.err(HMSTATUS.invalidSchemaVersion, {
|
||||
data: opts.format.trim(),
|
||||
quit: true
|
||||
});
|
||||
}
|
||||
targetSchema = matches[1];
|
||||
targetVer = matches[2] || '1';
|
||||
}
|
||||
if (this.hasError()) {
|
||||
this.reject(this.errorCode);
|
||||
return null;
|
||||
}
|
||||
results = _.map(srcs, function(src, idx) {
|
||||
var r;
|
||||
r = _convertOne.call(this, src, dst, idx);
|
||||
r = _convertOne.call(this, src, dst, idx, targetSchema, targetVer);
|
||||
if (r.fluenterror) {
|
||||
r.quit = opts.assert;
|
||||
this.err(r.fluenterror, r);
|
||||
@ -89,8 +103,8 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
|
||||
/** Private workhorse method. Convert a single resume. */
|
||||
|
||||
_convertOne = function(src, dst, idx) {
|
||||
var rez, rinfo, srcFmt, targetFormat;
|
||||
_convertOne = function(src, dst, idx, targetSchema, targetVer) {
|
||||
var err, rez, rinfo, srcFmt, targetFormat;
|
||||
rinfo = ResumeFactory.loadOne(src, {
|
||||
format: null,
|
||||
objectify: true,
|
||||
@ -118,14 +132,25 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
rinfo.fluenterror = HMSTATUS.unknownSchema;
|
||||
return rinfo;
|
||||
}
|
||||
targetFormat = srcFmt === 'JRS' ? 'FRESH' : 'JRS';
|
||||
targetFormat = targetSchema || (srcFmt === 'JRS' ? 'FRESH' : 'JRS');
|
||||
this.stat(HMEVENT.beforeConvert, {
|
||||
srcFile: rinfo.file,
|
||||
srcFmt: srcFmt,
|
||||
dstFile: dst[idx],
|
||||
dstFmt: targetFormat
|
||||
});
|
||||
rez.saveAs(dst[idx], targetFormat);
|
||||
try {
|
||||
rez.saveAs(dst[idx], targetFormat, targetVer);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
if (err.badVer) {
|
||||
return {
|
||||
fluenterror: HMSTATUS.invalidSchemaVersion,
|
||||
quit: true,
|
||||
data: err.badVer
|
||||
};
|
||||
}
|
||||
}
|
||||
return rez;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user