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": { "bugs": {
"url": "https://github.com/hacksalot/HackMyResume/issues" "url": "https://github.com/hacksalot/HackMyResume/issues"
}, },
"main": "src/hackmycmd.js", "main": "src/hackmyapi.js",
"bin": { "bin": {
"hackmyresume": "src/index.js" "hackmyresume": "src/index.js"
}, },

View File

@ -1,20 +1,20 @@
(function(){ (function(){
var FLUENT = require('../hackmyapi');
/** /**
Supported resume formats. Supported resume formats.
*/ */
module.exports = [ module.exports = [
{ name: 'html', ext: 'html', gen: new FLUENT.HtmlGenerator() },
{ name: 'txt', ext: 'txt', gen: new FLUENT.TextGenerator() }, { name: 'html', ext: 'html', gen: new (require('../gen/html-generator'))() },
{ name: 'doc', ext: 'doc', fmt: 'xml', gen: new FLUENT.WordGenerator() }, { name: 'txt', ext: 'txt', gen: new (require('../gen/text-generator'))() },
{ name: 'pdf', ext: 'pdf', fmt: 'html', is: false, gen: new FLUENT.HtmlPdfGenerator() }, { name: 'doc', ext: 'doc', fmt: 'xml', gen: new (require('../gen/word-generator'))() },
{ name: 'png', ext: 'png', fmt: 'html', is: false, gen: new FLUENT.HtmlPngGenerator() }, { name: 'pdf', ext: 'pdf', fmt: 'html', is: false, gen: new (require('../gen/html-pdf-generator'))() },
{ name: 'md', ext: 'md', fmt: 'txt', gen: new FLUENT.MarkdownGenerator() }, { name: 'png', ext: 'png', fmt: 'html', is: false, gen: new (require('../gen/html-png-generator'))() },
{ name: 'json', ext: 'json', gen: new FLUENT.JsonGenerator() }, { name: 'md', ext: 'md', fmt: 'txt', gen: new (require('../gen/markdown-generator'))() },
{ name: 'yml', ext: 'yml', fmt: 'yml', gen: new FLUENT.JsonYamlGenerator() }, { name: 'json', ext: 'json', gen: new (require('../gen/json-generator'))() },
{ name: 'latex', ext: 'tex', fmt: 'latex', gen: new FLUENT.LaTeXGenerator() } { 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') var HACKMYSTATUS = require('./status-codes')
, PKG = require('../../package.json') , PKG = require('../../package.json')
, FS = require('fs') , FS = require('fs')
, FCMD = require('../hackmycmd') , FCMD = require('../hackmyapi')
, PATH = require('path') , PATH = require('path')
, chalk = require('chalk') , chalk = require('chalk')
, title = chalk.white.bold('\n*** HackMyResume v' + PKG.version + ' ***'); , 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') , H2W = require('../utils/html-to-wpml')
, XML = require('xml-escape') , XML = require('xml-escape')
, moment = require('moment') , moment = require('moment')
, _ = require('underscore'); , _ = require('underscore')
, unused = require('../utils/string');
/** /**
Generic template helper function definitions. Generic template helper function definitions.

View File

@ -4,21 +4,40 @@ External API surface for HackMyResume.
@module hackmyapi.js @module hackmyapi.js
*/ */
module.exports = { (function() {
Sheet: require('./core/fresh-resume'),
FRESHResume: require('./core/fresh-resume'), var v = {
JRSResume: require('./core/jrs-resume'), build: require('./verbs/generate'),
FRESHTheme: require('./core/fresh-theme'), analyze: require('./verbs/analyze'),
JRSTheme: require('./core/jrs-theme'), validate: require('./verbs/validate'),
FluentDate: require('./core/fluent-date'), convert: require('./verbs/convert'),
HtmlGenerator: require('./gen/html-generator'), new: require('./verbs/create')
TextGenerator: require('./gen/text-generator'), };
HtmlPdfGenerator: require('./gen/html-pdf-generator'),
WordGenerator: require('./gen/word-generator'), var HackMyAPI = module.exports = {
MarkdownGenerator: require('./gen/markdown-generator'), verbs: v,
JsonGenerator: require('./gen/json-generator'), alias: {
YamlGenerator: require('./gen/yaml-generator'), generate: v.build,
JsonYamlGenerator: require('./gen/json-yaml-generator'), create: v.build
LaTeXGenerator: require('./gen/latex-generator'), },
HtmlPngGenerator: require('./gen/html-png-generator') 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('./gen/html-generator'),
TextGenerator: require('./gen/text-generator'),
HtmlPdfGenerator: require('./gen/html-pdf-generator'),
WordGenerator: require('./gen/word-generator'),
MarkdownGenerator: require('./gen/markdown-generator'),
JsonGenerator: require('./gen/json-generator'),
YamlGenerator: require('./gen/yaml-generator'),
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') var SPAWNW = require('./core/spawn-watch')
, FCMD = require( './hackmycmd') , HMR = require( './hackmyapi')
, PKG = require('../package.json') , PKG = require('../package.json')
, FS = require('fs') , FS = require('fs')
, EXTEND = require('./utils/extend') , EXTEND = require('./utils/extend')
@ -139,7 +139,7 @@ function initialize() {
} }
// Handle invalid verbs here (a bit easier here than in commander.js)... // 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, throw { fluenterror: HACKMYSTATUS.invalidCommand, shouldExit: true,
attempted: oVerb }; attempted: oVerb };
} }
@ -165,7 +165,7 @@ Invoke a HackMyResume verb.
*/ */
function execVerb( src, dst, opts, log ) { function execVerb( src, dst, opts, log ) {
loadOptions.call( this, opts ); 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') var MKDIRP = require('mkdirp')
, MKDIRP = require('mkdirp')
, PATH = require('path') , PATH = require('path')
, _ = require('underscore') , _ = require('underscore')
, ResumeFactory = require('../core/resume-factory') , ResumeFactory = require('../core/resume-factory')

View File

@ -6,8 +6,7 @@ Implementation of the 'create' verb for HackMyResume.
(function(){ (function(){
var FLUENT = require('../hackmyapi') var MKDIRP = require('mkdirp')
, MKDIRP = require('mkdirp')
, PATH = require('path') , PATH = require('path')
, chalk = require('chalk'); , chalk = require('chalk');
@ -22,7 +21,9 @@ Implementation of the 'create' verb for HackMyResume.
_log(chalk.green('Creating new ') + chalk.green.bold(safeFormat) + _log(chalk.green('Creating new ') + chalk.green.bold(safeFormat) +
chalk.green(' resume: ') + chalk.green.bold(t)); chalk.green(' resume: ') + chalk.green.bold(t));
MKDIRP.sync( PATH.dirname( t ) ); // Ensure dest folder exists; 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; _err = errHandler || error;
_opts.theme = (opts.theme && opts.theme.toLowerCase().trim())|| 'modern'; _opts.theme = (opts.theme && opts.theme.toLowerCase().trim())|| 'modern';
_opts.prettify = opts.prettify === true ? _opts.prettify : false; _opts.prettify = opts.prettify === true ? _opts.prettify : false;
_opts.css = opts.css; _opts.css = opts.css || 'embed';
_opts.pdf = opts.pdf; _opts.pdf = opts.pdf;
_opts.wrap = opts.wrap || 60; _opts.wrap = opts.wrap || 60;
@ -131,8 +131,20 @@ Implementation of the 'generate' verb for HackMyResume.
, theFormat; , theFormat;
var suffix = ''; var suffix = '';
if( targInfo.fmt.outFormat === 'pdf' && _opts.pdf ) { if( targInfo.fmt.outFormat === 'pdf' ) {
suffix = chalk.green(' (with ' + _opts.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 ') + _log( chalk.green('Generating ') +
@ -244,28 +256,22 @@ Implementation of the 'generate' verb for HackMyResume.
var to = PATH.resolve(t), pa = parsePath(to),fmat = pa.extname || '.all'; 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.push.apply(
targets, fmat === '.all' ? targets, fmat === '.all' ?
Object.keys( implicitFormats ).map( function( k ) { Object.keys( theTheme.formats ).map( function( k ) {
var z = theTheme.formats[k]; var z = theTheme.formats[k];
return { file: to.replace( /all$/g, z.outFormat ), fmt: z }; return { file: to.replace( /all$/g, z.outFormat ), fmt: z };
}) : }) :
[{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]); [{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]);
targets.push.apply( // targets.push.apply(
targets, fmat === '.all' ? // targets, fmat === '.all' ?
Object.keys( explicitFormats ).map( function( k ) { // Object.keys( explicitFormats ).map( function( k ) {
var z = theTheme.formats[k]; // var z = theTheme.formats[k];
return { file: to.replace( /all$/g, z.outFormat ), fmt: z }; // return { file: to.replace( /all$/g, z.outFormat ), fmt: z };
}) : // }) :
[{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]); // [{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]);
}); });

View File

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

View File

@ -6,7 +6,7 @@ var SPAWNWATCHER = require('../src/core/spawn-watch')
, path = require('path') , path = require('path')
, _ = require('underscore') , _ = require('underscore')
, FRESHResume = require('../src/core/fresh-resume') , FRESHResume = require('../src/core/fresh-resume')
, FCMD = require( '../src/hackmycmd') , HMR = require( '../src/hackmyapi')
, validator = require('is-my-json-valid') , validator = require('is-my-json-valid')
, READFILES = require('recursive-readdir-sync') , READFILES = require('recursive-readdir-sync')
, fileContains = require('../src/utils/file-contains') , fileContains = require('../src/utils/file-contains')
@ -31,9 +31,20 @@ function genThemes( title, src, fmt ) {
theme: themeLoc, theme: themeLoc,
format: fmt, format: fmt,
prettify: true, 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(); tryOpen.should.not.Throw();
}); });