mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-25 01:40:10 +00:00
feat: convert: support multiple JRS versions
This commit is contained in:
parent
58fe46dc83
commit
7cfdb95a04
4
dist/cli/error.js
vendored
4
dist/cli/error.js
vendored
@ -266,6 +266,10 @@ Error-handling routines for HackMyResume.
|
|||||||
case HMSTATUS.themeHelperLoad:
|
case HMSTATUS.themeHelperLoad:
|
||||||
msg = printf(M2C(this.msgs.themeHelperLoad.msg), ex.glob);
|
msg = printf(M2C(this.msgs.themeHelperLoad.msg), ex.glob);
|
||||||
etype = 'error';
|
etype = 'error';
|
||||||
|
break;
|
||||||
|
case HMSTATUS.invalidSchemaVersion:
|
||||||
|
msg = printf(M2C(this.msgs.invalidSchemaVersion.msg), ex.data);
|
||||||
|
etype = 'error';
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
msg: msg,
|
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) {
|
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);
|
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;
|
var x;
|
||||||
x = splitSrcDest.call(this);
|
x = splitSrcDest.call(this);
|
||||||
execute.call(this, x.src, x.dst, this.opts(), logMsg);
|
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
|
An error occurred while attempting to load the '%s' theme helper. Is the
|
||||||
theme correctly installed?
|
theme correctly installed?
|
||||||
dummy: dontcare
|
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.
|
Save the sheet to disk in a specific format, either FRESH or JSON Resume.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
FreshResume.prototype.saveAs = function(filename, format) {
|
FreshResume.prototype.saveAs = function(filename, format, version) {
|
||||||
var newRep;
|
var freshVersionReg, newRep, parts, safeFormat, safeVersion;
|
||||||
if (format !== 'JRS') {
|
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;
|
this.imp.file = filename || this.imp.file;
|
||||||
FS.writeFileSync(this.imp.file, this.stringify(), 'utf8');
|
FS.writeFileSync(this.imp.file, this.stringify(), 'utf8');
|
||||||
} else {
|
} else if (parts[0] === 'JRS') {
|
||||||
newRep = CONVERTER.toJRS(this);
|
newRep = CONVERTER.toJRS(this, null, parts.length > 1 ? parts[1] : "1.0.0");
|
||||||
FS.writeFileSync(filename, JRSResume.stringify(newRep), 'utf8');
|
FS.writeFileSync(filename, JRSResume.stringify(newRep), 'utf8');
|
||||||
|
} else {
|
||||||
|
throw {
|
||||||
|
badVer: safeFormat
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return this;
|
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,
|
invalidOptionsFile: 27,
|
||||||
optionsFileNotFound: 28,
|
optionsFileNotFound: 28,
|
||||||
unknownSchema: 29,
|
unknownSchema: 29,
|
||||||
themeHelperLoad: 30
|
themeHelperLoad: 30,
|
||||||
|
invalidSchemaVersion: 31
|
||||||
};
|
};
|
||||||
|
|
||||||
}).call(this);
|
}).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) {
|
_convert = function(srcs, dst, opts) {
|
||||||
var results;
|
var fmtUp, freshVerRegex, matches, results, targetSchema, targetVer;
|
||||||
if (!srcs || !srcs.length) {
|
if (!srcs || !srcs.length) {
|
||||||
this.err(HMSTATUS.resumeNotFound, {
|
this.err(HMSTATUS.resumeNotFound, {
|
||||||
quit: true
|
quit: true
|
||||||
@ -65,13 +65,27 @@ Implementation of the 'convert' verb for HackMyResume.
|
|||||||
quit: true
|
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()) {
|
if (this.hasError()) {
|
||||||
this.reject(this.errorCode);
|
this.reject(this.errorCode);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
results = _.map(srcs, function(src, idx) {
|
results = _.map(srcs, function(src, idx) {
|
||||||
var r;
|
var r;
|
||||||
r = _convertOne.call(this, src, dst, idx);
|
r = _convertOne.call(this, src, dst, idx, targetSchema, targetVer);
|
||||||
if (r.fluenterror) {
|
if (r.fluenterror) {
|
||||||
r.quit = opts.assert;
|
r.quit = opts.assert;
|
||||||
this.err(r.fluenterror, r);
|
this.err(r.fluenterror, r);
|
||||||
@ -89,8 +103,8 @@ Implementation of the 'convert' verb for HackMyResume.
|
|||||||
|
|
||||||
/** Private workhorse method. Convert a single resume. */
|
/** Private workhorse method. Convert a single resume. */
|
||||||
|
|
||||||
_convertOne = function(src, dst, idx) {
|
_convertOne = function(src, dst, idx, targetSchema, targetVer) {
|
||||||
var rez, rinfo, srcFmt, targetFormat;
|
var err, rez, rinfo, srcFmt, targetFormat;
|
||||||
rinfo = ResumeFactory.loadOne(src, {
|
rinfo = ResumeFactory.loadOne(src, {
|
||||||
format: null,
|
format: null,
|
||||||
objectify: true,
|
objectify: true,
|
||||||
@ -118,14 +132,25 @@ Implementation of the 'convert' verb for HackMyResume.
|
|||||||
rinfo.fluenterror = HMSTATUS.unknownSchema;
|
rinfo.fluenterror = HMSTATUS.unknownSchema;
|
||||||
return rinfo;
|
return rinfo;
|
||||||
}
|
}
|
||||||
targetFormat = srcFmt === 'JRS' ? 'FRESH' : 'JRS';
|
targetFormat = targetSchema || (srcFmt === 'JRS' ? 'FRESH' : 'JRS');
|
||||||
this.stat(HMEVENT.beforeConvert, {
|
this.stat(HMEVENT.beforeConvert, {
|
||||||
srcFile: rinfo.file,
|
srcFile: rinfo.file,
|
||||||
srcFmt: srcFmt,
|
srcFmt: srcFmt,
|
||||||
dstFile: dst[idx],
|
dstFile: dst[idx],
|
||||||
dstFmt: targetFormat
|
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;
|
return rez;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -257,6 +257,9 @@ assembleError = ( ex ) ->
|
|||||||
msg = printf M2C( @msgs.themeHelperLoad.msg ), ex.glob
|
msg = printf M2C( @msgs.themeHelperLoad.msg ), ex.glob
|
||||||
etype = 'error'
|
etype = 'error'
|
||||||
|
|
||||||
|
when HMSTATUS.invalidSchemaVersion
|
||||||
|
msg = printf M2C( @msgs.invalidSchemaVersion.msg ), ex.data
|
||||||
|
etype = 'error'
|
||||||
|
|
||||||
msg: msg # The error message to display
|
msg: msg # The error message to display
|
||||||
withStack: withStack # Whether to include the stack
|
withStack: withStack # Whether to include the stack
|
||||||
|
@ -84,6 +84,7 @@ main = module.exports = ( rawArgs, exitCallback ) ->
|
|||||||
program
|
program
|
||||||
.command('convert')
|
.command('convert')
|
||||||
.description('Convert a resume to/from FRESH or JSON RESUME format.')
|
.description('Convert a resume to/from FRESH or JSON RESUME format.')
|
||||||
|
.option('-f --format <fmt>', 'FRESH or JRS format and optional version', undefined)
|
||||||
.action(->
|
.action(->
|
||||||
x = splitSrcDest.call( this );
|
x = splitSrcDest.call( this );
|
||||||
execute.call( this, x.src, x.dst, this.opts(), logMsg)
|
execute.call( this, x.src, x.dst, this.opts(), logMsg)
|
||||||
|
@ -137,3 +137,5 @@ errors:
|
|||||||
An error occurred while attempting to load the '%s' theme helper. Is the
|
An error occurred while attempting to load the '%s' theme helper. Is the
|
||||||
theme correctly installed?
|
theme correctly installed?
|
||||||
dummy: dontcare
|
dummy: dontcare
|
||||||
|
invalidSchemaVersion:
|
||||||
|
msg: "'%s' is not recognized as a valid schema version."
|
||||||
|
@ -94,13 +94,26 @@ class FreshResume# extends AbstractResume
|
|||||||
###*
|
###*
|
||||||
Save the sheet to disk in a specific format, either FRESH or JSON Resume.
|
Save the sheet to disk in a specific format, either FRESH or JSON Resume.
|
||||||
###
|
###
|
||||||
saveAs: ( filename, format ) ->
|
saveAs: ( filename, format, version ) ->
|
||||||
if format != 'JRS'
|
|
||||||
|
# If format isn't specified, default to FRESH
|
||||||
|
safeFormat = (format || 'FRESH').trim()
|
||||||
|
safeVersion = version || "0"
|
||||||
|
|
||||||
|
# Validate against the FRESH version regex
|
||||||
|
# freshVersionReg = require '../utils/fresh-version-regex'
|
||||||
|
# if (not freshVersionReg().test( safeFormat ))
|
||||||
|
# throw badVer: safeFormat
|
||||||
|
|
||||||
|
parts = safeFormat.split '@'
|
||||||
|
if parts[0] == 'FRESH'
|
||||||
@imp.file = filename || @imp.file
|
@imp.file = filename || @imp.file
|
||||||
FS.writeFileSync @imp.file, @stringify(), 'utf8'
|
FS.writeFileSync @imp.file, @stringify(), 'utf8'
|
||||||
else
|
else if parts[0] == 'JRS'
|
||||||
newRep = CONVERTER.toJRS this
|
newRep = CONVERTER.toJRS @, null, if parts.length > 1 then parts[1] else "1"
|
||||||
FS.writeFileSync filename, JRSResume.stringify( newRep ), 'utf8'
|
FS.writeFileSync filename, JRSResume.stringify( newRep ), 'utf8'
|
||||||
|
else
|
||||||
|
throw badVer: safeFormat
|
||||||
@
|
@
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,3 +37,4 @@ module.exports =
|
|||||||
optionsFileNotFound: 28
|
optionsFileNotFound: 28
|
||||||
unknownSchema: 29
|
unknownSchema: 29
|
||||||
themeHelperLoad: 30
|
themeHelperLoad: 30
|
||||||
|
invalidSchemaVersion: 31
|
||||||
|
@ -46,6 +46,20 @@ _convert = ( srcs, dst, opts ) ->
|
|||||||
if srcs && dst && srcs.length && dst.length && srcs.length != dst.length
|
if srcs && dst && srcs.length && dst.length && srcs.length != dst.length
|
||||||
@err HMSTATUS.inputOutputParity, { quit: true }
|
@err HMSTATUS.inputOutputParity, { quit: true }
|
||||||
|
|
||||||
|
# Validate the destination format (if specified)
|
||||||
|
targetVer = null
|
||||||
|
if opts.format
|
||||||
|
fmtUp = opts.format.trim().toUpperCase()
|
||||||
|
freshVerRegex = require '../utils/fresh-version-regex'
|
||||||
|
matches = fmtUp.match freshVerRegex()
|
||||||
|
# null
|
||||||
|
# [ 'JRS@1.0', 'JRS', '1.0', index: 0, input: 'FRESH' ]
|
||||||
|
# [ 'FRESH', 'FRESH', undefined, index: 0, input: 'FRESH' ]
|
||||||
|
if not matches
|
||||||
|
@err HMSTATUS.invalidSchemaVersion, data: opts.format.trim(), quit: true
|
||||||
|
targetSchema = matches[1]
|
||||||
|
targetVer = matches[2] || '1'
|
||||||
|
|
||||||
# If any errors have occurred this early, we're done.
|
# If any errors have occurred this early, we're done.
|
||||||
if @hasError()
|
if @hasError()
|
||||||
@reject @errorCode
|
@reject @errorCode
|
||||||
@ -55,7 +69,7 @@ _convert = ( srcs, dst, opts ) ->
|
|||||||
results = _.map srcs, ( src, idx ) ->
|
results = _.map srcs, ( src, idx ) ->
|
||||||
|
|
||||||
# Convert each resume in turn
|
# Convert each resume in turn
|
||||||
r = _convertOne.call @, src, dst, idx
|
r = _convertOne.call @, src, dst, idx, targetSchema, targetVer
|
||||||
|
|
||||||
# Handle conversion errors
|
# Handle conversion errors
|
||||||
if r.fluenterror
|
if r.fluenterror
|
||||||
@ -74,12 +88,12 @@ _convert = ( srcs, dst, opts ) ->
|
|||||||
|
|
||||||
|
|
||||||
###* Private workhorse method. Convert a single resume. ###
|
###* Private workhorse method. Convert a single resume. ###
|
||||||
_convertOne = (src, dst, idx) ->
|
_convertOne = (src, dst, idx, targetSchema, targetVer) ->
|
||||||
|
|
||||||
# Load the resume
|
# Load the resume
|
||||||
rinfo = ResumeFactory.loadOne src,
|
rinfo = ResumeFactory.loadOne src,
|
||||||
format: null
|
format: null
|
||||||
objectify: true,
|
objectify: true
|
||||||
inner:
|
inner:
|
||||||
privatize: false
|
privatize: false
|
||||||
|
|
||||||
@ -94,6 +108,8 @@ _convertOne = (src, dst, idx) ->
|
|||||||
#@err rinfo.fluenterror, rinfo
|
#@err rinfo.fluenterror, rinfo
|
||||||
return rinfo
|
return rinfo
|
||||||
|
|
||||||
|
# Determine the resume's SOURCE format
|
||||||
|
# TODO: replace with detector component
|
||||||
rez = rinfo.rez
|
rez = rinfo.rez
|
||||||
srcFmt = ''
|
srcFmt = ''
|
||||||
if rez.meta && rez.meta.format #&& rez.meta.format.substr(0, 5).toUpperCase() == 'FRESH'
|
if rez.meta && rez.meta.format #&& rez.meta.format.substr(0, 5).toUpperCase() == 'FRESH'
|
||||||
@ -104,8 +120,10 @@ _convertOne = (src, dst, idx) ->
|
|||||||
rinfo.fluenterror = HMSTATUS.unknownSchema
|
rinfo.fluenterror = HMSTATUS.unknownSchema
|
||||||
return rinfo
|
return rinfo
|
||||||
|
|
||||||
targetFormat = if srcFmt == 'JRS' then 'FRESH' else 'JRS'
|
# Determine the TARGET format for the conversion
|
||||||
|
targetFormat = targetSchema or (if srcFmt == 'JRS' then 'FRESH' else 'JRS')
|
||||||
|
|
||||||
|
# Fire the beforeConvert event
|
||||||
this.stat HMEVENT.beforeConvert,
|
this.stat HMEVENT.beforeConvert,
|
||||||
srcFile: rinfo.file
|
srcFile: rinfo.file
|
||||||
srcFmt: srcFmt
|
srcFmt: srcFmt
|
||||||
@ -113,5 +131,9 @@ _convertOne = (src, dst, idx) ->
|
|||||||
dstFmt: targetFormat
|
dstFmt: targetFormat
|
||||||
|
|
||||||
# Save it to the destination format
|
# Save it to the destination format
|
||||||
rez.saveAs dst[idx], targetFormat
|
try
|
||||||
|
rez.saveAs dst[idx], targetFormat, targetVer
|
||||||
|
catch err
|
||||||
|
if err.badVer
|
||||||
|
return fluenterror: HMSTATUS.invalidSchemaVersion, quit: true, data: err.badVer
|
||||||
rez
|
rez
|
||||||
|
Loading…
Reference in New Issue
Block a user