1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-10 07:47:07 +01:00
This commit is contained in:
hacksalot
2016-01-18 00:34:57 -05:00
parent c9e45d4991
commit 712cba57b8
17 changed files with 122 additions and 229 deletions

View File

@ -12,7 +12,7 @@ Implementation of the 'analyze' verb for HackMyResume.
var MKDIRP = require('mkdirp')
, PATH = require('path')
, HME = require('../core/event-codes')
, HMEVENT = require('../core/event-codes')
, HMSTATUS = require('../core/status-codes')
, _ = require('underscore')
, ResumeFactory = require('../core/resume-factory')
@ -28,7 +28,9 @@ Implementation of the 'analyze' verb for HackMyResume.
},
invoke: function() {
this.stat( HMEVENT.begin, { cmd: 'analyze' });
analyze.apply( this, arguments );
this.stat( HMEVENT.end );
}
});
@ -39,7 +41,6 @@ Implementation of the 'analyze' verb for HackMyResume.
Run the 'analyze' command.
*/
function analyze( sources, dst, opts ) {
this.stat('begin');
if( !sources || !sources.length )
throw { fluenterror: HMSTATUS.resumeNotFound };
@ -52,7 +53,6 @@ Implementation of the 'analyze' verb for HackMyResume.
result.fluenterror || _analyze.call(this, result, nlzrs, opts );
}, this);
this.stat('end');
}
@ -66,11 +66,11 @@ Implementation of the 'analyze' verb for HackMyResume.
(rez.meta && rez.meta.format && rez.meta.format.startsWith('FRESH')) ?
'FRESH' : 'JRS';
this.stat( HME.beforeAnalyze, { fmt: safeFormat, file: resumeObject.file });
this.stat( HMEVENT.beforeAnalyze, { fmt: safeFormat, file: resumeObject.file });
var info = _.mapObject( nlzrs, function(val, key) {
return val.run( resumeObject.rez );
});
this.stat( HME.afterAnalyze, { info: info } );
this.stat( HMEVENT.afterAnalyze, { info: info } );
}

View File

