2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Implementation of the 'convert' verb for HackMyResume.
|
|
|
|
@module verbs/convert
|
|
|
|
@license MIT. See LICENSE.md for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
2016-02-02 04:16:49 +00:00
|
|
|
var ConvertVerb, HMEVENT, HMSTATUS, ResumeFactory, Verb, _, _convert, _convertOne, chalk,
|
|
|
|
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
|
|
hasProp = {}.hasOwnProperty;
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
ResumeFactory = require('../core/resume-factory');
|
|
|
|
|
|
|
|
chalk = require('chalk');
|
|
|
|
|
|
|
|
Verb = require('../verbs/verb');
|
|
|
|
|
|
|
|
HMSTATUS = require('../core/status-codes');
|
|
|
|
|
|
|
|
_ = require('underscore');
|
|
|
|
|
|
|
|
HMEVENT = require('../core/event-codes');
|
|
|
|
|
2016-02-02 04:16:49 +00:00
|
|
|
module.exports = ConvertVerb = (function(superClass) {
|
|
|
|
extend(ConvertVerb, superClass);
|
|
|
|
|
|
|
|
function ConvertVerb() {
|
|
|
|
ConvertVerb.__super__.constructor.call(this, 'convert', _convert);
|
2016-01-27 10:29:26 +00:00
|
|
|
}
|
2016-02-02 04:16:49 +00:00
|
|
|
|
|
|
|
return ConvertVerb;
|
|
|
|
|
|
|
|
})(Verb);
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
|
2016-02-02 02:14:36 +00:00
|
|
|
/** Private workhorse method. Convert 0..N resumes between FRESH and JRS
|
|
|
|
formats.
|
2016-01-27 10:29:26 +00:00
|
|
|
*/
|
|
|
|
|
2016-02-02 02:14:36 +00:00
|
|
|
_convert = function(srcs, dst, opts) {
|
|
|
|
var results;
|
2016-01-27 10:29:26 +00:00
|
|
|
if (!srcs || !srcs.length) {
|
2016-02-02 02:14:36 +00:00
|
|
|
this.err(HMSTATUS.resumeNotFound, {
|
2016-01-27 10:29:26 +00:00
|
|
|
quit: true
|
2016-02-02 02:14:36 +00:00
|
|
|
});
|
|
|
|
return null;
|
2016-01-27 10:29:26 +00:00
|
|
|
}
|
|
|
|
if (!dst || !dst.length) {
|
|
|
|
if (srcs.length === 1) {
|
2016-02-02 02:14:36 +00:00
|
|
|
this.err(HMSTATUS.inputOutputParity, {
|
2016-01-27 10:29:26 +00:00
|
|
|
quit: true
|
2016-02-02 02:14:36 +00:00
|
|
|
});
|
2016-01-27 10:29:26 +00:00
|
|
|
} else if (srcs.length === 2) {
|
|
|
|
dst = dst || [];
|
|
|
|
dst.push(srcs.pop());
|
|
|
|
} else {
|
2016-02-02 02:14:36 +00:00
|
|
|
this.err(HMSTATUS.inputOutputParity, {
|
2016-01-27 10:29:26 +00:00
|
|
|
quit: true
|
2016-02-02 02:14:36 +00:00
|
|
|
});
|
2016-01-27 10:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (srcs && dst && srcs.length && dst.length && srcs.length !== dst.length) {
|
2016-02-02 02:14:36 +00:00
|
|
|
this.err(HMSTATUS.inputOutputParity, {
|
|
|
|
quit: true
|
2016-01-27 10:29:26 +00:00
|
|
|
});
|
2016-02-02 02:14:36 +00:00
|
|
|
}
|
|
|
|
results = _.map(srcs, function(src, idx) {
|
|
|
|
var r;
|
|
|
|
if (opts.assert && this.hasError()) {
|
|
|
|
return {};
|
2016-01-27 10:29:26 +00:00
|
|
|
}
|
2016-02-02 02:14:36 +00:00
|
|
|
r = _convertOne.call(this, src, dst, idx);
|
|
|
|
if (r.fluenterror) {
|
|
|
|
r.quit = opts.assert;
|
|
|
|
this.err(r.fluenterror, r);
|
|
|
|
}
|
|
|
|
return r;
|
2016-01-27 10:29:26 +00:00
|
|
|
}, this);
|
2016-02-02 02:14:36 +00:00
|
|
|
if (this.hasError() && !opts.assert) {
|
|
|
|
this.reject(results);
|
|
|
|
} else if (!this.hasError()) {
|
|
|
|
this.resolve(results);
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** Private workhorse method. Convert a single resume. */
|
|
|
|
|
|
|
|
_convertOne = function(src, dst, idx) {
|
|
|
|
var rinfo, s, srcFmt, targetFormat;
|
|
|
|
rinfo = ResumeFactory.loadOne(src, {
|
|
|
|
format: null,
|
2016-02-14 18:15:47 +00:00
|
|
|
objectify: true,
|
|
|
|
inner: {
|
|
|
|
"private": true
|
|
|
|
}
|
2016-02-02 02:14:36 +00:00
|
|
|
});
|
|
|
|
if (rinfo.fluenterror) {
|
|
|
|
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,
|
|
|
|
srcFmt: srcFmt,
|
|
|
|
dstFile: dst[idx],
|
|
|
|
dstFmt: targetFormat
|
|
|
|
});
|
|
|
|
s.saveAs(dst[idx], targetFormat);
|
|
|
|
return s;
|
2016-01-27 10:29:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}).call(this);
|
2016-02-02 02:14:36 +00:00
|
|
|
|
|
|
|
//# sourceMappingURL=convert.js.map
|