mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-05 01:56:21 +00:00
CONVERT: Improve command consistency.
This commit is contained in:
parent
6b125ed907
commit
c913de4bf7
4
dist/cli/error.js
vendored
4
dist/cli/error.js
vendored
@ -258,6 +258,10 @@ Error-handling routines for HackMyResume.
|
|||||||
case HMSTATUS.optionsFileNotFound:
|
case HMSTATUS.optionsFileNotFound:
|
||||||
msg = M2C(this.msgs.optionsFileNotFound.msg);
|
msg = M2C(this.msgs.optionsFileNotFound.msg);
|
||||||
etype = 'error';
|
etype = 'error';
|
||||||
|
break;
|
||||||
|
case HMSTATUS.unknownSchema:
|
||||||
|
msg = M2C(this.msgs.unknownSchema.msg[0]);
|
||||||
|
etype = 'error';
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
msg: msg,
|
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) {
|
executeFail = function(err) {
|
||||||
var finalErrorCode, msgs;
|
var finalErrorCode, msgs;
|
||||||
|
console.dir(err);
|
||||||
finalErrorCode = -1;
|
finalErrorCode = -1;
|
||||||
if (err) {
|
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) {
|
if (_opts.debug) {
|
||||||
msgs = require('./msg').errors;
|
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."
|
- "\nMake sure the options file contains valid JSON."
|
||||||
optionsFileNotFound:
|
optionsFileNotFound:
|
||||||
msg: "The specified options file is missing or inaccessible."
|
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);
|
output = template(info);
|
||||||
return this.log(chalk.cyan(output));
|
return this.log(chalk.cyan(output));
|
||||||
case HME.beforeConvert:
|
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:
|
case HME.afterInlineConvert:
|
||||||
return L(M2C(this.msgs.afterInlineConvert.msg, 'gray', 'white.dim'), evt.file, evt.fmt);
|
return L(M2C(this.msgs.afterInlineConvert.msg, 'gray', 'white.dim'), evt.file, evt.fmt);
|
||||||
case HME.afterValidate:
|
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() {
|
(function() {
|
||||||
var FS, HACKMYSTATUS, HME, ResumeConverter, ResumeFactory, SyntaxErrorEx, _, _parse, chalk;
|
var FS, HME, HMS, ResumeConverter, ResumeFactory, SyntaxErrorEx, _, _parse, chalk, resumeDetect;
|
||||||
|
|
||||||
FS = require('fs');
|
FS = require('fs');
|
||||||
|
|
||||||
HACKMYSTATUS = require('./status-codes');
|
HMS = require('./status-codes');
|
||||||
|
|
||||||
HME = require('./event-codes');
|
HME = require('./event-codes');
|
||||||
|
|
||||||
@ -22,6 +22,8 @@ Definition of the ResumeFactory class.
|
|||||||
|
|
||||||
_ = require('underscore');
|
_ = require('underscore');
|
||||||
|
|
||||||
|
resumeDetect = require('../utils/resume-detector');
|
||||||
|
|
||||||
require('string.prototype.startswith');
|
require('string.prototype.startswith');
|
||||||
|
|
||||||
|
|
||||||
@ -54,7 +56,7 @@ Definition of the ResumeFactory class.
|
|||||||
|
|
||||||
/** Load a single resume from disk. */
|
/** Load a single resume from disk. */
|
||||||
loadOne: function(src, opts, emitter) {
|
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;
|
toFormat = opts.format;
|
||||||
objectify = opts.objectify;
|
objectify = opts.objectify;
|
||||||
toFormat && (toFormat = toFormat.toLowerCase().trim());
|
toFormat && (toFormat = toFormat.toLowerCase().trim());
|
||||||
@ -63,14 +65,18 @@ Definition of the ResumeFactory class.
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
json = info.json;
|
json = info.json;
|
||||||
isFRESH = json.meta && json.meta.format && json.meta.format.startsWith('FRESH@');
|
orgFormat = resumeDetect(json);
|
||||||
orgFormat = isFRESH ? 'fresh' : 'jrs';
|
if (orgFormat === 'unk') {
|
||||||
|
info.fluenterror = HMS.unknownSchema;
|
||||||
|
return info;
|
||||||
|
}
|
||||||
if (toFormat && (orgFormat !== toFormat)) {
|
if (toFormat && (orgFormat !== toFormat)) {
|
||||||
json = ResumeConverter['to' + toFormat.toUpperCase()](json);
|
json = ResumeConverter['to' + toFormat.toUpperCase()](json);
|
||||||
}
|
}
|
||||||
rez = null;
|
rez = null;
|
||||||
if (objectify) {
|
if (objectify) {
|
||||||
ResumeClass = require('../core/' + (toFormat || orgFormat) + '-resume');
|
reqLib = '../core/' + (toFormat || orgFormat) + '-resume';
|
||||||
|
ResumeClass = require(reqLib);
|
||||||
rez = new ResumeClass().parseJSON(json, opts.inner);
|
rez = new ResumeClass().parseJSON(json, opts.inner);
|
||||||
rez.i().file = src;
|
rez.i().file = src;
|
||||||
}
|
}
|
||||||
@ -109,7 +115,7 @@ Definition of the ResumeFactory class.
|
|||||||
return ret;
|
return ret;
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
return {
|
return {
|
||||||
fluenterror: rawData ? HACKMYSTATUS.parseError : HACKMYSTATUS.readError,
|
fluenterror: rawData ? HMS.parseError : HMS.readError,
|
||||||
inner: _error,
|
inner: _error,
|
||||||
raw: rawData,
|
raw: rawData,
|
||||||
file: fileName
|
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,
|
createError: 25,
|
||||||
validateError: 26,
|
validateError: 26,
|
||||||
invalidOptionsFile: 27,
|
invalidOptionsFile: 27,
|
||||||
optionsFileNotFound: 28
|
optionsFileNotFound: 28,
|
||||||
|
unknownSchema: 29
|
||||||
};
|
};
|
||||||
|
|
||||||
}).call(this);
|
}).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 = {
|
HandlebarsGenerator = module.exports = {
|
||||||
generateSimple: function(data, tpl) {
|
generateSimple: function(data, tpl) {
|
||||||
var noesc, template;
|
var template;
|
||||||
try {
|
try {
|
||||||
noesc = data.opts.noescape || false;
|
|
||||||
template = HANDLEBARS.compile(tpl, {
|
template = HANDLEBARS.compile(tpl, {
|
||||||
strict: false,
|
strict: false,
|
||||||
assumeObjects: false,
|
assumeObjects: false,
|
||||||
noEscape: noesc
|
noEscape: data.opts.noescape || false
|
||||||
});
|
});
|
||||||
return template(data);
|
return template(data);
|
||||||
} catch (_error) {
|
} 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
|
quit: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (this.hasError()) {
|
||||||
|
this.reject(this.errorCode);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
results = _.map(srcs, function(src, idx) {
|
results = _.map(srcs, function(src, idx) {
|
||||||
var r;
|
var r;
|
||||||
if (opts.assert && this.hasError()) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
r = _convertOne.call(this, src, dst, idx);
|
r = _convertOne.call(this, src, dst, idx);
|
||||||
if (r.fluenterror) {
|
if (r.fluenterror) {
|
||||||
r.quit = opts.assert;
|
r.quit = opts.assert;
|
||||||
@ -89,16 +90,31 @@ 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) {
|
||||||
var rinfo, s, srcFmt, targetFormat;
|
var rez, rinfo, srcFmt, targetFormat;
|
||||||
rinfo = ResumeFactory.loadOne(src, {
|
rinfo = ResumeFactory.loadOne(src, {
|
||||||
format: null,
|
format: null,
|
||||||
objectify: true
|
objectify: true
|
||||||
});
|
});
|
||||||
if (rinfo.fluenterror) {
|
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;
|
return rinfo;
|
||||||
}
|
}
|
||||||
s = rinfo.rez;
|
|
||||||
srcFmt = ((s.basics && s.basics.imp) || s.imp).orgFormat === 'JRS' ? 'JRS' : 'FRESH';
|
|
||||||
targetFormat = srcFmt === 'JRS' ? 'FRESH' : 'JRS';
|
targetFormat = srcFmt === 'JRS' ? 'FRESH' : 'JRS';
|
||||||
this.stat(HMEVENT.beforeConvert, {
|
this.stat(HMEVENT.beforeConvert, {
|
||||||
srcFile: rinfo.file,
|
srcFile: rinfo.file,
|
||||||
@ -106,8 +122,8 @@ Implementation of the 'convert' verb for HackMyResume.
|
|||||||
dstFile: dst[idx],
|
dstFile: dst[idx],
|
||||||
dstFmt: targetFormat
|
dstFmt: targetFormat
|
||||||
});
|
});
|
||||||
s.saveAs(dst[idx], targetFormat);
|
rez.saveAs(dst[idx], targetFormat);
|
||||||
return s;
|
return rez;
|
||||||
};
|
};
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
@ -248,6 +248,11 @@ assembleError = ( ex ) ->
|
|||||||
msg = M2C( @msgs.optionsFileNotFound.msg )
|
msg = M2C( @msgs.optionsFileNotFound.msg )
|
||||||
etype = 'error'
|
etype = 'error'
|
||||||
|
|
||||||
|
when HMSTATUS.unknownSchema
|
||||||
|
msg = M2C( @msgs.unknownSchema.msg[0] )
|
||||||
|
#msg += "\n" + M2C( @msgs.unknownSchema.msg[1], 'yellow' )
|
||||||
|
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
|
||||||
quit: quit
|
quit: quit
|
||||||
|
@ -262,7 +262,7 @@ execute = ( src, dst, opts, log ) ->
|
|||||||
v = new HMR.verbs[ @name() ]()
|
v = new HMR.verbs[ @name() ]()
|
||||||
|
|
||||||
# Initialize command-specific options
|
# Initialize command-specific options
|
||||||
loadOptions.call( this, opts, this.parent.jsonArgs )
|
loadOptions.call this, opts, this.parent.jsonArgs
|
||||||
|
|
||||||
# Set up error/output handling
|
# Set up error/output handling
|
||||||
_opts.errHandler = v
|
_opts.errHandler = v
|
||||||
@ -288,9 +288,15 @@ executeSuccess = (obj) ->
|
|||||||
|
|
||||||
### Failure handler for verb invocations. Calls process.exit by default ###
|
### Failure handler for verb invocations. Calls process.exit by default ###
|
||||||
executeFail = (err) ->
|
executeFail = (err) ->
|
||||||
|
console.dir err
|
||||||
finalErrorCode = -1
|
finalErrorCode = -1
|
||||||
if err
|
if err
|
||||||
finalErrorCode = if err.fluenterror then err.fluenterror else err
|
if err.fluenterror
|
||||||
|
finalErrorCode = err.fluenterror
|
||||||
|
else if err.length
|
||||||
|
finalErrorCode = err[0].fluenterror
|
||||||
|
else
|
||||||
|
finalErrorCode = err
|
||||||
if _opts.debug
|
if _opts.debug
|
||||||
msgs = require('./msg').errors;
|
msgs = require('./msg').errors;
|
||||||
logMsg printf M2C( msgs.exiting.msg, 'cyan' ), finalErrorCode
|
logMsg printf M2C( msgs.exiting.msg, 'cyan' ), finalErrorCode
|
||||||
|
@ -115,3 +115,20 @@ errors:
|
|||||||
- "\nMake sure the options file contains valid JSON."
|
- "\nMake sure the options file contains valid JSON."
|
||||||
optionsFileNotFound:
|
optionsFileNotFound:
|
||||||
msg: "The specified options file is missing or inaccessible."
|
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"
|
||||||
|
}
|
||||||
|
@ -131,7 +131,7 @@ module.exports = class OutputHandler
|
|||||||
@log( chalk.cyan(output) )
|
@log( chalk.cyan(output) )
|
||||||
|
|
||||||
when HME.beforeConvert
|
when HME.beforeConvert
|
||||||
L( M2C( this.msgs.beforeConvert.msg, 'green' ),
|
L( M2C( this.msgs.beforeConvert.msg, if evt.error then 'red' else 'green' ),
|
||||||
evt.srcFile, evt.srcFmt, evt.dstFile, evt.dstFmt
|
evt.srcFile, evt.srcFmt, evt.dstFile, evt.dstFmt
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -6,14 +6,15 @@ Definition of the ResumeFactory class.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
FS = require('fs')
|
FS = require 'fs'
|
||||||
HACKMYSTATUS = require('./status-codes')
|
HMS = require './status-codes'
|
||||||
HME = require('./event-codes')
|
HME = require './event-codes'
|
||||||
ResumeConverter = require('fresh-jrs-converter')
|
ResumeConverter = require 'fresh-jrs-converter'
|
||||||
chalk = require('chalk')
|
chalk = require 'chalk'
|
||||||
SyntaxErrorEx = require('../utils/syntax-error-ex')
|
SyntaxErrorEx = require '../utils/syntax-error-ex'
|
||||||
_ = require('underscore')
|
_ = require 'underscore'
|
||||||
require('string.prototype.startswith')
|
resumeDetect = require '../utils/resume-detector'
|
||||||
|
require 'string.prototype.startswith'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -62,20 +63,23 @@ ResumeFactory = module.exports =
|
|||||||
|
|
||||||
# Determine the resume format: FRESH or JRS
|
# Determine the resume format: FRESH or JRS
|
||||||
json = info.json
|
json = info.json
|
||||||
isFRESH = json.meta && json.meta.format && json.meta.format.startsWith('FRESH@');
|
orgFormat = resumeDetect json
|
||||||
orgFormat = if isFRESH then 'fresh' else 'jrs'
|
if orgFormat == 'unk'
|
||||||
|
info.fluenterror = HMS.unknownSchema
|
||||||
|
return info
|
||||||
|
|
||||||
# Convert between formats if necessary
|
# Convert between formats if necessary
|
||||||
if toFormat and ( orgFormat != toFormat )
|
if toFormat and ( orgFormat != toFormat )
|
||||||
json = ResumeConverter[ 'to' + toFormat.toUpperCase() ]( json )
|
json = ResumeConverter[ 'to' + toFormat.toUpperCase() ] json
|
||||||
|
|
||||||
# Objectify the resume, that is, convert it from JSON to a FRESHResume
|
# Objectify the resume, that is, convert it from JSON to a FRESHResume
|
||||||
# or JRSResume object.
|
# or JRSResume object.
|
||||||
rez = null
|
rez = null
|
||||||
if objectify
|
if objectify
|
||||||
ResumeClass = require('../core/' + (toFormat || orgFormat) + '-resume');
|
reqLib = '../core/' + (toFormat || orgFormat) + '-resume'
|
||||||
rez = new ResumeClass().parseJSON( json, opts.inner );
|
ResumeClass = require reqLib
|
||||||
rez.i().file = src;
|
rez = new ResumeClass().parseJSON( json, opts.inner )
|
||||||
|
rez.i().file = src
|
||||||
|
|
||||||
file: src
|
file: src
|
||||||
json: info.json
|
json: info.json
|
||||||
@ -103,7 +107,7 @@ _parse = ( fileName, opts, eve ) ->
|
|||||||
return ret
|
return ret
|
||||||
catch
|
catch
|
||||||
# Can be ENOENT, EACCES, SyntaxError, etc.
|
# Can be ENOENT, EACCES, SyntaxError, etc.
|
||||||
fluenterror: if rawData then HACKMYSTATUS.parseError else HACKMYSTATUS.readError
|
fluenterror: if rawData then HMS.parseError else HMS.readError
|
||||||
inner: _error
|
inner: _error
|
||||||
raw: rawData
|
raw: rawData
|
||||||
file: fileName
|
file: fileName
|
||||||
|
@ -35,3 +35,4 @@ module.exports =
|
|||||||
validateError: 26
|
validateError: 26
|
||||||
invalidOptionsFile: 27
|
invalidOptionsFile: 27
|
||||||
optionsFileNotFound: 28
|
optionsFileNotFound: 28
|
||||||
|
unknownSchema: 29
|
||||||
|
13
src/utils/resume-detector.coffee
Normal file
13
src/utils/resume-detector.coffee
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
###*
|
||||||
|
Definition of the ResumeDetector class.
|
||||||
|
@module utils/resume-detector
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
###
|
||||||
|
|
||||||
|
module.exports = ( rez ) ->
|
||||||
|
if rez.meta && rez.meta.format #&& rez.meta.format.substr(0, 5).toUpperCase() == 'FRESH'
|
||||||
|
'fresh'
|
||||||
|
else if rez.basics
|
||||||
|
'jrs'
|
||||||
|
else
|
||||||
|
'unk'
|
@ -26,10 +26,14 @@ formats. ###
|
|||||||
|
|
||||||
_convert = ( srcs, dst, opts ) ->
|
_convert = ( srcs, dst, opts ) ->
|
||||||
|
|
||||||
# Housekeeping...
|
# If no source resumes are specified, error out
|
||||||
if !srcs || !srcs.length
|
if !srcs || !srcs.length
|
||||||
@err HMSTATUS.resumeNotFound, { quit: true }
|
@err HMSTATUS.resumeNotFound, { quit: true }
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
# If no destination resumes are specified, error out except for the special
|
||||||
|
# case of two resumes:
|
||||||
|
# hackmyresume CONVERT r1.json r2.json
|
||||||
if !dst || !dst.length
|
if !dst || !dst.length
|
||||||
if srcs.length == 1
|
if srcs.length == 1
|
||||||
@err HMSTATUS.inputOutputParity, { quit: true }
|
@err HMSTATUS.inputOutputParity, { quit: true }
|
||||||
@ -37,19 +41,30 @@ _convert = ( srcs, dst, opts ) ->
|
|||||||
dst = dst || []; dst.push( srcs.pop() )
|
dst = dst || []; dst.push( srcs.pop() )
|
||||||
else
|
else
|
||||||
@err HMSTATUS.inputOutputParity, { quit: true }
|
@err HMSTATUS.inputOutputParity, { quit: true }
|
||||||
|
|
||||||
|
# Different number of source and dest resumes? Error out.
|
||||||
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 }
|
||||||
|
|
||||||
# Load source resumes
|
# If any errors have occurred this early, we're done.
|
||||||
|
if @hasError()
|
||||||
|
@reject @errorCode
|
||||||
|
return null
|
||||||
|
|
||||||
|
# Map each source resume to the converted destination resume
|
||||||
results = _.map srcs, ( src, idx ) ->
|
results = _.map srcs, ( src, idx ) ->
|
||||||
return { } if opts.assert and @hasError()
|
|
||||||
|
# Convert each resume in turn
|
||||||
r = _convertOne.call @, src, dst, idx
|
r = _convertOne.call @, src, dst, idx
|
||||||
|
|
||||||
|
# Handle conversion errors
|
||||||
if r.fluenterror
|
if r.fluenterror
|
||||||
r.quit = opts.assert
|
r.quit = opts.assert
|
||||||
@err r.fluenterror, r
|
@err r.fluenterror, r
|
||||||
r
|
r
|
||||||
, @
|
, @
|
||||||
|
|
||||||
|
|
||||||
if @hasError() and !opts.assert
|
if @hasError() and !opts.assert
|
||||||
@reject results
|
@reject results
|
||||||
else if !@hasError()
|
else if !@hasError()
|
||||||
@ -60,17 +75,31 @@ _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) ->
|
||||||
|
|
||||||
# Load the resume
|
# Load the resume
|
||||||
rinfo = ResumeFactory.loadOne src, format: null, objectify: true
|
rinfo = ResumeFactory.loadOne src, format: null, objectify: true
|
||||||
|
|
||||||
# If a load error occurs, report it and move on to the next file (if any)
|
# If a load error occurs, report it and move on to the next file (if any)
|
||||||
if rinfo.fluenterror
|
if rinfo.fluenterror
|
||||||
|
@stat HMEVENT.beforeConvert,
|
||||||
|
srcFile: src #rinfo.file
|
||||||
|
srcFmt: '???'
|
||||||
|
dstFile: dst[idx]
|
||||||
|
dstFmt: '???'
|
||||||
|
error: true
|
||||||
|
#@err rinfo.fluenterror, rinfo
|
||||||
|
return rinfo
|
||||||
|
|
||||||
|
rez = rinfo.rez
|
||||||
|
srcFmt = ''
|
||||||
|
if rez.meta && rez.meta.format #&& rez.meta.format.substr(0, 5).toUpperCase() == 'FRESH'
|
||||||
|
srcFmt = 'FRESH'
|
||||||
|
else if rez.basics
|
||||||
|
srcFmt = 'JRS'
|
||||||
|
else
|
||||||
|
rinfo.fluenterror = HMSTATUS.unknownSchema
|
||||||
return rinfo
|
return rinfo
|
||||||
|
|
||||||
s = rinfo.rez
|
|
||||||
srcFmt =
|
|
||||||
if ((s.basics && s.basics.imp) || s.imp).orgFormat == 'JRS'
|
|
||||||
then 'JRS' else 'FRESH'
|
|
||||||
targetFormat = if srcFmt == 'JRS' then 'FRESH' else 'JRS'
|
targetFormat = if srcFmt == 'JRS' then 'FRESH' else 'JRS'
|
||||||
|
|
||||||
this.stat HMEVENT.beforeConvert,
|
this.stat HMEVENT.beforeConvert,
|
||||||
@ -80,5 +109,5 @@ _convertOne = (src, dst, idx) ->
|
|||||||
dstFmt: targetFormat
|
dstFmt: targetFormat
|
||||||
|
|
||||||
# Save it to the destination format
|
# Save it to the destination format
|
||||||
s.saveAs dst[idx], targetFormat
|
rez.saveAs dst[idx], targetFormat
|
||||||
s
|
rez
|
||||||
|
@ -32,12 +32,20 @@ module.exports = class Verb
|
|||||||
|
|
||||||
###* Invoke the command. ###
|
###* Invoke the command. ###
|
||||||
invoke: ->
|
invoke: ->
|
||||||
|
|
||||||
|
# Sent the 'begin' notification for this verb
|
||||||
@stat HMEVENT.begin, cmd: @moniker
|
@stat HMEVENT.begin, cmd: @moniker
|
||||||
|
|
||||||
|
# Prepare command arguments
|
||||||
argsArray = Array::slice.call arguments
|
argsArray = Array::slice.call arguments
|
||||||
|
|
||||||
|
# Create a promise for this verb instance
|
||||||
that = @
|
that = @
|
||||||
@promise = new Promise (res, rej) ->
|
@promise = new Promise (res, rej) ->
|
||||||
that.resolve = res; that.reject = rej
|
that.resolve = res
|
||||||
that.workhorse.apply that, argsArray; return
|
that.reject = rej
|
||||||
|
that.workhorse.apply that, argsArray
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +13,10 @@
|
|||||||
0|analyze node_modules/fresh-test-resumes/src/fresh/johnny-trouble.json
|
0|analyze node_modules/fresh-test-resumes/src/fresh/johnny-trouble.json
|
||||||
3|convert
|
3|convert
|
||||||
7|convert doesnt-exist.json
|
7|convert doesnt-exist.json
|
||||||
|
14|convert from.json to.json
|
||||||
|
7|convert z1.json z2.json z3.json
|
||||||
|
7|convert z1.json z2.json z3.json z4.json
|
||||||
|
14|convert z1.json z2.json to z3.json z4.json
|
||||||
3|validate
|
3|validate
|
||||||
14|validate doesnt-exist.json
|
14|validate doesnt-exist.json
|
||||||
0|validate node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json
|
0|validate node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json
|
||||||
|
Loading…
Reference in New Issue
Block a user