1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-03 04:47:07 +01:00

Finish HackMyCore reshaping.

Reintroduce HackMyCore, dropping the interim submodule, and reorganize
and improve tests.
This commit is contained in:
hacksalot
2016-01-29 15:23:57 -05:00
parent e9971eb882
commit 0f65e4c9f3
130 changed files with 5384 additions and 337 deletions

8
dist/cli/error.js vendored
View File

@ -8,19 +8,19 @@ Error-handling routines for HackMyResume.
(function() {
var ErrorHandler, FCMD, FS, HMSTATUS, M2C, PATH, PKG, SyntaxErrorEx, WRAP, YAML, _defaultLog, assembleError, chalk, extend, printf;
HMSTATUS = require('../hmc/dist/core/status-codes');
HMSTATUS = require('../core/status-codes');
PKG = require('../../package.json');
FS = require('fs');
FCMD = require('../hmc');
FCMD = require('../index');
PATH = require('path');
WRAP = require('word-wrap');
M2C = require('../hmc/dist/utils/md2chalk.js');
M2C = require('../utils/md2chalk');
chalk = require('chalk');
@ -30,7 +30,7 @@ Error-handling routines for HackMyResume.
printf = require('printf');
SyntaxErrorEx = require('../hmc/dist/utils/syntax-error-ex');
SyntaxErrorEx = require('../utils/syntax-error-ex');
require('string.prototype.startswith');

22
dist/cli/index.js vendored Normal file
View File

@ -0,0 +1,22 @@
#! /usr/bin/env node
/**
Command-line interface (CLI) for HackMyResume.
@license MIT. See LICENSE.md for details.
@module index.js
*/
try {
require('./main')( process.argv );
}
catch( ex ) {
require('./error').err( ex, true );
}

11
dist/cli/main.js vendored
View File

@ -8,7 +8,7 @@ Definition of the `main` function.
(function() {
var Command, EXTEND, FS, HME, HMR, HMSTATUS, OUTPUT, PAD, PATH, PKG, StringUtils, _, _opts, _out, _title, chalk, execute, initOptions, initialize, loadOptions, logMsg, main, safeLoadJSON, splitSrcDest;
HMR = require('../hmc');
HMR = require('../index');
PKG = require('../../package.json');
@ -20,13 +20,13 @@ Definition of the `main` function.
PATH = require('path');
HMSTATUS = require('../hmc/dist/core/status-codes');
HMSTATUS = require('../core/status-codes');
HME = require('../hmc/dist/core/event-codes');
HME = require('../core/event-codes');
safeLoadJSON = require('../hmc/dist/utils/safe-json-loader');
safeLoadJSON = require('../utils/safe-json-loader');
StringUtils = require('../hmc/dist/utils/string.js');
StringUtils = require('../utils/string.js');
_ = require('underscore');
@ -210,6 +210,7 @@ Definition of the `main` function.
});
v.invoke.call(v, src, dst, _opts, log);
if (v.errorCode) {
console.log('Exiting with error code ' + v.errorCode);
return process.exit(v.errorCode);
}
};

8
dist/cli/out.js vendored
View File

@ -10,13 +10,13 @@ Output routines for HackMyResume.
chalk = require('chalk');
HME = require('../hmc/dist/core/event-codes');
HME = require('../core/event-codes');
_ = require('underscore');
Class = require('../hmc/dist/utils/class.js');
Class = require('../utils/class.js');
M2C = require('../hmc/dist/utils/md2chalk.js');
M2C = require('../utils/md2chalk.js');
PATH = require('path');
@ -110,7 +110,7 @@ Output routines for HackMyResume.
case HME.afterAnalyze:
info = evt.info;
rawTpl = FS.readFileSync(PATH.join(__dirname, 'analyze.hbs'), 'utf8');
HANDLEBARS.registerHelper(require('../hmc/dist/helpers/console-helpers'));
HANDLEBARS.registerHelper(require('../helpers/console-helpers'));
template = HANDLEBARS.compile(rawTpl, {
strict: false,
assumeObjects: false

View File

@ -55,6 +55,10 @@ Definition of the FRESHResume class.
/** Initialize the the FreshResume from JSON string data. */
FreshResume.prototype.parse = function(stringData, opts) {
var ref;
this.imp = (ref = this.imp) != null ? ref : {
raw: stringData
};
return this.parseJSON(JSON.parse(stringData), opts);
};
@ -74,7 +78,7 @@ Definition of the FRESHResume class.
*/
FreshResume.prototype.parseJSON = function(rep, opts) {
var ignoreList, scrubbed, that, traverse;
var ignoreList, ref, scrubbed, that, traverse;
that = this;
traverse = require('traverse');
ignoreList = [];
@ -87,12 +91,16 @@ Definition of the FRESHResume class.
}
});
extend(true, this, scrubbed);
if (!this.imp) {
if (!((ref = this.imp) != null ? ref.processed : void 0)) {
opts = opts || {};
if (opts.imp === void 0 || opts.imp) {
this.imp = this.imp || {};
this.imp.title = (opts.title || this.imp.title) || this.name;
if (!this.imp.raw) {
this.imp.raw = JSON.stringify(rep);
}
}
this.imp.processed = true;
(opts.date === void 0 || opts.date) && _parseDates.call(this);
(opts.sort === void 0 || opts.sort) && this.sort();
(opts.compute === void 0 || opts.compute) && (this.computed = {

View File

@ -39,24 +39,23 @@ Definition of the JRSResume class.
/** Initialize the JSResume from file. */
JRSResume.prototype.open = function(file, title) {
this.basics = {
imp: {
file: file,
raw: FS.readFileSync(file, 'utf8')
}
};
return this.parse(this.basics.imp.raw, title);
JRSResume.prototype.open = function(file, opts) {
var raw, ret;
raw = FS.readFileSync(file, 'utf8');
ret = this.parse(raw, opts);
this.imp.file = file;
return ret;
};
/** Initialize the the JSResume from string. */
JRSResume.prototype.parse = function(stringData, opts) {
var rep;
opts = opts || {};
rep = JSON.parse(stringData);
return this.parseJSON(rep, opts);
var ref;
this.imp = (ref = this.imp) != null ? ref : {
raw: stringData
};
return this.parseJSON(JSON.parse(stringData), opts);
};
@ -75,7 +74,7 @@ Definition of the JRSResume class.
*/
JRSResume.prototype.parseJSON = function(rep, opts) {
var ignoreList, scrubbed, that, traverse;
var ignoreList, ref, scrubbed, that, traverse;
opts = opts || {};
that = this;
traverse = require('traverse');
@ -89,10 +88,16 @@ Definition of the JRSResume class.
}
});
extend(true, this, scrubbed);
if (opts.imp === void 0 || opts.imp) {
this.basics.imp = this.basics.imp || {};
this.basics.imp.title = (opts.title || this.basics.imp.title) || this.basics.name;
this.basics.imp.orgFormat = 'JRS';
if (!((ref = this.imp) != null ? ref.processed : void 0)) {
opts = opts || {};
if (opts.imp === void 0 || opts.imp) {
this.imp = this.imp || {};
this.imp.title = (opts.title || this.imp.title) || this.basics.name;
if (!this.imp.raw) {
this.imp.raw = JSON.stringify(rep);
}
}
this.imp.processed = true;
}
(opts.date === void 0 || opts.date) && _parseDates.call(this);
(opts.sort === void 0 || opts.sort) && this.sort();
@ -109,8 +114,8 @@ Definition of the JRSResume class.
/** Save the sheet to disk (for environments that have disk access). */
JRSResume.prototype.save = function(filename) {
this.basics.imp.file = filename || this.basics.imp.file;
FS.writeFileSync(this.basics.imp.file, this.stringify(this), 'utf8');
this.imp.file = filename || this.imp.file;
FS.writeFileSync(this.imp.file, this.stringify(this), 'utf8');
return this;
};
@ -120,8 +125,8 @@ Definition of the JRSResume class.
JRSResume.prototype.saveAs = function(filename, format) {
var newRep, stringRep;
if (format === 'JRS') {
this.basics.imp.file = filename || this.basics.imp.file;
FS.writeFileSync(this.basics.imp.file, this.stringify(), 'utf8');
this.imp.file = filename || this.imp.file;
FS.writeFileSync(this.imp.file, this.stringify(), 'utf8');
} else {
newRep = CONVERTER.toFRESH(this);
stringRep = CONVERTER.toSTRING(newRep);
@ -163,9 +168,8 @@ Definition of the JRSResume class.
*/
JRSResume.prototype.i = function() {
this.basics = this.basics || {};
this.basics.imp = this.basics.imp || {};
return this.basics.imp;
var ref;
return this.imp = (ref = this.imp) != null ? ref : {};
};
@ -225,7 +229,7 @@ Definition of the JRSResume class.
/** Validate the sheet against the JSON Resume schema. */
JRSResume.prototype.isValid = function() {
var ret, schema, schemaObj, validate;
var ret, schema, schemaObj, temp, validate;
schema = FS.readFileSync(PATH.join(__dirname, 'resume.json'), 'utf8');
schemaObj = JSON.parse(schema);
validator = require('is-my-json-valid');
@ -234,10 +238,13 @@ Definition of the JRSResume class.
date: /^\d{4}(?:-(?:0[0-9]{1}|1[0-2]{1})(?:-[0-9]{2})?)?$/
}
});
temp = this.imp;
delete this.imp;
ret = validate(this);
this.imp = temp;
if (!ret) {
this.basics.imp = this.basics.imp || {};
this.basics.imp.validationErrors = validate.errors;
this.imp = this.imp || {};
this.imp.validationErrors = validate.errors;
}
return ret;
};

View File

@ -1,49 +0,0 @@
/**
External API surface for HackMyResume.
@license MIT. See LICENSE.md for details.
@module hackmycore/index
*/
/**
API facade for HackMyCore.
*/
(function() {
var HackMyCore;
HackMyCore = module.exports = {
verbs: {
build: require('./verbs/build'),
analyze: require('./verbs/analyze'),
validate: require('./verbs/validate'),
convert: require('./verbs/convert'),
"new": require('./verbs/create'),
peek: require('./verbs/peek')
},
alias: {
generate: require('./verbs/build'),
create: require('./verbs/create')
},
options: require('./core/default-options'),
formats: require('./core/default-formats'),
Sheet: require('./core/fresh-resume'),
FRESHResume: require('./core/fresh-resume'),
JRSResume: require('./core/jrs-resume'),
FRESHTheme: require('./core/fresh-theme'),
JRSTheme: require('./core/jrs-theme'),
FluentDate: require('./core/fluent-date'),
HtmlGenerator: require('./generators/html-generator'),
TextGenerator: require('./generators/text-generator'),
HtmlPdfCliGenerator: require('./generators/html-pdf-cli-generator'),
WordGenerator: require('./generators/word-generator'),
MarkdownGenerator: require('./generators/markdown-generator'),
JsonGenerator: require('./generators/json-generator'),
YamlGenerator: require('./generators/yaml-generator'),
JsonYamlGenerator: require('./generators/json-yaml-generator'),
LaTeXGenerator: require('./generators/latex-generator'),
HtmlPngGenerator: require('./generators/html-png-generator')
};
}).call(this);

View File

@ -1,34 +0,0 @@
/**
Safe spawn utility for HackMyResume / FluentCV.
@module utils/safe-spawn
@license MIT. See LICENSE.md for details.
*/
(function() {
module.exports = function(cmd, args, isSync) {
var info, spawn;
try {
spawn = require('child_process')[isSync ? 'spawnSync' : 'spawn'];
info = spawn(cmd, args);
if (!isSync) {
return info.on('error', function(err) {
throw {
cmd: 'wkhtmltopdf',
inner: err
};
});
} else {
if (info.error) {
throw {
cmd: 'wkhtmltopdf',
inner: info.error
};
}
}
} catch (_error) {
throw _error;
}
};
}).call(this);

92
dist/hmc/package.json vendored
View File

@ -1,92 +0,0 @@
{
"name": "hackmycore",
"version": "0.4.0",
"description": "The open core library for HackMyResume and FluentCV.",
"repository": {
"type": "git",
"url": "https://github.com/hacksalot/HackMyCore.git"
},
"scripts": {
"test": "grunt clean:test && mocha",
"grunt": "grunt"
},
"author": "hacksalot <hacksalot@indevious.com> (https://github.com/hacksalot)",
"contributors": [],
"license": "MIT",
"bugs": {
"url": "https://github.com/hacksalot/HackMyCore/issues"
},
"main": "dist/index.js",
"homepage": "https://github.com/hacksalot/HackMyCore",
"dependencies": {
"copy": "^0.1.3",
"extend": "^3.0.0",
"fresca": "~0.6.0",
"fresh-jrs-converter": "^0.2.0",
"fresh-resume-starter": "^0.2.2",
"fresh-themes": "~0.14.0-beta",
"fs-extra": "^0.24.0",
"handlebars": "^4.0.5",
"html": "0.0.10",
"is-my-json-valid": "^2.12.2",
"json-lint": "^0.1.0",
"jst": "0.0.13",
"lodash": "^3.10.1",
"marked": "^0.3.5",
"mkdirp": "^0.5.1",
"moment": "^2.10.6",
"parse-filepath": "^0.6.3",
"path-exists": "^2.1.0",
"printf": "^0.2.3",
"recursive-readdir-sync": "^1.0.6",
"simple-html-tokenizer": "^0.2.0",
"slash": "^1.0.0",
"string-padding": "^1.0.2",
"string.prototype.endswith": "^0.2.0",
"string.prototype.startswith": "^0.2.0",
"traverse": "^0.6.6",
"underscore": "^1.8.3",
"word-wrap": "^1.1.0",
"xml-escape": "^1.0.0",
"yamljs": "^0.2.4"
},
"devDependencies": {
"chai": "*",
"chalk": "^1.1.1",
"fresh-test-resumes": "^0.6.0",
"grunt": "*",
"grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-coffee": "^0.13.0",
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-jshint": "^0.11.3",
"grunt-contrib-yuidoc": "^0.10.0",
"grunt-jsdoc": "^1.1.0",
"grunt-simple-mocha": "*",
"jsonresume-theme-boilerplate": "^0.1.2",
"jsonresume-theme-classy": "^1.0.9",
"jsonresume-theme-modern": "0.0.18",
"jsonresume-theme-sceptile": "^1.0.5",
"mocha": "*",
"resample": "fluentdesk/resample"
},
"keywords": [
"resume",
"CV",
"portfolio",
"employment",
"career",
"HackMyResume",
"Markdown",
"JSON",
"Word",
"PDF",
"YAML",
"HTML",
"LaTeX",
"CLI",
"Handlebars",
"Underscore",
"template"
]
}

57
dist/index.js vendored
View File

@ -1,22 +1,49 @@
#! /usr/bin/env node
/**
External API surface for HackMyResume.
@license MIT. See LICENSE.md for details.
@module hackmycore/index
*/
/**
Command-line interface (CLI) for HackMyResume.
@license MIT. See LICENSE.md for details.
@module index.js
*/
API facade for HackMyCore.
*/
(function() {
var HackMyCore;
HackMyCore = module.exports = {
verbs: {
build: require('./verbs/build'),
analyze: require('./verbs/analyze'),
validate: require('./verbs/validate'),
convert: require('./verbs/convert'),
"new": require('./verbs/create'),
peek: require('./verbs/peek')
},
alias: {
generate: require('./verbs/build'),
create: require('./verbs/create')
},
options: require('./core/default-options'),
formats: require('./core/default-formats'),
Sheet: require('./core/fresh-resume'),
FRESHResume: require('./core/fresh-resume'),
JRSResume: require('./core/jrs-resume'),
FRESHTheme: require('./core/fresh-theme'),
JRSTheme: require('./core/jrs-theme'),
FluentDate: require('./core/fluent-date'),
HtmlGenerator: require('./generators/html-generator'),
TextGenerator: require('./generators/text-generator'),
HtmlPdfCliGenerator: require('./generators/html-pdf-cli-generator'),
WordGenerator: require('./generators/word-generator'),
MarkdownGenerator: require('./generators/markdown-generator'),
JsonGenerator: require('./generators/json-generator'),
YamlGenerator: require('./generators/yaml-generator'),
JsonYamlGenerator: require('./generators/json-yaml-generator'),
LaTeXGenerator: require('./generators/latex-generator'),
HtmlPngGenerator: require('./generators/html-png-generator')
};
try {
require('./cli/main')( process.argv );
}
catch( ex ) {
require('./cli/error').err( ex, true );
}
}).call(this);

46
dist/utils/safe-spawn.js vendored Normal file
View File

@ -0,0 +1,46 @@
/**
Safe spawn utility for HackMyResume / FluentCV.
@module utils/safe-spawn
@license MIT. See LICENSE.md for details.
*/
(function() {
module.exports = function(cmd, args, isSync, callback) {
var info, spawn;
try {
spawn = require('child_process')[isSync ? 'spawnSync' : 'spawn'];
info = spawn(cmd, args);
if (!isSync) {
info.on('error', function(err) {
if (callback != null) {
callback(err);
} else {
throw {
cmd: cmd,
inner: err
};
}
});
} else {
if (info.error) {
if (callback != null) {
callback(err);
} else {
throw {
cmd: cmd,
inner: info.error
};
}
}
}
} catch (_error) {
if (callback != null) {
return callback(_error);
} else {
throw _error;
}
}
};
}).call(this);

View File

@ -34,9 +34,7 @@ Implementation of the 'peek' verb for HackMyResume.
});
/**
Peek at a resume, resume section, or resume field.
*/
/** Peek at a resume, resume section, or resume field. */
peek = function(src, dst, opts) {
var objPath;

View File

@ -6,7 +6,7 @@ Implementation of the 'validate' verb for HackMyResume.
*/
(function() {
var FS, HMEVENT, HMSTATUS, ResumeFactory, SyntaxErrorEx, ValidateVerb, Verb, _, chalk, validate;
var FS, HMEVENT, HMSTATUS, ResumeFactory, SyntaxErrorEx, ValidateVerb, Verb, _, chalk, safeLoadJSON, validate;
FS = require('fs');
@ -24,6 +24,8 @@ Implementation of the 'validate' verb for HackMyResume.
_ = require('underscore');
safeLoadJSON = require('../utils/safe-json-loader');
/** An invokable resume validation command. */
@ -32,11 +34,13 @@ Implementation of the 'validate' verb for HackMyResume.
return this._super('validate');
},
invoke: function() {
var ret;
this.stat(HMEVENT.begin, {
cmd: 'validate'
});
validate.apply(this, arguments);
ret = validate.apply(this, arguments);
this.stat(HMEVENT.end);
return ret;
}
});
@ -44,7 +48,7 @@ Implementation of the 'validate' verb for HackMyResume.
/** Validate 1 to N resumes in FRESH or JSON Resume format. */
validate = function(sources, unused, opts) {
var resumes, schemas, validator;
var schemas, validator;
if (!sources || !sources.length) {
throw {
fluenterror: HMSTATUS.resumeNotFoundAlt,
@ -56,53 +60,51 @@ Implementation of the 'validate' verb for HackMyResume.
fresh: require('fresca'),
jars: require('../core/resume.json')
};
resumes = ResumeFactory.load(sources, {
format: null,
objectify: false
}, this);
return resumes.map(function(src) {
var errors, exc, fmt, json, ret;
return _.map(sources, function(t) {
var errCode, errors, fmt, json, obj, ret;
ret = {
file: src,
file: t,
isValid: false
};
if (src.fluenterror) {
if (opts.assert) {
throw src;
}
this.setError(src.fluenterror, src);
return ret;
}
json = src.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})?)?$/
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;
}
});
ret.isValid = validate(json);
if (!ret.isValid) {
errors = validate.errors;
} catch (_error) {
ret.ex = _error;
}
} catch (_error) {
exc = _error;
return ret;
} 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);
}
this.stat(HMEVENT.afterValidate, {
file: src.file,
file: t,
isValid: ret.isValid,
fmt: fmt.replace('jars', 'JSON Resume'),
fmt: fmt != null ? fmt.replace('jars', 'JSON Resume') : void 0,
errors: errors
});
if (opts.assert && !ret.isValid) {
throw {
fluenterror: HMSTATUS.invalid({
shouldExit: true
})
fluenterror: HMSTATUS.invalid,
shouldExit: true
};
}
console.log('1111');
return ret;
}, this);
};