mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-02 12:27:08 +01:00
Asynchrony.
This commit is contained in:
60
dist/verbs/analyze.js
vendored
60
dist/verbs/analyze.js
vendored
@ -6,7 +6,7 @@ Implementation of the 'analyze' verb for HackMyResume.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var AnalyzeVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, ResumeFactory, Verb, _, _analyze, _loadInspectors, analyze, chalk;
|
||||
var AnalyzeVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, ResumeFactory, Verb, _, _analyze, _analyzeOne, _loadInspectors, chalk;
|
||||
|
||||
MKDIRP = require('mkdirp');
|
||||
|
||||
@ -24,46 +24,56 @@ Implementation of the 'analyze' verb for HackMyResume.
|
||||
|
||||
chalk = require('chalk');
|
||||
|
||||
|
||||
/** An invokable resume analysis command. */
|
||||
|
||||
AnalyzeVerb = module.exports = Verb.extend({
|
||||
init: function() {
|
||||
return this._super('analyze', analyze);
|
||||
return this._super('analyze', _analyze);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
Run the 'analyze' command.
|
||||
*/
|
||||
/** Private workhorse for the 'analyze' command. */
|
||||
|
||||
analyze = function(sources, dst, opts) {
|
||||
var nlzrs;
|
||||
_analyze = function(sources, dst, opts) {
|
||||
var nlzrs, results;
|
||||
if (!sources || !sources.length) {
|
||||
throw {
|
||||
fluenterror: HMSTATUS.resumeNotFound,
|
||||
this.err(HMSTATUS.resumeNotFound, {
|
||||
quit: true
|
||||
};
|
||||
});
|
||||
return null;
|
||||
}
|
||||
nlzrs = _loadInspectors();
|
||||
return _.each(sources, function(src) {
|
||||
var result;
|
||||
result = ResumeFactory.loadOne(src, {
|
||||
results = _.map(sources, function(src) {
|
||||
var r;
|
||||
r = ResumeFactory.loadOne(src, {
|
||||
format: 'FRESH',
|
||||
objectify: true
|
||||
}, this);
|
||||
if (result.fluenterror) {
|
||||
return this.setError(result.fluenterror, result);
|
||||
if (opts.assert && this.hasError()) {
|
||||
return {};
|
||||
}
|
||||
if (r.fluenterror) {
|
||||
r.quit = opts.assert;
|
||||
this.err(r.fluenterror, r);
|
||||
return r;
|
||||
} else {
|
||||
return _analyze.call(this, result, nlzrs, opts);
|
||||
return _analyzeOne.call(this, r, nlzrs, opts);
|
||||
}
|
||||
}, this);
|
||||
if (this.hasError() && !opts.assert) {
|
||||
this.reject(this.errorCode);
|
||||
} else if (!this.hasError()) {
|
||||
this.resolve(results);
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Analyze a single resume.
|
||||
*/
|
||||
/** Analyze a single resume. */
|
||||
|
||||
_analyze = function(resumeObject, nlzrs, opts) {
|
||||
_analyzeOne = function(resumeObject, nlzrs, opts) {
|
||||
var info, rez, safeFormat;
|
||||
rez = resumeObject.rez;
|
||||
safeFormat = rez.meta && rez.meta.format && rez.meta.format.startsWith('FRESH') ? 'FRESH' : 'JRS';
|
||||
@ -74,16 +84,12 @@ Implementation of the 'analyze' verb for HackMyResume.
|
||||
info = _.mapObject(nlzrs, function(val, key) {
|
||||
return val.run(rez);
|
||||
});
|
||||
return this.stat(HMEVENT.afterAnalyze, {
|
||||
this.stat(HMEVENT.afterAnalyze, {
|
||||
info: info
|
||||
});
|
||||
return info;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Load inspectors.
|
||||
*/
|
||||
|
||||
_loadInspectors = function() {
|
||||
return {
|
||||
totals: require('../inspectors/totals-inspector'),
|
||||
@ -93,3 +99,5 @@ Implementation of the 'analyze' verb for HackMyResume.
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
||||
//# sourceMappingURL=analyze.js.map
|
||||
|
63
dist/verbs/build.js
vendored
63
dist/verbs/build.js
vendored
@ -6,7 +6,7 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var BuildVerb, FRESHTheme, FS, HMEVENT, HMSTATUS, JRSTheme, MD, MKDIRP, PATH, RConverter, RTYPES, ResumeFactory, Verb, _, _err, _fmts, _log, _opts, _rezObj, addFreebieFormats, build, expand, extend, loadTheme, parsePath, prep, single, verifyOutputs, verifyTheme;
|
||||
var BuildVerb, FRESHTheme, FS, HMEVENT, HMSTATUS, JRSTheme, MD, MKDIRP, PATH, RConverter, RTYPES, ResumeFactory, Verb, _, _addFreebieFormats, _build, _err, _expand, _fmts, _loadTheme, _log, _opts, _prep, _rezObj, _single, _verifyOutputs, _verifyTheme, addFreebieFormats, build, expand, extend, loadTheme, parsePath, prep, single, verifyOutputs, verifyTheme;
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
@ -74,7 +74,7 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
|
||||
/** Create a new build verb. */
|
||||
init: function() {
|
||||
return this._super('build', build);
|
||||
return this._super('build', _build);
|
||||
}
|
||||
});
|
||||
|
||||
@ -87,15 +87,15 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
@param opts Generation options.
|
||||
*/
|
||||
|
||||
build = function(src, dst, opts) {
|
||||
var ex, inv, isFRESH, mixed, newEx, orgFormat, problemSheets, rez, sheetObjects, sheets, tFolder, targets, theme, toFormat;
|
||||
_build = function(src, dst, opts) {
|
||||
var inv, isFRESH, mixed, newEx, orgFormat, problemSheets, results, rez, sheetObjects, sheets, tFolder, targets, theme, toFormat;
|
||||
if (!src || !src.length) {
|
||||
this.err(HMSTATUS.resumeNotFound, {
|
||||
quit: true
|
||||
});
|
||||
return null;
|
||||
}
|
||||
prep(src, dst, opts);
|
||||
_prep(src, dst, opts);
|
||||
sheetObjects = ResumeFactory.load(src, {
|
||||
format: null,
|
||||
objectify: false,
|
||||
@ -120,14 +120,13 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
theme: _opts.theme
|
||||
});
|
||||
try {
|
||||
tFolder = verifyTheme.call(this, _opts.theme);
|
||||
theme = _opts.themeObj = loadTheme(tFolder);
|
||||
addFreebieFormats(theme);
|
||||
tFolder = _verifyTheme.call(this, _opts.theme);
|
||||
theme = _opts.themeObj = _loadTheme(tFolder);
|
||||
_addFreebieFormats(theme);
|
||||
} catch (_error) {
|
||||
ex = _error;
|
||||
newEx = {
|
||||
fluenterror: HMSTATUS.themeLoad,
|
||||
inner: ex,
|
||||
inner: _error,
|
||||
attempted: _opts.theme,
|
||||
quit: true
|
||||
};
|
||||
@ -137,7 +136,7 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
this.stat(HMEVENT.afterTheme, {
|
||||
theme: theme
|
||||
});
|
||||
inv = verifyOutputs.call(this, dst, theme);
|
||||
inv = _verifyOutputs.call(this, dst, theme);
|
||||
if (inv && inv.length) {
|
||||
this.err(HMSTATUS.invalidFormat, {
|
||||
data: inv,
|
||||
@ -187,15 +186,28 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
theme: theme
|
||||
});
|
||||
_rezObj = new RTYPES[toFormat]().parseJSON(rez);
|
||||
targets = expand(dst, theme);
|
||||
targets = _expand(dst, theme);
|
||||
_.each(targets, function(t) {
|
||||
return t.final = single.call(this, t, theme, targets);
|
||||
if (this.hasError() && opts.assert) {
|
||||
return {};
|
||||
}
|
||||
t.final = _single.call(this, t, theme, targets);
|
||||
if (t.final.fluenterror) {
|
||||
t.final.quit = opts.assert;
|
||||
this.err(t.final.fluenterror, t.final);
|
||||
}
|
||||
}, this);
|
||||
return {
|
||||
results = {
|
||||
sheet: _rezObj,
|
||||
targets: targets,
|
||||
processed: targets
|
||||
};
|
||||
if (this.hasError() && !opts.assert) {
|
||||
this.reject(results);
|
||||
} else if (!this.hasError()) {
|
||||
this.resolve(results);
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
|
||||
@ -203,7 +215,7 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
Prepare for a BUILD run.
|
||||
*/
|
||||
|
||||
prep = function(src, dst, opts) {
|
||||
_prep = function(src, dst, opts) {
|
||||
_opts.theme = (opts.theme && opts.theme.toLowerCase().trim()) || 'modern';
|
||||
_opts.prettify = opts.prettify === true;
|
||||
_opts.css = opts.css;
|
||||
@ -226,7 +238,7 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
@param theme A FRESHTheme or JRSTheme object.
|
||||
*/
|
||||
|
||||
single = function(targInfo, theme, finished) {
|
||||
_single = function(targInfo, theme, finished) {
|
||||
var e, ex, f, fName, fType, outFolder, ret, theFormat;
|
||||
ret = null;
|
||||
ex = null;
|
||||
@ -268,11 +280,12 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
});
|
||||
if (ex) {
|
||||
if (ex.fluenterror) {
|
||||
this.err(ex.fluenterror, ex);
|
||||
ret = ex;
|
||||
} else {
|
||||
this.err(HMSTATUS.generateError, {
|
||||
ret = {
|
||||
fluenterror: HMSTATUS.generateError,
|
||||
inner: ex
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -281,7 +294,7 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
|
||||
/** Ensure that user-specified outputs/targets are valid. */
|
||||
|
||||
verifyOutputs = function(targets, theme) {
|
||||
_verifyOutputs = function(targets, theme) {
|
||||
this.stat(HMEVENT.verifyOutputs, {
|
||||
targets: targets,
|
||||
theme: theme
|
||||
@ -308,7 +321,7 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
@param theTheme A FRESHTheme or JRSTheme object.
|
||||
*/
|
||||
|
||||
addFreebieFormats = function(theTheme) {
|
||||
_addFreebieFormats = function(theTheme) {
|
||||
theTheme.formats.json = theTheme.formats.json || {
|
||||
freebie: true,
|
||||
title: 'json',
|
||||
@ -347,7 +360,7 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
@param theTheme A FRESHTheme or JRSTheme object.
|
||||
*/
|
||||
|
||||
expand = function(dst, theTheme) {
|
||||
_expand = function(dst, theTheme) {
|
||||
var destColl, targets;
|
||||
destColl = (dst && dst.length && dst) || [PATH.normalize('out/resume.all')];
|
||||
targets = [];
|
||||
@ -378,7 +391,7 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
Verify the specified theme name/path.
|
||||
*/
|
||||
|
||||
verifyTheme = function(themeNameOrPath) {
|
||||
_verifyTheme = function(themeNameOrPath) {
|
||||
var exists, tFolder;
|
||||
tFolder = PATH.join(parsePath(require.resolve('fresh-themes')).dirname, '/themes/', themeNameOrPath);
|
||||
exists = require('path-exists').sync;
|
||||
@ -399,7 +412,7 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
theme.
|
||||
*/
|
||||
|
||||
loadTheme = function(tFolder) {
|
||||
_loadTheme = function(tFolder) {
|
||||
var theTheme;
|
||||
theTheme = _opts.theme.indexOf('jsonresume-theme-') > -1 ? new JRSTheme().open(tFolder) : new FRESHTheme().open(tFolder);
|
||||
_opts.themeObj = theTheme;
|
||||
@ -407,3 +420,5 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
||||
//# sourceMappingURL=build.js.map
|
||||
|
98
dist/verbs/convert.js
vendored
98
dist/verbs/convert.js
vendored
@ -6,7 +6,7 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var ConvertVerb, HMEVENT, HMSTATUS, ResumeFactory, Verb, _, chalk, convert;
|
||||
var ConvertVerb, HMEVENT, HMSTATUS, ResumeFactory, Verb, _, _convert, _convertOne, chalk;
|
||||
|
||||
ResumeFactory = require('../core/resume-factory');
|
||||
|
||||
@ -22,67 +22,87 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
|
||||
ConvertVerb = module.exports = Verb.extend({
|
||||
init: function() {
|
||||
return this._super('convert', convert);
|
||||
return this._super('convert', _convert);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
Convert between FRESH and JRS formats.
|
||||
/** Private workhorse method. Convert 0..N resumes between FRESH and JRS
|
||||
formats.
|
||||
*/
|
||||
|
||||
convert = function(srcs, dst, opts) {
|
||||
_convert = function(srcs, dst, opts) {
|
||||
var results;
|
||||
if (!srcs || !srcs.length) {
|
||||
throw {
|
||||
fluenterror: 6,
|
||||
this.err(HMSTATUS.resumeNotFound, {
|
||||
quit: true
|
||||
};
|
||||
});
|
||||
return null;
|
||||
}
|
||||
if (!dst || !dst.length) {
|
||||
if (srcs.length === 1) {
|
||||
throw {
|
||||
fluenterror: HMSTATUS.inputOutputParity,
|
||||
this.err(HMSTATUS.inputOutputParity, {
|
||||
quit: true
|
||||
};
|
||||
});
|
||||
} else if (srcs.length === 2) {
|
||||
dst = dst || [];
|
||||
dst.push(srcs.pop());
|
||||
} else {
|
||||
throw {
|
||||
fluenterror: HMSTATUS.inputOutputParity,
|
||||
this.err(HMSTATUS.inputOutputParity, {
|
||||
quit: true
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
if (srcs && dst && srcs.length && dst.length && srcs.length !== dst.length) {
|
||||
throw {
|
||||
fluenterror: HMSTATUS.inputOutputParity({
|
||||
quit: true
|
||||
})
|
||||
};
|
||||
this.err(HMSTATUS.inputOutputParity, {
|
||||
quit: true
|
||||
});
|
||||
}
|
||||
_.each(srcs, function(src, idx) {
|
||||
var rinfo, s, srcFmt, targetFormat;
|
||||
rinfo = ResumeFactory.loadOne(src, {
|
||||
format: null,
|
||||
objectify: true,
|
||||
"throw": false
|
||||
});
|
||||
if (rinfo.fluenterror) {
|
||||
this.err(rinfo.fluenterror, rinfo);
|
||||
return;
|
||||
results = _.map(srcs, function(src, idx) {
|
||||
var r;
|
||||
if (opts.assert && this.hasError()) {
|
||||
return {};
|
||||
}
|
||||
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);
|
||||
r = _convertOne.call(this, src, dst, idx);
|
||||
if (r.fluenterror) {
|
||||
r.quit = opts.assert;
|
||||
this.err(r.fluenterror, r);
|
||||
}
|
||||
return r;
|
||||
}, this);
|
||||
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,
|
||||
objectify: true
|
||||
});
|
||||
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;
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
||||
//# sourceMappingURL=convert.js.map
|
||||
|
66
dist/verbs/create.js
vendored
66
dist/verbs/create.js
vendored
@ -6,7 +6,7 @@ Implementation of the 'create' verb for HackMyResume.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var CreateVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, Verb, _, chalk, create;
|
||||
var CreateVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, Verb, _, _create, _createOne, chalk;
|
||||
|
||||
MKDIRP = require('mkdirp');
|
||||
|
||||
@ -24,24 +24,48 @@ Implementation of the 'create' verb for HackMyResume.
|
||||
|
||||
CreateVerb = module.exports = Verb.extend({
|
||||
init: function() {
|
||||
return this._super('new', create);
|
||||
return this._super('new', _create);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
Create a new empty resume in either FRESH or JRS format.
|
||||
*/
|
||||
/** Create a new empty resume in either FRESH or JRS format. */
|
||||
|
||||
create = function(src, dst, opts) {
|
||||
_create = function(src, dst, opts) {
|
||||
var results;
|
||||
if (!src || !src.length) {
|
||||
throw {
|
||||
fluenterror: HMSTATUS.createNameMissing,
|
||||
this.err(HMSTATUS.createNameMissing, {
|
||||
quit: true
|
||||
};
|
||||
});
|
||||
return null;
|
||||
}
|
||||
_.each(src, function(t) {
|
||||
var RezClass, safeFmt;
|
||||
results = _.map(src, function(t) {
|
||||
var r;
|
||||
if (opts.assert && this.hasError()) {
|
||||
return {};
|
||||
}
|
||||
r = _createOne.call(this, t, opts);
|
||||
if (r.fluenterror) {
|
||||
r.quit = opts.assert;
|
||||
this.err(r.fluenterror, r);
|
||||
}
|
||||
return r;
|
||||
}, this);
|
||||
if (this.hasError() && !opts.assert) {
|
||||
this.reject(results);
|
||||
} else if (!this.hasError()) {
|
||||
this.resolve(results);
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
|
||||
/** Create a single new resume */
|
||||
|
||||
_createOne = function(t, opts) {
|
||||
var RezClass, newRez, ret, safeFmt;
|
||||
try {
|
||||
ret = null;
|
||||
safeFmt = opts.format.toUpperCase();
|
||||
this.stat(HMEVENT.beforeCreate, {
|
||||
fmt: safeFmt,
|
||||
@ -49,12 +73,24 @@ Implementation of the 'create' verb for HackMyResume.
|
||||
});
|
||||
MKDIRP.sync(PATH.dirname(t));
|
||||
RezClass = require('../core/' + safeFmt.toLowerCase() + '-resume');
|
||||
RezClass["default"]().save(t);
|
||||
return this.stat(HMEVENT.afterCreate, {
|
||||
newRez = RezClass["default"]();
|
||||
newRez.save(t);
|
||||
ret = newRez;
|
||||
} catch (_error) {
|
||||
ret = {
|
||||
fluenterror: HMSTATUS.createError,
|
||||
inner: _error
|
||||
};
|
||||
} finally {
|
||||
this.stat(HMEVENT.afterCreate, {
|
||||
fmt: safeFmt,
|
||||
file: t
|
||||
file: t,
|
||||
isError: ret.fluenterror
|
||||
});
|
||||
}, this);
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
||||
//# sourceMappingURL=create.js.map
|
||||
|
87
dist/verbs/peek.js
vendored
87
dist/verbs/peek.js
vendored
@ -6,7 +6,7 @@ Implementation of the 'peek' verb for HackMyResume.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var HMEVENT, HMSTATUS, PeekVerb, Verb, _, __, peek, safeLoadJSON;
|
||||
var HMEVENT, HMSTATUS, PeekVerb, Verb, _, __, _peek, _peekOne, safeLoadJSON;
|
||||
|
||||
Verb = require('../verbs/verb');
|
||||
|
||||
@ -22,49 +22,74 @@ Implementation of the 'peek' verb for HackMyResume.
|
||||
|
||||
PeekVerb = module.exports = Verb.extend({
|
||||
init: function() {
|
||||
return this._super('peek', peek);
|
||||
return this._super('peek', _peek);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/** Peek at a resume, resume section, or resume field. */
|
||||
|
||||
peek = function(src, dst, opts) {
|
||||
var objPath;
|
||||
_peek = function(src, dst, opts) {
|
||||
var objPath, results;
|
||||
if (!src || !src.length) {
|
||||
({
|
||||
"throw": {
|
||||
fluenterror: HMSTATUS.resumeNotFound
|
||||
}
|
||||
this.err(HMSTATUS.resumeNotFound, {
|
||||
quit: true
|
||||
});
|
||||
return null;
|
||||
}
|
||||
objPath = (dst && dst[0]) || '';
|
||||
_.each(src, function(t) {
|
||||
var errCode, obj, tgt;
|
||||
this.stat(HMEVENT.beforePeek, {
|
||||
file: t,
|
||||
target: objPath
|
||||
});
|
||||
obj = safeLoadJSON(t);
|
||||
tgt = null;
|
||||
if (!obj.ex) {
|
||||
tgt = objPath ? __.get(obj.json, objPath) : obj.json;
|
||||
results = _.map(src, function(t) {
|
||||
var tgt;
|
||||
if (opts.assert && this.hasError()) {
|
||||
return {};
|
||||
}
|
||||
this.stat(HMEVENT.afterPeek, {
|
||||
file: t,
|
||||
requested: objPath,
|
||||
target: tgt,
|
||||
error: obj.ex
|
||||
});
|
||||
if (obj.ex) {
|
||||
errCode = obj.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError;
|
||||
if (errCode === HMSTATUS.readError) {
|
||||
obj.ex.quiet = true;
|
||||
}
|
||||
this.setError(errCode, obj.ex);
|
||||
return this.err(errCode, obj.ex);
|
||||
tgt = _peekOne.call(this, t, objPath);
|
||||
if (tgt.fluenterror) {
|
||||
tgt.quit = opts.assert;
|
||||
return this.err(tgt.fluenterror, tgt);
|
||||
}
|
||||
}, this);
|
||||
if (this.hasError() && !opts.assert) {
|
||||
this.reject(this.errorCode);
|
||||
} else if (!this.hasError()) {
|
||||
this.resolve(results);
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
|
||||
/** Peek at a single resume, resume section, or resume field. */
|
||||
|
||||
_peekOne = function(t, objPath) {
|
||||
var errCode, obj, tgt;
|
||||
this.stat(HMEVENT.beforePeek, {
|
||||
file: t,
|
||||
target: objPath
|
||||
});
|
||||
obj = safeLoadJSON(t);
|
||||
tgt = null;
|
||||
if (!obj.ex) {
|
||||
tgt = objPath ? __.get(obj.json, objPath) : obj.json;
|
||||
}
|
||||
this.stat(HMEVENT.afterPeek, {
|
||||
file: t,
|
||||
requested: objPath,
|
||||
target: tgt,
|
||||
error: obj.ex
|
||||
});
|
||||
if (obj.ex) {
|
||||
errCode = obj.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError;
|
||||
if (errCode === HMSTATUS.readError) {
|
||||
obj.ex.quiet = true;
|
||||
}
|
||||
return {
|
||||
fluenterror: errCode,
|
||||
inner: obj.ex
|
||||
};
|
||||
}
|
||||
return tgt;
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
||||
//# sourceMappingURL=peek.js.map
|
||||
|
123
dist/verbs/validate.js
vendored
123
dist/verbs/validate.js
vendored
@ -6,7 +6,7 @@ Implementation of the 'validate' verb for HackMyResume.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var FS, HMEVENT, HMSTATUS, ResumeFactory, SyntaxErrorEx, ValidateVerb, Verb, _, chalk, safeLoadJSON, validate;
|
||||
var FS, HMEVENT, HMSTATUS, ResumeFactory, SyntaxErrorEx, ValidateVerb, Verb, _, _validate, _validateOne, chalk, safeLoadJSON;
|
||||
|
||||
FS = require('fs');
|
||||
|
||||
@ -31,72 +31,95 @@ Implementation of the 'validate' verb for HackMyResume.
|
||||
|
||||
ValidateVerb = module.exports = Verb.extend({
|
||||
init: function() {
|
||||
return this._super('validate', validate);
|
||||
return this._super('validate', _validate);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/** Validate 1 to N resumes in FRESH or JSON Resume format. */
|
||||
|
||||
validate = function(sources, unused, opts) {
|
||||
var schemas, validator;
|
||||
_validate = function(sources, unused, opts) {
|
||||
var results, schemas, validator;
|
||||
if (!sources || !sources.length) {
|
||||
throw {
|
||||
fluenterror: HMSTATUS.resumeNotFoundAlt,
|
||||
this.err(HMSTATUS.resumeNotFoundAlt, {
|
||||
quit: true
|
||||
};
|
||||
});
|
||||
return null;
|
||||
}
|
||||
validator = require('is-my-json-valid');
|
||||
schemas = {
|
||||
fresh: require('fresca'),
|
||||
jars: require('../core/resume.json')
|
||||
};
|
||||
return _.map(sources, function(t) {
|
||||
var errCode, errors, fmt, json, obj, ret;
|
||||
ret = {
|
||||
file: t,
|
||||
isValid: false
|
||||
};
|
||||
obj = safeLoadJSON(t);
|
||||
if (!obj.ex) {
|
||||
json = obj.json;
|
||||
fmt = json.basics ? 'jrs' : 'fresh';
|
||||
errors = [];
|
||||
try {
|
||||
validate = validator(schemas[fmt], {
|
||||
formats: {
|
||||
date: /^\d{4}(?:-(?:0[0-9]{1}|1[0-2]{1})(?:-[0-9]{2})?)?$/
|
||||
}
|
||||
});
|
||||
ret.isValid = validate(json);
|
||||
if (!ret.isValid) {
|
||||
errors = validate.errors;
|
||||
}
|
||||
} catch (_error) {
|
||||
ret.ex = _error;
|
||||
}
|
||||
} else {
|
||||
errCode = obj.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError;
|
||||
if (errCode === HMSTATUS.readError) {
|
||||
obj.ex.quiet = true;
|
||||
}
|
||||
this.setError(errCode, obj.ex);
|
||||
this.err(errCode, obj.ex);
|
||||
results = _.map(sources, function(t) {
|
||||
var r;
|
||||
if (this.hasError() && opts.assert) {
|
||||
return {};
|
||||
}
|
||||
this.stat(HMEVENT.afterValidate, {
|
||||
file: t,
|
||||
isValid: ret.isValid,
|
||||
fmt: fmt != null ? fmt.replace('jars', 'JSON Resume') : void 0,
|
||||
errors: errors
|
||||
});
|
||||
if (opts.assert && !ret.isValid) {
|
||||
throw {
|
||||
fluenterror: HMSTATUS.invalid,
|
||||
shouldExit: true
|
||||
};
|
||||
r = _validateOne.call(this, t, validator, schemas);
|
||||
if (r.fluenterror) {
|
||||
console.log(r);
|
||||
r.quit = opts.assert;
|
||||
this.err(r.fluenterror, r);
|
||||
}
|
||||
return ret;
|
||||
return r;
|
||||
}, this);
|
||||
if (this.hasError() && !opts.assert) {
|
||||
this.reject(this.errorCode);
|
||||
} else if (!this.hasError()) {
|
||||
this.resolve(results);
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
_validateOne = function(t, validator, schemas) {
|
||||
var errCode, errors, fmt, json, obj, ret, validate;
|
||||
ret = {
|
||||
file: t,
|
||||
isValid: false
|
||||
};
|
||||
obj = safeLoadJSON(t);
|
||||
if (obj.ex) {
|
||||
errCode = obj.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError;
|
||||
if (errCode === HMSTATUS.readError) {
|
||||
obj.ex.quiet = true;
|
||||
}
|
||||
return {
|
||||
fluenterror: errCode,
|
||||
inner: obj.ex
|
||||
};
|
||||
}
|
||||
json = obj.json;
|
||||
fmt = json.basics ? 'jrs' : 'fresh';
|
||||
errors = [];
|
||||
try {
|
||||
validate = validator(schemas[fmt], {
|
||||
formats: {
|
||||
date: /^\d{4}(?:-(?:0[0-9]{1}|1[0-2]{1})(?:-[0-9]{2})?)?$/
|
||||
}
|
||||
});
|
||||
ret.isValid = validate(json);
|
||||
if (!ret.isValid) {
|
||||
errors = validate.errors;
|
||||
}
|
||||
} catch (_error) {
|
||||
ret.ex = _error;
|
||||
}
|
||||
this.stat(HMEVENT.afterValidate, {
|
||||
file: t,
|
||||
isValid: ret.isValid,
|
||||
fmt: fmt != null ? fmt.replace('jars', 'JSON Resume') : void 0,
|
||||
errors: errors
|
||||
});
|
||||
if (opts.assert && !ret.isValid) {
|
||||
return {
|
||||
fluenterror: HMSTATUS.invalid,
|
||||
errors: errors
|
||||
};
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
||||
//# sourceMappingURL=validate.js.map
|
||||
|
27
dist/verbs/verb.js
vendored
27
dist/verbs/verb.js
vendored
@ -6,7 +6,7 @@ Definition of the Verb class.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var Class, EVENTS, HMEVENT, Verb;
|
||||
var Class, EVENTS, HMEVENT, Promise, Verb;
|
||||
|
||||
Class = require('../utils/class');
|
||||
|
||||
@ -14,6 +14,8 @@ Definition of the Verb class.
|
||||
|
||||
HMEVENT = require('../core/event-codes');
|
||||
|
||||
Promise = require('pinkie-promise');
|
||||
|
||||
|
||||
/**
|
||||
An instantiation of a HackMyResume command.
|
||||
@ -25,19 +27,23 @@ Definition of the Verb class.
|
||||
/** Constructor. Automatically called at creation. */
|
||||
init: function(moniker, workhorse) {
|
||||
this.moniker = moniker;
|
||||
this.emitter = new EVENTS.EventEmitter();
|
||||
this.workhorse = workhorse;
|
||||
this.emitter = new EVENTS.EventEmitter();
|
||||
},
|
||||
|
||||
/** Invoke the command. */
|
||||
invoke: function() {
|
||||
var ret;
|
||||
var argsArray, that;
|
||||
this.stat(HMEVENT.begin, {
|
||||
cmd: this.moniker
|
||||
});
|
||||
ret = this.workhorse.apply(this, arguments);
|
||||
this.stat(HMEVENT.end);
|
||||
return ret;
|
||||
argsArray = Array.prototype.slice.call(arguments);
|
||||
that = this;
|
||||
return this.promise = new Promise(function(res, rej) {
|
||||
that.resolve = res;
|
||||
that.reject = rej;
|
||||
that.workhorse.apply(that, argsArray);
|
||||
});
|
||||
},
|
||||
|
||||
/** Forward subscriptions to the event emitter. */
|
||||
@ -58,6 +64,10 @@ Definition of the Verb class.
|
||||
payload = payload || {};
|
||||
payload.sub = payload.fluenterror = errorCode;
|
||||
payload["throw"] = hot;
|
||||
this.setError(errorCode, payload);
|
||||
if (payload.quit) {
|
||||
this.reject(payload);
|
||||
}
|
||||
this.fire('error', payload);
|
||||
if (hot) {
|
||||
throw payload;
|
||||
@ -72,6 +82,9 @@ Definition of the Verb class.
|
||||
this.fire('status', payload);
|
||||
return true;
|
||||
},
|
||||
hasError: function() {
|
||||
return this.errorCode || this.errorObj;
|
||||
},
|
||||
|
||||
/** Associate error info with the invocation. */
|
||||
setError: function(code, obj) {
|
||||
@ -81,3 +94,5 @@ Definition of the Verb class.
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
|
||||
//# sourceMappingURL=verb.js.map
|
||||
|
Reference in New Issue
Block a user