@ -15,8 +15,11 @@ Implementation of the 'build' verb for HackMyResume.
, MD = require('marked')
, MKDIRP = require('mkdirp')
, EXTEND = require('../utils/extend')
, HACKMYSTATUS = require('../core/status-codes')
, HME = require('../core/event-codes')
, HMSTATUS = require('../core/status-codes')
, HMEVENT = require('../core/event-codes')
, RConverter = require('fresh-jrs-converter')
, RTYPES = { FRESH: require('../core/fresh-resume'),
JRS: require('../core/jrs-resume') }
, parsePath = require('parse-filepath')
, _opts = require('../core/default-options')
, FluentTheme = require('../core/fresh-theme')
@ -43,9 +46,9 @@ Implementation of the 'build' verb for HackMyResume.
/** Invoke the Build command. */
invoke: function() {
this.stat( HME.begin, { cmd: 'build' } );
this.stat( HMEVENT.begin, { cmd: 'build' } );
build.apply( this, arguments );
this.stat( HME.end );
this.stat( HMEVENT.end );
}
});
@ -63,7 +66,7 @@ Implementation of the 'build' verb for HackMyResume.
function build( src, dst, opts ) {
if( !src || !src.length ) { this.err( HACKMYSTATUS.resumeNotFound ); }
if( !src || !src.length ) { this.err( HMSTATUS.resumeNotFound ); }
prep( src, dst, opts );
@ -76,24 +79,36 @@ Implementation of the 'build' verb for HackMyResume.
// Load the theme...we do this first because the theme choice (FRESH or
// JSON Resume) determines what format we'll convert the resume to.
this.stat( HME.beforeTheme, { theme: _opts.theme });
this.stat( HMEVENT.beforeTheme, { theme: _opts.theme });
var tFolder = verifyTheme.call( this, _opts.theme );
var theme = loadTheme( tFolder );
this.stat( HME.afterTheme, { theme: theme });
this.stat( HMEVENT.afterTheme, { theme: theme });
// Check for invalid outputs
var inv = verifyOutputs.call( this, dst, theme );
if( inv && inv.length ) {
this.err( HACKMYSTATUS.invalidFormat, { data: inv, theme: theme } );
this.err( HMSTATUS.invalidFormat, { data: inv, theme: theme } );
}
// Convert resume inputs as necessary
var toFormat = theme.render ? 'JRS' : 'FRESH';
sheets.forEach( function( sh, idx ) {
if( sh.format() !== toFormat ) {
this.stat( HMEVENT.beforeInlineConvert );
sheets[ idx ] = new (RTYPES[ toFormat ])();
var convJSON = RConverter[ 'to' + toFormat ]( sh );
sheets[ idx ].parseJSON( convJSON );
this.stat( HMEVENT.afterInlineConvert, { file: sh.i().file, fmt: toFormat } );
}
}, this);
// Merge input resumes...
(sheets.length > 1) && this.stat( HME.beforeMerge, { f: _.clone(sheets) });
(sheets.length > 1) && this.stat( HMEVENT.beforeMerge, { f: _.clone(sheets) });
rez = _.reduceRight( sheets, function( a, b, idx ) {
return extend( true, b, a );
});
// TODO: Fix this condition
(sheets.length) && this.stat( HME.afterMerge, { r: rez } );
(sheets.length) && this.stat( HMEVENT.afterMerge, { r: rez } );
// Expand output resumes...
var targets = expand( dst, theme );
@ -151,7 +166,7 @@ Implementation of the 'build' verb for HackMyResume.
, fName = PATH.basename(f, '.' + fType)
, theFormat;
this.stat( HME.beforeGenerate, {
this.stat( HMEVENT.beforeGenerate, {
fmt: targInfo.fmt.outFormat,
file: PATH.relative(process.cwd(), f)
});
@ -184,7 +199,7 @@ Implementation of the 'build' verb for HackMyResume.
// Catch any errors caused by generating this file and don't let them
// propagate -- typically we want to continue processing other formats
// even if this format failed.
this.err( HME.generate, { inner: ex } );
this.err( HMEVENT.generate, { inner: ex } );
}
}
@ -195,7 +210,7 @@ Implementation of the 'build' verb for HackMyResume.
*/
function verifyOutputs( targets, theme ) {
this.stat(HME.verifyOutputs, { targets: targets, theme: theme });
this.stat(HMEVENT.verifyOutputs, { targets: targets, theme: theme });
return _.reject(
targets.map( function( t ) {
@ -286,7 +301,7 @@ Implementation of the 'build' verb for HackMyResume.
if( !exists( tFolder ) ) {
tFolder = PATH.resolve( themeNameOrPath );
if( !exists( tFolder ) ) {
this.err( HACKMYSTATUS.themeNotFound, { data: _opts.theme } );
this.err( HMSTATUS.themeNotFound, { data: _opts.theme } );
}
}
return tFolder;

View File

@ -13,9 +13,9 @@ Implementation of the 'convert' verb for HackMyResume.
var ResumeFactory = require('../core/resume-factory')
, chalk = require('chalk')
, Verb = require('../verbs/verb')
, HACKMYSTATUS = require('../core/status-codes')
, HMSTATUS = require('../core/status-codes')
, _ = require('underscore')
, HME = require('../core/event-codes');
, HMEVENT = require('../core/event-codes');
var ConvertVerb = module.exports = Verb.extend({
@ -25,7 +25,9 @@ Implementation of the 'convert' verb for HackMyResume.
},
invoke: function() {
this.stat( HMEVENT.begin, { cmd: 'convert' });
convert.apply( this, arguments );
this.stat( HMEVENT.end );
}
});
@ -41,17 +43,17 @@ Implementation of the 'convert' verb for HackMyResume.
if( !srcs || !srcs.length ) { throw { fluenterror: 6 }; }
if( !dst || !dst.length ) {
if( srcs.length === 1 ) {
throw { fluenterror: HACKMYSTATUS.inputOutputParity };
throw { fluenterror: HMSTATUS.inputOutputParity };
}
else if( srcs.length === 2 ) {
dst = dst || []; dst.push( srcs.pop() );
}
else {
throw { fluenterror: HACKMYSTATUS.inputOutputParity };
throw { fluenterror: HMSTATUS.inputOutputParity };
}
}
if(srcs && dst && srcs.length && dst.length && srcs.length !== dst.length){
throw { fluenterror: HACKMYSTATUS.inputOutputParity };
throw { fluenterror: HMSTATUS.inputOutputParity };
}
// Load source resumes
@ -67,7 +69,7 @@ Implementation of the 'convert' verb for HackMyResume.
'JRS' : 'FRESH'
, targetFormat = srcFmt === 'JRS' ? 'FRESH' : 'JRS';
this.stat(HME.beforeConvert, { srcFile: rinfo.file, srcFmt: srcFmt, dstFile: dst[idx], dstFmt: targetFormat });
this.stat(HMEVENT.beforeConvert, { srcFile: rinfo.file, srcFmt: srcFmt, dstFile: dst[idx], dstFmt: targetFormat });
// Save it to the destination format
s.saveAs( dst[idx], targetFormat );

View File

@ -15,8 +15,8 @@ Implementation of the 'create' verb for HackMyResume.
, chalk = require('chalk')
, Verb = require('../verbs/verb')
, _ = require('underscore')
, HACKMYSTATUS = require('../core/status-codes')
, HME = require('../core/event-codes');
, HMSTATUS = require('../core/status-codes')
, HMEVENT = require('../core/event-codes');
@ -27,7 +27,9 @@ Implementation of the 'create' verb for HackMyResume.
},
invoke: function() {
this.stat( HMEVENT.begin, { cmd: 'create' });
create.apply( this, arguments );
this.stat( HMEVENT.begin, { cmd: 'convert' });
}
});
@ -39,19 +41,17 @@ Implementation of the 'create' verb for HackMyResume.
*/
function create( src, dst, opts ) {
if(!src || !src.length) throw {fluenterror: HACKMYSTATUS.createNameMissing};
this.stat( HME.begin );
if(!src || !src.length) throw {fluenterror: HMSTATUS.createNameMissing};
_.each( src, function( t ) {
var safeFmt = opts.format.toUpperCase();
this.stat( HME.beforeCreate, { fmt: safeFmt, file: t } );
this.stat( HMEVENT.beforeCreate, { fmt: safeFmt, file: t } );
MKDIRP.sync( PATH.dirname( t ) ); // Ensure dest folder exists;
var RezClass = require('../core/' + safeFmt.toLowerCase() + '-resume' );
RezClass.default().save(t);
this.stat( HME.afterCreate, { fmt: safeFmt, file: t } );
this.stat( HMEVENT.afterCreate, { fmt: safeFmt, file: t } );
}, this);
this.stat( HME.end );
}

View File

@ -26,7 +26,9 @@ Implementation of the 'peek' verb for HackMyResume.
},
invoke: function() {
this.stat( HMEVENT.begin, { cmd: 'peek' } );
peek.apply( this, arguments );
this.stat( HMEVENT.end );
}
});
@ -39,7 +41,6 @@ Implementation of the 'peek' verb for HackMyResume.
function peek( src, dst, opts ) {
if(!src || !src.length) throw {fluenterror: HMSTATUS.resumeNotFound};
this.stat( HMEVENT.begin );
var objPath = (dst && dst[0]) || '';
@ -55,7 +56,6 @@ Implementation of the 'peek' verb for HackMyResume.
this.stat( HMEVENT.afterPeek, { file: t, requested: objPath, target: targ } );
}, this);
this.stat( HMEVENT.end );
}

