mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-02 20:37:08 +01:00
CONVERT: Improve command consistency.
This commit is contained in:
4
dist/cli/error.js
vendored
4
dist/cli/error.js
vendored
@ -258,6 +258,10 @@ Error-handling routines for HackMyResume.
|
||||
case HMSTATUS.optionsFileNotFound:
|
||||
msg = M2C(this.msgs.optionsFileNotFound.msg);
|
||||
etype = 'error';
|
||||
break;
|
||||
case HMSTATUS.unknownSchema:
|
||||
msg = M2C(this.msgs.unknownSchema.msg[0]);
|
||||
etype = 'error';
|
||||
}
|
||||
return {
|
||||
msg: msg,
|
||||
|
9
dist/cli/main.js
vendored
9
dist/cli/main.js
vendored
@ -257,9 +257,16 @@ Definition of the `main` function.
|
||||
|
||||
executeFail = function(err) {
|
||||
var finalErrorCode, msgs;
|
||||
console.dir(err);
|
||||
finalErrorCode = -1;
|
||||
if (err) {
|
||||
finalErrorCode = err.fluenterror ? err.fluenterror : err;
|
||||
if (err.fluenterror) {
|
||||
finalErrorCode = err.fluenterror;
|
||||
} else if (err.length) {
|
||||
finalErrorCode = err[0].fluenterror;
|
||||
} else {
|
||||
finalErrorCode = err;
|
||||
}
|
||||
}
|
||||
if (_opts.debug) {
|
||||
msgs = require('./msg').errors;
|
||||
|
17
dist/cli/msg.yml
vendored
17
dist/cli/msg.yml
vendored
@ -115,3 +115,20 @@ errors:
|
||||
- "\nMake sure the options file contains valid JSON."
|
||||
optionsFileNotFound:
|
||||
msg: "The specified options file is missing or inaccessible."
|
||||
unknownSchema:
|
||||
msg:
|
||||
- "Unknown resume schema. Did you specify a valid FRESH or JRS resume?"
|
||||
- |
|
||||
At a minimum, a FRESH resume must include a "name" field and a "meta"
|
||||
property.
|
||||
|
||||
"name": "John Doe",
|
||||
"meta": {
|
||||
"format": "FRESH@0.1.0"
|
||||
}
|
||||
|
||||
JRS-format resumes must include a "basics" section with a "name":
|
||||
|
||||
"basics": {
|
||||
"name": "John Doe"
|
||||
}
|
||||
|
2
dist/cli/out.js
vendored
2
dist/cli/out.js
vendored
@ -128,7 +128,7 @@ Output routines for HackMyResume.
|
||||
output = template(info);
|
||||
return this.log(chalk.cyan(output));
|
||||
case HME.beforeConvert:
|
||||
return L(M2C(this.msgs.beforeConvert.msg, 'green'), evt.srcFile, evt.srcFmt, evt.dstFile, evt.dstFmt);
|
||||
return L(M2C(this.msgs.beforeConvert.msg, evt.error ? 'red' : 'green'), evt.srcFile, evt.srcFmt, evt.dstFile, evt.dstFmt);
|
||||
case HME.afterInlineConvert:
|
||||
return L(M2C(this.msgs.afterInlineConvert.msg, 'gray', 'white.dim'), evt.file, evt.fmt);
|
||||
case HME.afterValidate:
|
||||
|
20
dist/core/resume-factory.js
vendored
20
dist/core/resume-factory.js
vendored
@ -6,11 +6,11 @@ Definition of the ResumeFactory class.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var FS, HACKMYSTATUS, HME, ResumeConverter, ResumeFactory, SyntaxErrorEx, _, _parse, chalk;
|
||||
var FS, HME, HMS, ResumeConverter, ResumeFactory, SyntaxErrorEx, _, _parse, chalk, resumeDetect;
|
||||
|
||||
FS = require('fs');
|
||||
|
||||
HACKMYSTATUS = require('./status-codes');
|
||||
HMS = require('./status-codes');
|
||||
|
||||
HME = require('./event-codes');
|
||||
|
||||
@ -22,6 +22,8 @@ Definition of the ResumeFactory class.
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
resumeDetect = require('../utils/resume-detector');
|
||||
|
||||
require('string.prototype.startswith');
|
||||
|
||||
|
||||
@ -54,7 +56,7 @@ Definition of the ResumeFactory class.
|
||||
|
||||
/** Load a single resume from disk. */
|
||||
loadOne: function(src, opts, emitter) {
|
||||
var ResumeClass, info, isFRESH, json, objectify, orgFormat, rez, toFormat;
|
||||
var ResumeClass, info, json, objectify, orgFormat, reqLib, rez, toFormat;
|
||||
toFormat = opts.format;
|
||||
objectify = opts.objectify;
|
||||
toFormat && (toFormat = toFormat.toLowerCase().trim());
|
||||
@ -63,14 +65,18 @@ Definition of the ResumeFactory class.
|
||||
return info;
|
||||
}
|
||||
json = info.json;
|
||||
isFRESH = json.meta && json.meta.format && json.meta.format.startsWith('FRESH@');
|
||||
orgFormat = isFRESH ? 'fresh' : 'jrs';
|
||||
orgFormat = resumeDetect(json);
|
||||
if (orgFormat === 'unk') {
|
||||
info.fluenterror = HMS.unknownSchema;
|
||||
return info;
|
||||
}
|
||||
if (toFormat && (orgFormat !== toFormat)) {
|
||||
json = ResumeConverter['to' + toFormat.toUpperCase()](json);
|
||||
}
|
||||
rez = null;
|
||||
if (objectify) {
|
||||
ResumeClass = require('../core/' + (toFormat || orgFormat) + '-resume');
|
||||
reqLib = '../core/' + (toFormat || orgFormat) + '-resume';
|
||||
ResumeClass = require(reqLib);
|
||||
rez = new ResumeClass().parseJSON(json, opts.inner);
|
||||
rez.i().file = src;
|
||||
}
|
||||
@ -109,7 +115,7 @@ Definition of the ResumeFactory class.
|
||||
return ret;
|
||||
} catch (_error) {
|
||||
return {
|
||||
fluenterror: rawData ? HACKMYSTATUS.parseError : HACKMYSTATUS.readError,
|
||||
fluenterror: rawData ? HMS.parseError : HMS.readError,
|
||||
inner: _error,
|
||||
raw: rawData,
|
||||
file: fileName
|
||||
|
3
dist/core/status-codes.js
vendored
3
dist/core/status-codes.js
vendored
@ -35,7 +35,8 @@ Status codes for HackMyResume.
|
||||
createError: 25,
|
||||
validateError: 26,
|
||||
invalidOptionsFile: 27,
|
||||
optionsFileNotFound: 28
|
||||
optionsFileNotFound: 28,
|
||||
unknownSchema: 29
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
5
dist/renderers/handlebars-generator.js
vendored
5
dist/renderers/handlebars-generator.js
vendored
@ -34,13 +34,12 @@ Definition of the HandlebarsGenerator class.
|
||||
|
||||
HandlebarsGenerator = module.exports = {
|
||||
generateSimple: function(data, tpl) {
|
||||
var noesc, template;
|
||||
var template;
|
||||
try {
|
||||
noesc = data.opts.noescape || false;
|
||||
template = HANDLEBARS.compile(tpl, {
|
||||
strict: false,
|
||||
assumeObjects: false,
|
||||
noEscape: noesc
|
||||
noEscape: data.opts.noescape || false
|
||||
});
|
||||
return template(data);
|
||||
} catch (_error) {
|
||||
|
21
dist/utils/resume-detector.js
vendored
Normal file
21
dist/utils/resume-detector.js
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
/**
|
||||
Definition of the ResumeDetector class.
|
||||
@module utils/resume-detector
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
module.exports = function(rez) {
|
||||
if (rez.meta && rez.meta.format) {
|
||||
return 'fresh';
|
||||
} else if (rez.basics) {
|
||||
return 'jrs';
|
||||
} else {
|
||||
return 'unk';
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
||||
//# sourceMappingURL=resume-detector.js.map
|
32
dist/verbs/convert.js
vendored
32
dist/verbs/convert.js
vendored
@ -65,11 +65,12 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
quit: true
|
||||
});
|
||||
}
|
||||
if (this.hasError()) {
|
||||
this.reject(this.errorCode);
|
||||
return null;
|
||||
}
|
||||
results = _.map(srcs, function(src, idx) {
|
||||
var r;
|
||||
if (opts.assert && this.hasError()) {
|
||||
return {};
|
||||
}
|
||||
r = _convertOne.call(this, src, dst, idx);
|
||||
if (r.fluenterror) {
|
||||
r.quit = opts.assert;
|
||||
@ -89,16 +90,31 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
/** Private workhorse method. Convert a single resume. */
|
||||
|
||||
_convertOne = function(src, dst, idx) {
|
||||
var rinfo, s, srcFmt, targetFormat;
|
||||
var rez, rinfo, srcFmt, targetFormat;
|
||||
rinfo = ResumeFactory.loadOne(src, {
|
||||
format: null,
|
||||
objectify: true
|
||||
});
|
||||
if (rinfo.fluenterror) {
|
||||
this.stat(HMEVENT.beforeConvert, {
|
||||
srcFile: src,
|
||||
srcFmt: '???',
|
||||
dstFile: dst[idx],
|
||||
dstFmt: '???',
|
||||
error: true
|
||||
});
|
||||
return rinfo;
|
||||
}
|
||||
rez = rinfo.rez;
|
||||
srcFmt = '';
|
||||
if (rez.meta && rez.meta.format) {
|
||||
srcFmt = 'FRESH';
|
||||
} else if (rez.basics) {
|
||||
srcFmt = 'JRS';
|
||||
} else {
|
||||
rinfo.fluenterror = HMSTATUS.unknownSchema;
|
||||
return rinfo;
|
||||
}
|
||||
s = rinfo.rez;
|
||||
srcFmt = ((s.basics && s.basics.imp) || s.imp).orgFormat === 'JRS' ? 'JRS' : 'FRESH';
|
||||
targetFormat = srcFmt === 'JRS' ? 'FRESH' : 'JRS';
|
||||
this.stat(HMEVENT.beforeConvert, {
|
||||
srcFile: rinfo.file,
|
||||
@ -106,8 +122,8 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
dstFile: dst[idx],
|
||||
dstFmt: targetFormat
|
||||
});
|
||||
s.saveAs(dst[idx], targetFormat);
|
||||
return s;
|
||||
rez.saveAs(dst[idx], targetFormat);
|
||||
return rez;
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
Reference in New Issue
Block a user