mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-05 01:56:21 +00:00
Refactor API interface.
This commit is contained in:
parent
a8fed1b69b
commit
ce75f09210
@ -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"
|
||||
},
|
||||
|
@ -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'))() }
|
||||
|
||||
];
|
||||
|
||||
|
@ -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 + ' ***');
|
||||
|
@ -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.
|
||||
|
@ -4,21 +4,40 @@ External API surface for HackMyResume.
|
||||
@module hackmyapi.js
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
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')
|
||||
};
|
||||
(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'),
|
||||
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')
|
||||
};
|
||||
|
||||
}());
|
||||
|
@ -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
|
@ -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 );
|
||||
}
|
||||
|
||||
|
||||
|
@ -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')
|
||||
|
@ -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 );
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -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,8 +131,20 @@ Implementation of the 'generate' verb for HackMyResume.
|
||||
, theFormat;
|
||||
|
||||
var suffix = '';
|
||||
if( targInfo.fmt.outFormat === 'pdf' && _opts.pdf ) {
|
||||
suffix = chalk.green(' (with ' + _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 ') +
|
||||
@ -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) ) }]);
|
||||
|
||||
});
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user