View File

@ -11,8 +11,8 @@ Implementation of the 'validate' verb for HackMyResume.
var SyntaxErrorEx = require('../utils/syntax-error-ex');
var chalk = require('chalk');
var Verb = require('../verbs/verb');
var HACKMYSTATUS = require('../core/status-codes');
var HME = require('../core/event-codes');
var HMSTATUS = require('../core/status-codes');
var HMEVENT = require('../core/event-codes');
var _ = require('underscore');
@ -24,7 +24,9 @@ Implementation of the 'validate' verb for HackMyResume.
},
invoke: function() {
this.stat( HMEVENT.begin, { cmd: 'validate' } );
validate.apply( this, arguments );
this.stat( HMEVENT.end );
}
});
@ -81,11 +83,11 @@ Implementation of the 'validate' verb for HackMyResume.
return ret;
}
this.stat(HME.afterValidate, { file: src.file, isValid: isValid,
this.stat(HMEVENT.afterValidate, { file: src.file, isValid: isValid,
fmt: fmt.replace('jars', 'JSON Resume'), errors: errors });
if( opts.assert && !isValid ) {
throw { fluenterror: HACKMYSTATUS.invalid, shouldExit: true };
throw { fluenterror: HMSTATUS.invalid, shouldExit: true };
}
return ret;