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:
parent
a8fed1b69b
commit
ce75f09210
@ -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"
|
||||||
},
|
},
|
||||||
|
@ -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'))() }
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -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 + ' ***');
|
||||||
|
@ -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.
|
||||||
|
@ -4,7 +4,24 @@ External API surface for HackMyResume.
|
|||||||
@module hackmyapi.js
|
@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'),
|
Sheet: require('./core/fresh-resume'),
|
||||||
FRESHResume: require('./core/fresh-resume'),
|
FRESHResume: require('./core/fresh-resume'),
|
||||||
JRSResume: require('./core/jrs-resume'),
|
JRSResume: require('./core/jrs-resume'),
|
||||||
@ -21,4 +38,6 @@ module.exports = {
|
|||||||
JsonYamlGenerator: require('./gen/json-yaml-generator'),
|
JsonYamlGenerator: require('./gen/json-yaml-generator'),
|
||||||
LaTeXGenerator: require('./gen/latex-generator'),
|
LaTeXGenerator: require('./gen/latex-generator'),
|
||||||
HtmlPngGenerator: require('./gen/html-png-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')
|
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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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')
|
||||||
|
@ -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 );
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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,9 +131,21 @@ 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' ) {
|
||||||
|
if( _opts.pdf ) {
|
||||||
|
if( _opts.pdf !== 'none' ) {
|
||||||
suffix = chalk.green(' (with ' + _opts.pdf + ')');
|
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 ') +
|
||||||
chalk.green.bold(
|
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 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) ) }]);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user