mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-06 06:17:07 +01:00
chore: update project dependencies
This commit is contained in:
40
dist/verbs/analyze.js
vendored
40
dist/verbs/analyze.js
vendored
@ -1,14 +1,12 @@
|
||||
|
||||
/**
|
||||
Implementation of the 'analyze' verb for HackMyResume.
|
||||
@module verbs/analyze
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var AnalyzeVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, ResumeFactory, Verb, _, _analyze, _analyzeOne, _loadInspectors, 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;
|
||||
/**
|
||||
Implementation of the 'analyze' verb for HackMyResume.
|
||||
@module verbs/analyze
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
/** Private workhorse for the 'analyze' command. */
|
||||
/** Analyze a single resume. */
|
||||
var AnalyzeVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, ResumeFactory, Verb, _, _analyze, _analyzeOne, _loadInspectors, chalk;
|
||||
|
||||
MKDIRP = require('mkdirp');
|
||||
|
||||
@ -26,22 +24,13 @@ Implementation of the 'analyze' verb for HackMyResume.
|
||||
|
||||
chalk = require('chalk');
|
||||
|
||||
|
||||
/** An invokable resume analysis command. */
|
||||
|
||||
module.exports = AnalyzeVerb = (function(superClass) {
|
||||
extend(AnalyzeVerb, superClass);
|
||||
|
||||
function AnalyzeVerb() {
|
||||
AnalyzeVerb.__super__.constructor.call(this, 'analyze', _analyze);
|
||||
module.exports = AnalyzeVerb = class AnalyzeVerb extends Verb {
|
||||
constructor() {
|
||||
super('analyze', _analyze);
|
||||
}
|
||||
|
||||
return AnalyzeVerb;
|
||||
|
||||
})(Verb);
|
||||
|
||||
|
||||
/** Private workhorse for the 'analyze' command. */
|
||||
};
|
||||
|
||||
_analyze = function(sources, dst, opts) {
|
||||
var nlzrs, results;
|
||||
@ -58,7 +47,7 @@ Implementation of the 'analyze' verb for HackMyResume.
|
||||
format: 'FRESH',
|
||||
objectify: true,
|
||||
inner: {
|
||||
"private": opts["private"] === true
|
||||
private: opts.private === true
|
||||
}
|
||||
}, this);
|
||||
if (opts.assert && this.hasError()) {
|
||||
@ -80,9 +69,6 @@ Implementation of the 'analyze' verb for HackMyResume.
|
||||
return results;
|
||||
};
|
||||
|
||||
|
||||
/** Analyze a single resume. */
|
||||
|
||||
_analyzeOne = function(resumeObject, nlzrs, opts) {
|
||||
var info, rez, safeFormat;
|
||||
rez = resumeObject.rez;
|
||||
|
199
dist/verbs/build.js
vendored
199
dist/verbs/build.js
vendored
@ -1,14 +1,49 @@
|
||||
|
||||
/**
|
||||
Implementation of the 'build' verb for HackMyResume.
|
||||
@module verbs/build
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
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,
|
||||
extend1 = 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;
|
||||
/**
|
||||
Implementation of the 'build' verb for HackMyResume.
|
||||
@module verbs/build
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
/**
|
||||
Reinforce the chosen theme with "freebie" formats provided by HackMyResume.
|
||||
A "freebie" format is an output format such as JSON, YML, or PNG that can be
|
||||
generated directly from the resume model or from one of the theme's declared
|
||||
output formats. For example, the PNG format can be generated for any theme
|
||||
that declares an HTML format; the theme doesn't have to provide an explicit
|
||||
PNG template.
|
||||
@param theTheme A FRESHTheme or JRSTheme object.
|
||||
*/
|
||||
/**
|
||||
Given a source resume in FRESH or JRS format, a destination resume path, and a
|
||||
theme file, generate 0..N resumes in the desired formats.
|
||||
@param src Path to the source JSON resume file: "rez/resume.json".
|
||||
@param dst An array of paths to the target resume file(s).
|
||||
@param opts Generation options.
|
||||
*/
|
||||
/**
|
||||
Expand output files. For example, "foo.all" should be expanded to
|
||||
["foo.html", "foo.doc", "foo.pdf", "etc"].
|
||||
@param dst An array of output files as specified by the user.
|
||||
@param theTheme A FRESHTheme or JRSTheme object.
|
||||
*/
|
||||
/**
|
||||
Load the specified theme, which could be either a FRESH theme or a JSON Resume
|
||||
theme (or both).
|
||||
*/
|
||||
/**
|
||||
Prepare for a BUILD run.
|
||||
*/
|
||||
/**
|
||||
Generate a single target resume such as "out/rez.html" or "out/rez.doc".
|
||||
TODO: Refactor.
|
||||
@param targInfo Information for the target resume.
|
||||
@param theme A FRESHTheme or JRSTheme object.
|
||||
*/
|
||||
/** Ensure that user-specified outputs/targets are valid. */
|
||||
/**
|
||||
Verify the specified theme name/path.
|
||||
*/
|
||||
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');
|
||||
|
||||
@ -69,34 +104,17 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
|
||||
loadTheme = null;
|
||||
|
||||
|
||||
/** An invokable resume generation command. */
|
||||
|
||||
module.exports = BuildVerb = (function(superClass) {
|
||||
extend1(BuildVerb, superClass);
|
||||
|
||||
|
||||
module.exports = BuildVerb = class BuildVerb extends Verb {
|
||||
/** Create a new build verb. */
|
||||
|
||||
function BuildVerb() {
|
||||
BuildVerb.__super__.constructor.call(this, 'build', _build);
|
||||
constructor() {
|
||||
super('build', _build);
|
||||
}
|
||||
|
||||
return BuildVerb;
|
||||
|
||||
})(Verb);
|
||||
|
||||
|
||||
/**
|
||||
Given a source resume in FRESH or JRS format, a destination resume path, and a
|
||||
theme file, generate 0..N resumes in the desired formats.
|
||||
@param src Path to the source JSON resume file: "rez/resume.json".
|
||||
@param dst An array of paths to the target resume file(s).
|
||||
@param opts Generation options.
|
||||
*/
|
||||
};
|
||||
|
||||
_build = function(src, dst, opts) {
|
||||
var inv, isFRESH, mixed, newEx, orgFormat, problemSheets, results, rez, sheetObjects, sheets, tFolder, targets, theme, toFormat;
|
||||
var err, inv, isFRESH, mixed, newEx, orgFormat, problemSheets, results, rez, sheetObjects, sheets, tFolder, targets, theme, toFormat;
|
||||
if (!src || !src.length) {
|
||||
this.err(HMSTATUS.resumeNotFound, {
|
||||
quit: true
|
||||
@ -104,26 +122,30 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
return null;
|
||||
}
|
||||
_prep.call(this, src, dst, opts);
|
||||
// Load input resumes as JSON...
|
||||
sheetObjects = ResumeFactory.load(src, {
|
||||
format: null,
|
||||
objectify: false,
|
||||
quit: true,
|
||||
inner: {
|
||||
sort: _opts.sort,
|
||||
"private": _opts["private"]
|
||||
private: _opts.private
|
||||
}
|
||||
}, this);
|
||||
// Explicit check for any resume loading errors...
|
||||
problemSheets = _.filter(sheetObjects, function(so) {
|
||||
return so.fluenterror;
|
||||
});
|
||||
if (problemSheets && problemSheets.length) {
|
||||
problemSheets[0].quit = true;
|
||||
problemSheets[0].quit = true; // can't go on
|
||||
this.err(problemSheets[0].fluenterror, problemSheets[0]);
|
||||
return null;
|
||||
}
|
||||
// Get the collection of raw JSON sheets
|
||||
sheets = sheetObjects.map(function(r) {
|
||||
return r.json;
|
||||
});
|
||||
// Load the theme...
|
||||
theme = null;
|
||||
this.stat(HMEVENT.beforeTheme, {
|
||||
theme: _opts.theme
|
||||
@ -137,10 +159,11 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
}
|
||||
theme = _opts.themeObj = _loadTheme(tFolder);
|
||||
_addFreebieFormats(theme);
|
||||
} catch (_error) {
|
||||
} catch (error) {
|
||||
err = error;
|
||||
newEx = {
|
||||
fluenterror: HMSTATUS.themeLoad,
|
||||
inner: _error,
|
||||
inner: err,
|
||||
attempted: _opts.theme,
|
||||
quit: true
|
||||
};
|
||||
@ -150,6 +173,7 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
this.stat(HMEVENT.afterTheme, {
|
||||
theme: theme
|
||||
});
|
||||
// Check for invalid outputs...
|
||||
inv = _verifyOutputs.call(this, dst, theme);
|
||||
if (inv && inv.length) {
|
||||
this.err(HMSTATUS.invalidFormat, {
|
||||
@ -159,6 +183,7 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
});
|
||||
return null;
|
||||
}
|
||||
//# Merge input resumes, yielding a single source resume...
|
||||
rez = null;
|
||||
if (sheets.length > 1) {
|
||||
isFRESH = !sheets[0].basics;
|
||||
@ -195,14 +220,17 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
fmt: toFormat
|
||||
});
|
||||
}
|
||||
// Announce the theme
|
||||
this.stat(HMEVENT.applyTheme, {
|
||||
r: rez,
|
||||
theme: theme
|
||||
});
|
||||
// Load the resume into a FRESHResume or JRSResume object
|
||||
_rezObj = new RTYPES[toFormat]().parseJSON(rez, {
|
||||
"private": _opts["private"]
|
||||
private: _opts.private
|
||||
});
|
||||
targets = _expand(dst, theme);
|
||||
// Run the transformation!
|
||||
_.each(targets, function(t) {
|
||||
var ref;
|
||||
if (this.hasError() && opts.assert) {
|
||||
@ -227,16 +255,12 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
return results;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Prepare for a BUILD run.
|
||||
*/
|
||||
|
||||
_prep = function(src, dst, opts) {
|
||||
var that;
|
||||
// Cherry-pick options //_opts = extend( true, _opts, opts );
|
||||
_opts.theme = (opts.theme && opts.theme.toLowerCase().trim()) || 'modern';
|
||||
_opts.prettify = opts.prettify === true;
|
||||
_opts["private"] = opts["private"] === true;
|
||||
_opts.private = opts.private === true;
|
||||
_opts.noescape = opts.noescape === true;
|
||||
_opts.css = opts.css;
|
||||
_opts.pdf = opts.pdf;
|
||||
@ -249,6 +273,7 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
_opts.sort = opts.sort;
|
||||
_opts.wkhtmltopdf = opts.wkhtmltopdf;
|
||||
that = this;
|
||||
// Set up callbacks for internal generators
|
||||
_opts.onTransform = function(info) {
|
||||
that.stat(HMEVENT.afterTransform, info);
|
||||
};
|
||||
@ -258,17 +283,11 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
_opts.afterWrite = function(info) {
|
||||
that.stat(HMEVENT.afterWrite, info);
|
||||
};
|
||||
// If two or more files are passed to the GENERATE command and the TO
|
||||
// keyword is omitted, the last file specifies the output file.
|
||||
(src.length > 1 && (!dst || !dst.length)) && dst.push(src.pop());
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Generate a single target resume such as "out/rez.html" or "out/rez.doc".
|
||||
TODO: Refactor.
|
||||
@param targInfo Information for the target resume.
|
||||
@param theme A FRESHTheme or JRSTheme object.
|
||||
*/
|
||||
|
||||
_single = function(targInfo, theme, finished) {
|
||||
var e, ex, f, fName, fType, outFolder, ret, theFormat;
|
||||
ret = null;
|
||||
@ -286,6 +305,8 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
file: PATH.relative(process.cwd(), f)
|
||||
});
|
||||
_opts.targets = finished;
|
||||
// If targInfo.fmt.files exists, this format is backed by a document.
|
||||
// Fluent/FRESH themes are handled here.
|
||||
if (targInfo.fmt.files && targInfo.fmt.files.length) {
|
||||
theFormat = _fmts.filter(function(fmt) {
|
||||
return fmt.name === targInfo.fmt.outFormat;
|
||||
@ -293,15 +314,17 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
MKDIRP.sync(PATH.dirname(f));
|
||||
ret = theFormat.gen.generate(_rezObj, f, _opts);
|
||||
} else {
|
||||
// Otherwise this is an ad-hoc format (JSON, YML, or PNG) that every theme
|
||||
// gets "for free".
|
||||
theFormat = _fmts.filter(function(fmt) {
|
||||
return fmt.name === targInfo.fmt.outFormat;
|
||||
})[0];
|
||||
outFolder = PATH.dirname(f);
|
||||
MKDIRP.sync(outFolder);
|
||||
MKDIRP.sync(outFolder); // Ensure dest folder exists;
|
||||
ret = theFormat.gen.generate(_rezObj, f, _opts);
|
||||
}
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
} catch (error) {
|
||||
e = error;
|
||||
ex = e;
|
||||
}
|
||||
this.stat(HMEVENT.afterGenerate, {
|
||||
@ -322,9 +345,6 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
/** Ensure that user-specified outputs/targets are valid. */
|
||||
|
||||
_verifyOutputs = function(targets, theme) {
|
||||
this.stat(HMEVENT.verifyOutputs, {
|
||||
targets: targets,
|
||||
@ -341,18 +361,9 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Reinforce the chosen theme with "freebie" formats provided by HackMyResume.
|
||||
A "freebie" format is an output format such as JSON, YML, or PNG that can be
|
||||
generated directly from the resume model or from one of the theme's declared
|
||||
output formats. For example, the PNG format can be generated for any theme
|
||||
that declares an HTML format; the theme doesn't have to provide an explicit
|
||||
PNG template.
|
||||
@param theTheme A FRESHTheme or JRSTheme object.
|
||||
*/
|
||||
|
||||
_addFreebieFormats = function(theTheme) {
|
||||
// Add freebie formats (JSON, YAML, PNG) every theme gets...
|
||||
// Add HTML-driven PNG only if the theme has an HTML format.
|
||||
theTheme.formats.json = theTheme.formats.json || {
|
||||
freebie: true,
|
||||
title: 'json',
|
||||
@ -383,16 +394,10 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Expand output files. For example, "foo.all" should be expanded to
|
||||
["foo.html", "foo.doc", "foo.pdf", "etc"].
|
||||
@param dst An array of output files as specified by the user.
|
||||
@param theTheme A FRESHTheme or JRSTheme object.
|
||||
*/
|
||||
|
||||
_expand = function(dst, theTheme) {
|
||||
var destColl, targets;
|
||||
// Set up the destination collection. It's either the array of files passed
|
||||
// by the user or 'out/resume.all' if no targets were specified.
|
||||
destColl = (dst && dst.length && dst) || [PATH.normalize('out/resume.all')];
|
||||
targets = [];
|
||||
destColl.forEach(function(t) {
|
||||
@ -417,19 +422,22 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
return targets;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Verify the specified theme name/path.
|
||||
*/
|
||||
|
||||
_verifyTheme = function(themeNameOrPath) {
|
||||
var exists, tFolder, themesObj;
|
||||
// First, see if this is one of the predefined FRESH themes. There are only a
|
||||
// handful of these, but they may change over time, so we need to query
|
||||
// the official source of truth: the fresh-themes repository, which mounts the
|
||||
// themes conveniently by name to the module object, and which is embedded
|
||||
// locally inside the HackMyResume installation.
|
||||
themesObj = require('fresh-themes');
|
||||
if (_.has(themesObj.themes, themeNameOrPath)) {
|
||||
tFolder = PATH.join(parsePath(require.resolve('fresh-themes')).dirname, '/themes/', themeNameOrPath);
|
||||
} else {
|
||||
// Otherwsie it's a path to an arbitrary FRESH or JRS theme sitting somewhere
|
||||
// on the user's system (or, in the future, at a URI).
|
||||
tFolder = PATH.resolve(themeNameOrPath);
|
||||
}
|
||||
// In either case, make sure the theme folder exists
|
||||
exists = require('path-exists').sync;
|
||||
if (exists(tFolder)) {
|
||||
return tFolder;
|
||||
@ -441,21 +449,36 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Load the specified theme, which could be either a FRESH theme or a JSON Resume
|
||||
theme (or both).
|
||||
*/
|
||||
|
||||
_loadTheme = function(tFolder) {
|
||||
var exists, theTheme, themeJsonPath;
|
||||
themeJsonPath = PATH.join(tFolder, 'theme.json');
|
||||
themeJsonPath = PATH.join(tFolder, 'theme.json'); // [^1]
|
||||
exists = require('path-exists').sync;
|
||||
// Create a FRESH or JRS theme object
|
||||
theTheme = exists(themeJsonPath) ? new FRESHTheme().open(tFolder) : new JRSTheme().open(tFolder);
|
||||
// Cache the theme object
|
||||
_opts.themeObj = theTheme;
|
||||
return theTheme;
|
||||
};
|
||||
|
||||
// FOOTNOTES
|
||||
// ------------------------------------------------------------------------------
|
||||
// [^1] We don't know ahead of time whether this is a FRESH or JRS theme.
|
||||
// However, all FRESH themes have a theme.json file, so we'll use that as a
|
||||
// canary for now, as an interim solution.
|
||||
|
||||
// Unfortunately, with the exception of FRESH's theme.json, both FRESH and
|
||||
// JRS themes are free-form and don't have a ton of reliable distinguishing
|
||||
// marks, which makes a simple task like ad hoc theme detection harder than
|
||||
// it should be to do cleanly.
|
||||
|
||||
// Another complicating factor is that it's possible for a theme to be BOTH.
|
||||
// That is, a single set of theme files can serve as a FRESH theme -and- a
|
||||
// JRS theme.
|
||||
|
||||
// TODO: The most robust way to deal with all these issues is with a strong
|
||||
// theme validator. If a theme structure validates as a particular theme
|
||||
// type, then for all intents and purposes, it IS a theme of that type.
|
||||
|
||||
}).call(this);
|
||||
|
||||
//# sourceMappingURL=build.js.map
|
||||
|
71
dist/verbs/convert.js
vendored
71
dist/verbs/convert.js
vendored
@ -1,14 +1,13 @@
|
||||
|
||||
/**
|
||||
Implementation of the 'convert' verb for HackMyResume.
|
||||
@module verbs/convert
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
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;
|
||||
/**
|
||||
Implementation of the 'convert' verb for HackMyResume.
|
||||
@module verbs/convert
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
/** Private workhorse method. Convert 0..N resumes between FRESH and JRS
|
||||
formats. */
|
||||
/** Private workhorse method. Convert a single resume. */
|
||||
var ConvertVerb, HMEVENT, HMSTATUS, ResumeFactory, Verb, _, _convert, _convertOne, chalk;
|
||||
|
||||
ResumeFactory = require('../core/resume-factory');
|
||||
|
||||
@ -22,21 +21,12 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
|
||||
HMEVENT = require('../core/event-codes');
|
||||
|
||||
module.exports = ConvertVerb = (function(superClass) {
|
||||
extend(ConvertVerb, superClass);
|
||||
|
||||
function ConvertVerb() {
|
||||
ConvertVerb.__super__.constructor.call(this, 'convert', _convert);
|
||||
module.exports = ConvertVerb = class ConvertVerb extends Verb {
|
||||
constructor() {
|
||||
super('convert', _convert);
|
||||
}
|
||||
|
||||
return ConvertVerb;
|
||||
|
||||
})(Verb);
|
||||
|
||||
|
||||
/** Private workhorse method. Convert 0..N resumes between FRESH and JRS
|
||||
formats.
|
||||
*/
|
||||
};
|
||||
|
||||
_convert = function(srcs, dst, opts) {
|
||||
var fmtUp, results, targetVer;
|
||||
@ -60,11 +50,13 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
});
|
||||
}
|
||||
}
|
||||
// Different number of source and dest resumes? Error out.
|
||||
if (srcs && dst && srcs.length && dst.length && srcs.length !== dst.length) {
|
||||
this.err(HMSTATUS.inputOutputParity, {
|
||||
quit: true
|
||||
});
|
||||
}
|
||||
// Validate the destination format (if specified)
|
||||
targetVer = null;
|
||||
if (opts.format) {
|
||||
fmtUp = opts.format.trim().toUpperCase();
|
||||
@ -75,13 +67,27 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
});
|
||||
}
|
||||
}
|
||||
// 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 (this.hasError()) {
|
||||
this.reject(this.errorCode);
|
||||
return null;
|
||||
}
|
||||
// Map each source resume to the converted destination resume
|
||||
results = _.map(srcs, function(src, idx) {
|
||||
var r;
|
||||
// Convert each resume in turn
|
||||
r = _convertOne.call(this, src, dst, idx, fmtUp);
|
||||
// Handle conversion errors
|
||||
if (r.fluenterror) {
|
||||
r.quit = opts.assert;
|
||||
this.err(r.fluenterror, r);
|
||||
@ -96,11 +102,9 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
return results;
|
||||
};
|
||||
|
||||
|
||||
/** Private workhorse method. Convert a single resume. */
|
||||
|
||||
_convertOne = function(src, dst, idx, targetSchema) {
|
||||
var err, rez, rinfo, srcFmt, targetFormat;
|
||||
// Load the resume
|
||||
rinfo = ResumeFactory.loadOne(src, {
|
||||
format: null,
|
||||
objectify: true,
|
||||
@ -108,19 +112,23 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
privatize: false
|
||||
}
|
||||
});
|
||||
// If a load error occurs, report it and move on to the next file (if any)
|
||||
if (rinfo.fluenterror) {
|
||||
this.stat(HMEVENT.beforeConvert, {
|
||||
srcFile: src,
|
||||
srcFile: src, //rinfo.file
|
||||
srcFmt: '???',
|
||||
dstFile: dst[idx],
|
||||
dstFmt: '???',
|
||||
error: true
|
||||
});
|
||||
//@err rinfo.fluenterror, rinfo
|
||||
return rinfo;
|
||||
}
|
||||
// Determine the resume's SOURCE format
|
||||
// TODO: replace with detector component
|
||||
rez = rinfo.rez;
|
||||
srcFmt = '';
|
||||
if (rez.meta && rez.meta.format) {
|
||||
if (rez.meta && rez.meta.format) { //&& rez.meta.format.substr(0, 5).toUpperCase() == 'FRESH'
|
||||
srcFmt = 'FRESH';
|
||||
} else if (rez.basics) {
|
||||
srcFmt = 'JRS';
|
||||
@ -128,7 +136,9 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
rinfo.fluenterror = HMSTATUS.unknownSchema;
|
||||
return rinfo;
|
||||
}
|
||||
// Determine the TARGET format for the conversion
|
||||
targetFormat = targetSchema || (srcFmt === 'JRS' ? 'FRESH' : 'JRS');
|
||||
// Fire the beforeConvert event
|
||||
this.stat(HMEVENT.beforeConvert, {
|
||||
srcFile: rinfo.file,
|
||||
srcFmt: srcFmt,
|
||||
@ -136,9 +146,10 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
dstFmt: targetFormat
|
||||
});
|
||||
try {
|
||||
// Save it to the destination format
|
||||
rez.saveAs(dst[idx], targetFormat);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
} catch (error) {
|
||||
err = error;
|
||||
if (err.badVer) {
|
||||
return {
|
||||
fluenterror: HMSTATUS.invalidSchemaVersion,
|
||||
|
47
dist/verbs/create.js
vendored
47
dist/verbs/create.js
vendored
@ -1,14 +1,12 @@
|
||||
|
||||
/**
|
||||
Implementation of the 'create' verb for HackMyResume.
|
||||
@module verbs/create
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var CreateVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, Verb, _, _create, _createOne, 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;
|
||||
/**
|
||||
Implementation of the 'create' verb for HackMyResume.
|
||||
@module verbs/create
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
/** Create a new empty resume in either FRESH or JRS format. */
|
||||
/** Create a single new resume */
|
||||
var CreateVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, Verb, _, _create, _createOne, chalk;
|
||||
|
||||
MKDIRP = require('mkdirp');
|
||||
|
||||
@ -24,19 +22,12 @@ Implementation of the 'create' verb for HackMyResume.
|
||||
|
||||
HMEVENT = require('../core/event-codes');
|
||||
|
||||
module.exports = CreateVerb = (function(superClass) {
|
||||
extend(CreateVerb, superClass);
|
||||
|
||||
function CreateVerb() {
|
||||
CreateVerb.__super__.constructor.call(this, 'new', _create);
|
||||
module.exports = CreateVerb = class CreateVerb extends Verb {
|
||||
constructor() {
|
||||
super('new', _create);
|
||||
}
|
||||
|
||||
return CreateVerb;
|
||||
|
||||
})(Verb);
|
||||
|
||||
|
||||
/** Create a new empty resume in either FRESH or JRS format. */
|
||||
};
|
||||
|
||||
_create = function(src, dst, opts) {
|
||||
var results;
|
||||
@ -66,11 +57,8 @@ Implementation of the 'create' verb for HackMyResume.
|
||||
return results;
|
||||
};
|
||||
|
||||
|
||||
/** Create a single new resume */
|
||||
|
||||
_createOne = function(t, opts) {
|
||||
var RezClass, newRez, ret, safeFmt;
|
||||
var RezClass, err, newRez, ret, safeFmt;
|
||||
try {
|
||||
ret = null;
|
||||
safeFmt = opts.format.toUpperCase();
|
||||
@ -78,15 +66,16 @@ Implementation of the 'create' verb for HackMyResume.
|
||||
fmt: safeFmt,
|
||||
file: t
|
||||
});
|
||||
MKDIRP.sync(PATH.dirname(t));
|
||||
MKDIRP.sync(PATH.dirname(t)); // Ensure dest folder exists;
|
||||
RezClass = require('../core/' + safeFmt.toLowerCase() + '-resume');
|
||||
newRez = RezClass["default"]();
|
||||
newRez = RezClass.default();
|
||||
newRez.save(t);
|
||||
ret = newRez;
|
||||
} catch (_error) {
|
||||
} catch (error) {
|
||||
err = error;
|
||||
ret = {
|
||||
fluenterror: HMSTATUS.createError,
|
||||
inner: _error
|
||||
inner: err
|
||||
};
|
||||
} finally {
|
||||
this.stat(HMEVENT.afterCreate, {
|
||||
|
42
dist/verbs/peek.js
vendored
42
dist/verbs/peek.js
vendored
@ -1,14 +1,12 @@
|
||||
|
||||
/**
|
||||
Implementation of the 'peek' verb for HackMyResume.
|
||||
@module verbs/peek
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var HMEVENT, HMSTATUS, PeekVerb, Verb, _, __, _peek, _peekOne, safeLoadJSON,
|
||||
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;
|
||||
/**
|
||||
Implementation of the 'peek' verb for HackMyResume.
|
||||
@module verbs/peek
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
/** Peek at a resume, resume section, or resume field. */
|
||||
/** Peek at a single resume, resume section, or resume field. */
|
||||
var HMEVENT, HMSTATUS, PeekVerb, Verb, _, __, _peek, _peekOne, safeLoadJSON;
|
||||
|
||||
Verb = require('../verbs/verb');
|
||||
|
||||
@ -22,19 +20,12 @@ Implementation of the 'peek' verb for HackMyResume.
|
||||
|
||||
HMEVENT = require('../core/event-codes');
|
||||
|
||||
module.exports = PeekVerb = (function(superClass) {
|
||||
extend(PeekVerb, superClass);
|
||||
|
||||
function PeekVerb() {
|
||||
PeekVerb.__super__.constructor.call(this, 'peek', _peek);
|
||||
module.exports = PeekVerb = class PeekVerb extends Verb {
|
||||
constructor() {
|
||||
super('peek', _peek);
|
||||
}
|
||||
|
||||
return PeekVerb;
|
||||
|
||||
})(Verb);
|
||||
|
||||
|
||||
/** Peek at a resume, resume section, or resume field. */
|
||||
};
|
||||
|
||||
_peek = function(src, dst, opts) {
|
||||
var objPath, results;
|
||||
@ -54,6 +45,8 @@ Implementation of the 'peek' verb for HackMyResume.
|
||||
if (tgt.error) {
|
||||
this.setError(tgt.error.fluenterror, tgt.error);
|
||||
}
|
||||
//tgt.error.quit = opts.assert
|
||||
//@err tgt.error.fluenterror, tgt.error
|
||||
return tgt;
|
||||
}, this);
|
||||
if (this.hasError() && !opts.assert) {
|
||||
@ -64,20 +57,20 @@ Implementation of the 'peek' verb for HackMyResume.
|
||||
return results;
|
||||
};
|
||||
|
||||
|
||||
/** Peek at a single resume, resume section, or resume field. */
|
||||
|
||||
_peekOne = function(t, objPath) {
|
||||
var errCode, obj, pkgError, tgt;
|
||||
this.stat(HMEVENT.beforePeek, {
|
||||
file: t,
|
||||
target: objPath
|
||||
});
|
||||
// Load the input file JSON 1st
|
||||
obj = safeLoadJSON(t);
|
||||
// Fetch the requested object path (or the entire file)
|
||||
tgt = null;
|
||||
if (!obj.ex) {
|
||||
tgt = objPath ? __.get(obj.json, objPath) : obj.json;
|
||||
}
|
||||
//# safeLoadJSON can only return a READ error or a PARSE error
|
||||
pkgError = null;
|
||||
if (obj.ex) {
|
||||
errCode = obj.ex.op === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError;
|
||||
@ -89,6 +82,7 @@ Implementation of the 'peek' verb for HackMyResume.
|
||||
inner: obj.ex
|
||||
};
|
||||
}
|
||||
// Fire the 'afterPeek' event with collected info
|
||||
this.stat(HMEVENT.afterPeek, {
|
||||
file: t,
|
||||
requested: objPath,
|
||||
|
65
dist/verbs/validate.js
vendored
65
dist/verbs/validate.js
vendored
@ -1,14 +1,21 @@
|
||||
|
||||
/**
|
||||
Implementation of the 'validate' verb for HackMyResume.
|
||||
@module verbs/validate
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var FS, HMEVENT, HMSTATUS, ResumeFactory, SyntaxErrorEx, ValidateVerb, Verb, _, _validate, _validateOne, chalk, safeLoadJSON,
|
||||
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;
|
||||
/**
|
||||
Implementation of the 'validate' verb for HackMyResume.
|
||||
@module verbs/validate
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
/**
|
||||
Validate a single resume.
|
||||
@returns {
|
||||
file: <fileName>,
|
||||
isValid: <validFlag>,
|
||||
status: <validationStatus>,
|
||||
violations: <validationErrors>,
|
||||
schema: <schemaType>,
|
||||
error: <errorObject>
|
||||
}
|
||||
*/
|
||||
var FS, HMEVENT, HMSTATUS, ResumeFactory, SyntaxErrorEx, ValidateVerb, Verb, _, _validate, _validateOne, chalk, safeLoadJSON;
|
||||
|
||||
FS = require('fs');
|
||||
|
||||
@ -28,20 +35,15 @@ Implementation of the 'validate' verb for HackMyResume.
|
||||
|
||||
safeLoadJSON = require('../utils/safe-json-loader');
|
||||
|
||||
|
||||
/** An invokable resume validation command. */
|
||||
|
||||
module.exports = ValidateVerb = (function(superClass) {
|
||||
extend(ValidateVerb, superClass);
|
||||
|
||||
function ValidateVerb() {
|
||||
ValidateVerb.__super__.constructor.call(this, 'validate', _validate);
|
||||
module.exports = ValidateVerb = class ValidateVerb extends Verb {
|
||||
constructor() {
|
||||
super('validate', _validate);
|
||||
}
|
||||
|
||||
return ValidateVerb;
|
||||
|
||||
})(Verb);
|
||||
};
|
||||
|
||||
// Validate 1 to N resumes in FRESH or JSON Resume format.
|
||||
_validate = function(sources, unused, opts) {
|
||||
var results, schemas, validator;
|
||||
if (!sources || !sources.length) {
|
||||
@ -71,21 +73,8 @@ Implementation of the 'validate' verb for HackMyResume.
|
||||
return results;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Validate a single resume.
|
||||
@returns {
|
||||
file: <fileName>,
|
||||
isValid: <validFlag>,
|
||||
status: <validationStatus>,
|
||||
violations: <validationErrors>,
|
||||
schema: <schemaType>,
|
||||
error: <errorObject>
|
||||
}
|
||||
*/
|
||||
|
||||
_validateOne = function(t, validator, schemas, opts) {
|
||||
var errCode, obj, ret, validate;
|
||||
var err, errCode, obj, ret, validate;
|
||||
ret = {
|
||||
file: t,
|
||||
isValid: false,
|
||||
@ -93,6 +82,7 @@ Implementation of the 'validate' verb for HackMyResume.
|
||||
schema: '-----'
|
||||
};
|
||||
try {
|
||||
// Read and parse the resume JSON. Won't throw.
|
||||
obj = safeLoadJSON(t);
|
||||
if (!obj.ex) {
|
||||
if (obj.json.basics) {
|
||||
@ -111,6 +101,7 @@ Implementation of the 'validate' verb for HackMyResume.
|
||||
ret.violations = validate.errors;
|
||||
}
|
||||
} else {
|
||||
// If failure, package JSON read/parse errors
|
||||
if (obj.ex.op === 'parse') {
|
||||
errCode = HMSTATUS.parseError;
|
||||
ret.status = 'broken';
|
||||
@ -124,10 +115,12 @@ Implementation of the 'validate' verb for HackMyResume.
|
||||
quiet: errCode === HMSTATUS.readError
|
||||
};
|
||||
}
|
||||
} catch (_error) {
|
||||
} catch (error) {
|
||||
err = error;
|
||||
// Package any unexpected exceptions
|
||||
ret.error = {
|
||||
fluenterror: HMSTATUS.validateError,
|
||||
inner: _error
|
||||
inner: err
|
||||
};
|
||||
}
|
||||
this.stat(HMEVENT.afterValidate, ret);
|
||||
|
72
dist/verbs/verb.js
vendored
72
dist/verbs/verb.js
vendored
@ -1,11 +1,9 @@
|
||||
|
||||
/**
|
||||
Definition of the Verb class.
|
||||
@module verbs/verb
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
/**
|
||||
Definition of the Verb class.
|
||||
@module verbs/verb
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
var EVENTS, HMEVENT, Promise, Verb;
|
||||
|
||||
EVENTS = require('events');
|
||||
@ -14,65 +12,57 @@ Definition of the Verb class.
|
||||
|
||||
Promise = require('pinkie-promise');
|
||||
|
||||
|
||||
/**
|
||||
An abstract invokable verb.
|
||||
Provides base class functionality for verbs. Provide common services such as
|
||||
error handling, event management, and promise support.
|
||||
@class Verb
|
||||
*/
|
||||
|
||||
module.exports = Verb = (function() {
|
||||
|
||||
*/
|
||||
module.exports = Verb = class Verb {
|
||||
/** Constructor. Automatically called at creation. */
|
||||
function Verb(moniker, workhorse) {
|
||||
constructor(moniker, workhorse) {
|
||||
this.moniker = moniker;
|
||||
this.workhorse = workhorse;
|
||||
this.emitter = new EVENTS.EventEmitter();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/** Invoke the command. */
|
||||
|
||||
Verb.prototype.invoke = function() {
|
||||
invoke() {
|
||||
var argsArray, that;
|
||||
// Sent the 'begin' notification for this verb
|
||||
this.stat(HMEVENT.begin, {
|
||||
cmd: this.moniker
|
||||
});
|
||||
// Prepare command arguments
|
||||
argsArray = Array.prototype.slice.call(arguments);
|
||||
// Create a promise for this verb instance
|
||||
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. */
|
||||
|
||||
Verb.prototype.on = function() {
|
||||
on() {
|
||||
return this.emitter.on.apply(this.emitter, arguments);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/** Fire an arbitrary event, scoped to "hmr:". */
|
||||
|
||||
Verb.prototype.fire = function(evtName, payload) {
|
||||
fire(evtName, payload) {
|
||||
payload = payload || {};
|
||||
payload.cmd = this.moniker;
|
||||
this.emitter.emit('hmr:' + evtName, payload);
|
||||
return true;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/** Handle an error condition. */
|
||||
|
||||
Verb.prototype.err = function(errorCode, payload, hot) {
|
||||
err(errorCode, payload, hot) {
|
||||
payload = payload || {};
|
||||
payload.sub = payload.fluenterror = errorCode;
|
||||
payload["throw"] = hot;
|
||||
payload.throw = hot;
|
||||
this.setError(errorCode, payload);
|
||||
if (payload.quit) {
|
||||
this.reject(errorCode);
|
||||
@ -82,36 +72,28 @@ Definition of the Verb class.
|
||||
throw payload;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/** Fire the 'hmr:status' error event. */
|
||||
|
||||
Verb.prototype.stat = function(subEvent, payload) {
|
||||
stat(subEvent, payload) {
|
||||
payload = payload || {};
|
||||
payload.sub = subEvent;
|
||||
this.fire('status', payload);
|
||||
return true;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/** Has an error occurred during this verb invocation? */
|
||||
|
||||
Verb.prototype.hasError = function() {
|
||||
hasError() {
|
||||
return this.errorCode || this.errorObj;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/** Associate error info with the invocation. */
|
||||
|
||||
Verb.prototype.setError = function(code, obj) {
|
||||
setError(code, obj) {
|
||||
this.errorCode = code;
|
||||
this.errorObj = obj;
|
||||
};
|
||||
}
|
||||
|
||||
return Verb;
|
||||
|
||||
})();
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
||||
|
Reference in New Issue
Block a user