1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-22 16:30:11 +00:00

Refactor API interface.

This commit is contained in:
hacksalot 2016-01-04 07:23:20 -05:00
parent a8fed1b69b
commit ce75f09210
12 changed files with 98 additions and 113 deletions

View File

@ -39,7 +39,7 @@
"bugs": {
"url": "https://github.com/hacksalot/HackMyResume/issues"
},
"main": "src/hackmycmd.js",
"main": "src/hackmyapi.js",
"bin": {
"hackmyresume": "src/index.js"
},

View File

@ -1,20 +1,20 @@
(function(){
var FLUENT = require('../hackmyapi');
/**
Supported resume formats.
*/
module.exports = [
{ name: 'html', ext: 'html', gen: new FLUENT.HtmlGenerator() },
{ name: 'txt', ext: 'txt', gen: new FLUENT.TextGenerator() },
{ name: 'doc', ext: 'doc', fmt: 'xml', gen: new FLUENT.WordGenerator() },
{ name: 'pdf', ext: 'pdf', fmt: 'html', is: false, gen: new FLUENT.HtmlPdfGenerator() },
{ name: 'png', ext: 'png', fmt: 'html', is: false, gen: new FLUENT.HtmlPngGenerator() },
{ name: 'md', ext: 'md', fmt: 'txt', gen: new FLUENT.MarkdownGenerator() },
{ name: 'json', ext: 'json', gen: new FLUENT.JsonGenerator() },
{ name: 'yml', ext: 'yml', fmt: 'yml', gen: new FLUENT.JsonYamlGenerator() },
{ name: 'latex', ext: 'tex', fmt: 'latex', gen: new FLUENT.LaTeXGenerator() }
{ name: 'html', ext: 'html', gen: new (require('../gen/html-generator'))() },
{ name: 'txt', ext: 'txt', gen: new (require('../gen/text-generator'))() },
{ name: 'doc', ext: 'doc', fmt: 'xml', gen: new (require('../gen/word-generator'))() },
{ name: 'pdf', ext: 'pdf', fmt: 'html', is: false, gen: new (require('../gen/html-pdf-generator'))() },
{ name: 'png', ext: 'png', fmt: 'html', is: false, gen: new (require('../gen/html-png-generator'))() },
{ name: 'md', ext: 'md', fmt: 'txt', gen: new (require('../gen/markdown-generator'))() },
{ name: 'json', ext: 'json', gen: new (require('../gen/json-generator'))() },
{ name: 'yml', ext: 'yml', fmt: 'yml', gen: new (require('../gen/json-yaml-generator'))() },
{ name: 'latex', ext: 'tex', fmt: 'latex', gen: new (require('../gen/latex-generator'))() }
];

View File

@ -13,7 +13,7 @@ Error-handling routines for HackMyResume.
var HACKMYSTATUS = require('./status-codes')
, PKG = require('../../package.json')
, FS = require('fs')
, FCMD = require('../hackmycmd')
, FCMD = require('../hackmyapi')
, PATH = require('path')
, chalk = require('chalk')
, title = chalk.white.bold('\n*** HackMyResume v' + PKG.version + ' ***');

View File

@ -11,7 +11,8 @@ Generic template helper definitions for HackMyResume / FluentCV.
, H2W = require('../utils/html-to-wpml')
, XML = require('xml-escape')
, moment = require('moment')
, _ = require('underscore');
, _ = require('underscore')
, unused = require('../utils/string');
/**
Generic template helper function definitions.

View File

@ -4,7 +4,24 @@ External API surface for HackMyResume.
@module hackmyapi.js
*/
module.exports = {
(function() {
var v = {
build: require('./verbs/generate'),
analyze: require('./verbs/analyze'),
validate: require('./verbs/validate'),
convert: require('./verbs/convert'),
new: require('./verbs/create')
};
var HackMyAPI = module.exports = {
verbs: v,
alias: {
generate: v.build,
create: v.build
},
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'),
@ -21,4 +38,6 @@ module.exports = {
JsonYamlGenerator: require('./gen/json-yaml-generator'),
LaTeXGenerator: require('./gen/latex-generator'),
HtmlPngGenerator: require('./gen/html-png-generator')
};
};
}());

View File

@ -1,52 +0,0 @@
/**
Internal resume generation logic for HackMyResume.
@license MIT. Copyright (c) 2015 James M. Devlin / FluentDesk.
@module hackmycmd.js
*/
(function() {
module.exports = function () {
var unused = require('./utils/string')
, PATH = require('path')
, FS = require('fs')
, chalk = require('chalk');
/**
Display help documentation.
*/
function help() {
var manPage = FS.readFileSync( PATH.join(__dirname, 'use.txt'), 'utf8' );
console.log( chalk.green.bold(manPage) );
}
/**
Internal module interface. Used by FCV Desktop and HMR.
*/
var v = {
build: require('./verbs/generate'),
analyze: require('./verbs/analyze'),
validate: require('./verbs/validate'),
convert: require('./verbs/convert'),
new: require('./verbs/create'),
help: help
};
return {
verbs: v,
alias: {
generate: v.build,
create: v.build
},
lib: require('./hackmyapi'),
options: require('./core/default-options'),
formats: require('./core/default-formats')
};
}();
}());
// [1]: JSON.parse throws SyntaxError on invalid JSON. See:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

View File

@ -11,7 +11,7 @@ Command-line interface (CLI) for HackMyResume.
var SPAWNW = require('./core/spawn-watch')
, FCMD = require( './hackmycmd')
, HMR = require( './hackmyapi')
, PKG = require('../package.json')
, FS = require('fs')
, EXTEND = require('./utils/extend')
@ -139,7 +139,7 @@ function initialize() {
}
// Handle invalid verbs here (a bit easier here than in commander.js)...
if( verb && !FCMD.verbs[ verb ] && !FCMD.alias[ verb ] ) {
if( verb && !HMR.verbs[ verb ] && !HMR.alias[ verb ] ) {
throw { fluenterror: HACKMYSTATUS.invalidCommand, shouldExit: true,
attempted: oVerb };
}
@ -165,7 +165,7 @@ Invoke a HackMyResume verb.
*/
function execVerb( src, dst, opts, log ) {
loadOptions.call( this, opts );
FCMD.verbs[ this.name() ].call( null, src, dst, _opts, log );
HMR.verbs[ this.name() ].call( null, src, dst, _opts, log );
}

View File

@ -10,8 +10,7 @@ Implementation of the 'analyze' verb for HackMyResume.
var FLUENT = require('../hackmyapi')
, MKDIRP = require('mkdirp')
var MKDIRP = require('mkdirp')
, PATH = require('path')
, _ = require('underscore')
, ResumeFactory = require('../core/resume-factory')

View File

@ -6,8 +6,7 @@ Implementation of the 'create' verb for HackMyResume.
(function(){
var FLUENT = require('../hackmyapi')
, MKDIRP = require('mkdirp')
var MKDIRP = require('mkdirp')
, PATH = require('path')
, chalk = require('chalk');
@ -22,7 +21,9 @@ Implementation of the 'create' verb for HackMyResume.
_log(chalk.green('Creating new ') + chalk.green.bold(safeFormat) +
chalk.green(' resume: ') + chalk.green.bold(t));
MKDIRP.sync( PATH.dirname( t ) ); // Ensure dest folder exists;
FLUENT[ safeFormat + 'Resume' ].default().save( t );
var RezClass = require('../core/' + safeFormat.toLowerCase() + '-resume' );
RezClass.default().save(t);
//FLUENT[ safeFormat + 'Resume' ].default().save( t );
});
};

View File

@ -52,7 +52,7 @@ Implementation of the 'generate' verb for HackMyResume.
_err = errHandler || error;
_opts.theme = (opts.theme && opts.theme.toLowerCase().trim())|| 'modern';
_opts.prettify = opts.prettify === true ? _opts.prettify : false;
_opts.css = opts.css;
_opts.css = opts.css || 'embed';
_opts.pdf = opts.pdf;
_opts.wrap = opts.wrap || 60;
@ -131,9 +131,21 @@ Implementation of the 'generate' verb for HackMyResume.
, theFormat;
var suffix = '';
if( targInfo.fmt.outFormat === 'pdf' && _opts.pdf ) {
if( targInfo.fmt.outFormat === 'pdf' ) {
if( _opts.pdf ) {
if( _opts.pdf !== 'none' ) {
suffix = chalk.green(' (with ' + _opts.pdf + ')');
}
else {
_log( chalk.gray('Skipping ') +
chalk.white.bold(
pad(targInfo.fmt.outFormat.toUpperCase(),4,null,pad.RIGHT)) +
chalk.gray(' resume') + suffix + chalk.green(': ') +
chalk.white( PATH.relative(process.cwd(), f )) );
return;
}
}
}
_log( chalk.green('Generating ') +
chalk.green.bold(
@ -244,28 +256,22 @@ Implementation of the 'generate' verb for HackMyResume.
var to = PATH.resolve(t), pa = parsePath(to),fmat = pa.extname || '.all';
var explicitFormats = _.omit( theTheme.formats, function(val, key) {
return !val.freebie;
});
var implicitFormats = _.omit( theTheme.formats, function(val) {
return val.freebie;
});
targets.push.apply(
targets, fmat === '.all' ?
Object.keys( implicitFormats ).map( function( k ) {
Object.keys( theTheme.formats ).map( function( k ) {
var z = theTheme.formats[k];
return { file: to.replace( /all$/g, z.outFormat ), fmt: z };
}) :
[{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]);
targets.push.apply(
targets, fmat === '.all' ?
Object.keys( explicitFormats ).map( function( k ) {
var z = theTheme.formats[k];
return { file: to.replace( /all$/g, z.outFormat ), fmt: z };
}) :
[{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]);
// targets.push.apply(
// targets, fmat === '.all' ?
// Object.keys( explicitFormats ).map( function( k ) {
// var z = theTheme.formats[k];
// return { file: to.replace( /all$/g, z.outFormat ), fmt: z };
// }) :
// [{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]);
});

View File

@ -5,7 +5,7 @@ var chai = require('chai')
, path = require('path')
, _ = require('underscore')
, FRESHResume = require('../src/core/fresh-resume')
, FCMD = require( '../src/hackmycmd')
, FCMD = require( '../src/hackmyapi')
, validator = require('is-my-json-valid');
chai.config.includeStack = false;

View File

@ -6,7 +6,7 @@ var SPAWNWATCHER = require('../src/core/spawn-watch')
, path = require('path')
, _ = require('underscore')
, FRESHResume = require('../src/core/fresh-resume')
, FCMD = require( '../src/hackmycmd')
, HMR = require( '../src/hackmyapi')
, validator = require('is-my-json-valid')
, READFILES = require('recursive-readdir-sync')
, fileContains = require('../src/utils/file-contains')
@ -31,9 +31,20 @@ function genThemes( title, src, fmt ) {
theme: themeLoc,
format: fmt,
prettify: true,
silent: false
silent: false,
css: 'embed'
};
FCMD.verbs.build( src, dst, opts, function(msg) { console.log(msg); } );
try {
HMR.verbs.build( src, dst, opts, function(msg) {
msg = msg || '';
console.log(msg);
});
}
catch(ex) {
console.log(ex);
console.log(ex.stack);
throw ex;
}
}
tryOpen.should.not.Throw();
});