From 712cba57b827cb8f5d17512a5a2595f8f0650392 Mon Sep 17 00:00:00 2001 From: hacksalot Date: Mon, 18 Jan 2016 00:34:57 -0500 Subject: [PATCH] Capture. --- src/cli/error.js | 39 ++++++++-------- src/cli/main.js | 14 ++++-- src/cli/msg.yml | 4 +- src/cli/out.js | 9 +++- src/core/event-codes.js | 4 +- src/core/fresh-resume.js | 10 ++-- src/core/jrs-resume.js | 15 +++--- src/verbs/analyze.js | 10 ++-- src/verbs/build.js | 43 +++++++++++------ src/verbs/convert.js | 14 +++--- src/verbs/create.js | 14 +++--- src/verbs/peek.js | 4 +- src/verbs/validate.js | 10 ++-- test/test-api.js | 99 ---------------------------------------- test/test-converter.js | 44 ------------------ test/test-hmr.txt | 4 +- test/test-themes.js | 14 +++--- 17 files changed, 122 insertions(+), 229 deletions(-) delete mode 100644 test/test-api.js delete mode 100644 test/test-converter.js diff --git a/src/cli/error.js b/src/cli/error.js index fb6b13a..1445fc7 100644 --- a/src/cli/error.js +++ b/src/cli/error.js @@ -10,7 +10,7 @@ Error-handling routines for HackMyResume. - var HACKMYSTATUS = require('../core/status-codes') + var HMSTATUS = require('../core/status-codes') , PKG = require('../../package.json') , FS = require('fs') , FCMD = require('../hackmyapi') @@ -31,15 +31,18 @@ Error-handling routines for HackMyResume. */ var ErrorHandler = module.exports = { - init: function( debug, assert ) { + init: function( debug, assert, silent ) { this.debug = debug; this.assert = assert; + this.silent = silent; this.msgs = require('./msg.js').errors; return this; }, err: function( ex, shouldExit ) { + var o = this.silent ? function() { } : _defaultLog; + if( !this.msgs ) { this.msgs = require('./msg.js').errors; } @@ -91,9 +94,9 @@ Error-handling routines for HackMyResume. }; - var o = function() { + function _defaultLog() { console.log.apply( console.log, arguments ); - }; + } function assembleError( ex ) { @@ -101,20 +104,20 @@ Error-handling routines for HackMyResume. switch( ex.fluenterror ) { - case HACKMYSTATUS.themeNotFound: + case HMSTATUS.themeNotFound: msg = printf( M2C( this.msgs.themeNotFound.msg, 'yellow' ), ex.data); break; - case HACKMYSTATUS.copyCSS: + case HMSTATUS.copyCSS: msg = M2C( this.msgs.copyCSS.msg, 'red' ); quit = false; break; - case HACKMYSTATUS.resumeNotFound: + case HMSTATUS.resumeNotFound: msg = M2C( this.msgs.resumeNotFound.msg, 'yellow' ); break; - case HACKMYSTATUS.missingCommand: + case HMSTATUS.missingCommand: msg = M2C( this.msgs.missingCommand.msg + " (", 'yellow'); msg += Object.keys( FCMD.verbs ).map( function(v, idx, ar) { return (idx === ar.length - 1 ? chalk.yellow('or ') : '') + @@ -125,53 +128,53 @@ Error-handling routines for HackMyResume. PATH.resolve(__dirname, '../cli/use.txt'), 'utf8' )); break; - case HACKMYSTATUS.invalidCommand: + case HMSTATUS.invalidCommand: msg = printf( M2C( this.msgs.invalidCommand.msg, 'yellow'), ex.attempted ); break; - case HACKMYSTATUS.resumeNotFoundAlt: + case HMSTATUS.resumeNotFoundAlt: msg = M2C( this.msgs.resumeNotFoundAlt.msg, 'yellow' ); break; - case HACKMYSTATUS.inputOutputParity: + case HMSTATUS.inputOutputParity: msg = M2C( this.msgs.inputOutputParity.msg ); break; - case HACKMYSTATUS.createNameMissing: + case HMSTATUS.createNameMissing: msg = M2C( this.msgs.createNameMissing.msg ); break; - case HACKMYSTATUS.pdfGeneration: + case HMSTATUS.pdfGeneration: msg = M2C( this.msgs.pdfGeneration.msg, 'bold' ); if( ex.inner ) msg += chalk.red('\n' + ex.inner); withStack = true; quit = false; warn = false; break; - case HACKMYSTATUS.invalid: + case HMSTATUS.invalid: msg = M2C( this.msgs.invalid.msg, 'red' ); warn = false; break; - case HACKMYSTATUS.invalidFormat: + case HMSTATUS.invalidFormat: ex.data.forEach(function(d){ msg += printf( M2C( this.msgs.invalidFormat.msg, 'bold' ), ex.theme.name.toUpperCase(), d.format.toUpperCase()); }, this); break; - case HACKMYSTATUS.notOnPath: + case HMSTATUS.notOnPath: msg = printf( M2C(this.msgs.notOnPath.msg, 'bold'), ex.engine); quit = false; warn = false; break; - case HACKMYSTATUS.readError: + case HMSTATUS.readError: console.error( printf( M2C(this.msgs.readError.msg, 'red'), ex.file ) ); msg = ex.inner.toString(); warn = false; break; - case HACKMYSTATUS.parseError: + case HMSTATUS.parseError: if( SyntaxErrorEx.is( ex.inner )) { var se = new SyntaxErrorEx( ex, ex.raw ); msg = printf( M2C( this.msgs.parseError.msg, 'red' ), diff --git a/src/cli/main.js b/src/cli/main.js index b6aecd3..8cb6443 100644 --- a/src/cli/main.js +++ b/src/cli/main.js @@ -131,10 +131,10 @@ Definition of the `main` function. /** Massage command-line args and setup Commander.js. */ function initialize( ar ) { - logMsg( _title ); - var o = initOptions( ar ); + o.silent || logMsg( _title ); + // Emit debug prelude if --debug was specified if( o.debug ) { _out.log(chalk.cyan('The -d or --debug switch was specified. DEBUG mode engaged.')); @@ -213,8 +213,14 @@ Definition of the `main` function. return v === '-d' || v === '--debug'; }); + // Grab the --silent flag + var isSilent = _.some( args, function(v) { + return v === '-s' || v === '--silent'; + }); + return { debug: isDebug, + silent: isSilent, orgVerb: oVerb, verb: verb, json: oJSON, @@ -229,7 +235,7 @@ Definition of the `main` function. loadOptions.call( this, opts, this.parent.jsonArgs ); var hand = require( './error' ); - hand.init( _opts.debug, _opts.assert ); + hand.init( _opts.debug, _opts.assert, _opts.silent ); var v = new HMR.verbs[ this.name() ](); _out.init( _opts ); v.on( 'hmr:status', function() { _out.do.apply( _out, arguments ); }); @@ -271,7 +277,7 @@ Definition of the `main` function. logMsg(chalk.cyan('OPTIONS:') + '\n'); _.each(o, function(val, key) { logMsg(chalk.cyan(' %s') + chalk.cyan.bold(' %s'), - PAD(key,17,null,PAD.RIGHT), val); + PAD(key,22,null,PAD.RIGHT), val); }); logMsg(''); } diff --git a/src/cli/msg.yml b/src/cli/msg.yml index 95ca13d..52578a4 100644 --- a/src/cli/msg.yml +++ b/src/cli/msg.yml @@ -47,10 +47,12 @@ events: - Peeking at **%s** afterPeek: msg: "The specified key **%s** was not found in **%s**." + afterInlineConvert: + msg: Converting **%s** to **%s** format. errors: themeNotFound: msg: > - Couldn't find the '%s' theme. Please specify the name of a preinstalled + **Couldn't find the '%s' theme.** Please specify the name of a preinstalled FRESH theme or the path to a locally installed FRESH or JSON Resume theme. copyCSS: msg: Couldn't copy CSS file to destination folder. diff --git a/src/cli/out.js b/src/cli/out.js index 4d16a7f..3062817 100644 --- a/src/cli/out.js +++ b/src/cli/out.js @@ -100,7 +100,7 @@ Output routines for HackMyResume. this.msgs.beforeMerge.msg[1] ), a.i().file ); }, this); - L( M2C(msg, 'cyan') ); + L( M2C(msg, 'green') ); break; case HME.afterMerge: @@ -148,7 +148,7 @@ Output routines for HackMyResume. break; case HME.beforeAnalyze: - L( M2C( this.msgs.beforeAnalyze.msg, 'cyan' ), evt.fmt, evt.file); + L( M2C( this.msgs.beforeAnalyze.msg, 'green' ), evt.fmt, evt.file); break; case HME.afterAnalyze: @@ -169,6 +169,11 @@ Output routines for HackMyResume. ); break; + case HME.afterInlineConvert: + L( M2C( this.msgs.afterInlineConvert.msg, 'green'), + evt.file, evt.fmt ); + break; + case HME.afterValidate: var style = evt.isValid ? 'green' : 'yellow'; L( diff --git a/src/core/event-codes.js b/src/core/event-codes.js index a85047a..55cf36f 100644 --- a/src/core/event-codes.js +++ b/src/core/event-codes.js @@ -34,7 +34,9 @@ Event code definitions. beforeParse: 18, afterParse: 19, beforePeek: 20, - afterPeek: 21 + afterPeek: 21, + beforeInlineConvert: 22, + afterInlineConvert: 23 }; diff --git a/src/core/fresh-resume.js b/src/core/fresh-resume.js index 6977e34..65fc05d 100644 --- a/src/core/fresh-resume.js +++ b/src/core/fresh-resume.js @@ -41,7 +41,7 @@ Definition of the FRESHResume class. FreshResume.prototype.open = function( file, opts ) { var raw = FS.readFileSync( file, 'utf8' ); var ret = this.parse( raw, opts ); - this.imp.fileName = file; + this.imp.file = file; return ret; }; @@ -100,8 +100,8 @@ Definition of the FRESHResume class. Save the sheet to disk (for environments that have disk access). */ FreshResume.prototype.save = function( filename ) { - this.imp.fileName = filename || this.imp.fileName; - FS.writeFileSync( this.imp.fileName, this.stringify(), 'utf8' ); + this.imp.file = filename || this.imp.file; + FS.writeFileSync( this.imp.file, this.stringify(), 'utf8' ); return this; }; @@ -113,8 +113,8 @@ Definition of the FRESHResume class. FreshResume.prototype.saveAs = function( filename, format ) { if( format !== 'JRS' ) { - this.imp.fileName = filename || this.imp.fileName; - FS.writeFileSync( this.imp.fileName, this.stringify(), 'utf8' ); + this.imp.file = filename || this.imp.file; + FS.writeFileSync( this.imp.file, this.stringify(), 'utf8' ); } else { var newRep = CONVERTER.toJRS( this ); diff --git a/src/core/jrs-resume.js b/src/core/jrs-resume.js index 2ebb48a..f464886 100644 --- a/src/core/jrs-resume.js +++ b/src/core/jrs-resume.js @@ -39,7 +39,7 @@ Definition of the JRSResume class. //this.imp = { fileName: file }; <-- schema violation, tuck it into .basics this.basics = { imp: { - fileName: file, + file: file, raw: FS.readFileSync( file, 'utf8' ) } }; @@ -91,8 +91,8 @@ Definition of the JRSResume class. Save the sheet to disk (for environments that have disk access). */ JRSResume.prototype.save = function( filename ) { - this.basics.imp.fileName = filename || this.basics.imp.fileName; - FS.writeFileSync(this.basics.imp.fileName, this.stringify( this ), 'utf8'); + this.basics.imp.file = filename || this.basics.imp.file; + FS.writeFileSync(this.basics.imp.file, this.stringify( this ), 'utf8'); return this; }; @@ -104,8 +104,8 @@ Definition of the JRSResume class. JRSResume.prototype.saveAs = function( filename, format ) { if( format === 'JRS' ) { - this.basics.imp.fileName = filename || this.imp.fileName; - FS.writeFileSync( this.basics.imp.fileName, this.stringify(), 'utf8' ); + this.basics.imp.file = filename || this.basics.imp.file; + FS.writeFileSync( this.basics.imp.file, this.stringify(), 'utf8' ); } else { var newRep = CONVERTER.toFRESH( this ); @@ -171,8 +171,9 @@ Definition of the JRSResume class. so tuck this into the .basic sub-object. */ JRSResume.prototype.i = function() { - this.basics = this.basics || { imp: { } }; - return this.basics; + this.basics = this.basics || { }; + this.basics.imp = this.basics.imp || { }; + return this.basics.imp; }; diff --git a/src/verbs/analyze.js b/src/verbs/analyze.js index 5fbb294..0373a72 100644 --- a/src/verbs/analyze.js +++ b/src/verbs/analyze.js @@ -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 } ); } diff --git a/src/verbs/build.js b/src/verbs/build.js index 074665c..592ceed 100644 --- a/src/verbs/build.js +++ b/src/verbs/build.js @@ -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; diff --git a/src/verbs/convert.js b/src/verbs/convert.js index dbb42c9..1cb968b 100644 --- a/src/verbs/convert.js +++ b/src/verbs/convert.js @@ -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 ); diff --git a/src/verbs/create.js b/src/verbs/create.js index d50b229..1c06fb5 100644 --- a/src/verbs/create.js +++ b/src/verbs/create.js @@ -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 ); } diff --git a/src/verbs/peek.js b/src/verbs/peek.js index 715d8f8..6254525 100644 --- a/src/verbs/peek.js +++ b/src/verbs/peek.js @@ -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 ); } diff --git a/src/verbs/validate.js b/src/verbs/validate.js index 36346b4..651ab20 100644 --- a/src/verbs/validate.js +++ b/src/verbs/validate.js @@ -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; diff --git a/test/test-api.js b/test/test-api.js deleted file mode 100644 index aa572c7..0000000 --- a/test/test-api.js +++ /dev/null @@ -1,99 +0,0 @@ -/** -@module test-api.js -*/ - -var chai = require('chai') - , expect = chai.expect - , should = chai.should() - , path = require('path') - , _ = require('underscore') - , FRESHResume = require('../src/core/fresh-resume') - , FCMD = require( '../src/hackmyapi') - , validator = require('is-my-json-valid') - , HMRMAIN = require('../src/cli/main') - , EXTEND = require('../src/utils/extend'); - -chai.config.includeStack = false; - -describe('Testing CLI interface', function () { - - var _sheet; - - - var opts = { - format: 'FRESH', - prettify: true, - silent: false, - assert: true // Causes validation errors to throw exceptions - }; - - var opts2 = { - format: 'JRS', - prettify: true, - silent: true - }; - - var sb = 'test/sandbox/'; - var ft = 'node_modules/fresh-test-resumes/src/fresh/'; - - [ - - [ 'new', [sb + 'new-fresh-resume.json'], [], opts, ' (FRESH format)' ], - [ 'new', [sb + 'new-jrs-resume.json'], [], opts2, ' (JRS format)'], - [ 'new', [sb + 'new-1.json', sb + 'new-2.json', sb + 'new-3.json'], [], opts, ' (multiple FRESH resumes)' ], - [ 'new', [sb + 'new-jrs-1.json', sb + 'new-jrs-2.json', sb + 'new-jrs-3.json'], [], opts, ' (multiple JRS resumes)' ], - [ '!new', [], [], opts, " (when a filename isn't specified)" ], - - [ 'validate', [ft + 'jane-fullstacker.json'], [], opts, ' (jane-q-fullstacker|FRESH)' ], - [ 'validate', [ft + 'johnny-trouble.json'], [], opts, ' (johnny-trouble|FRESH)' ], - [ 'validate', [sb + 'new-fresh-resume.json'], [], opts, ' (new-fresh-resume|FRESH)' ], - [ 'validate', ['test/resumes/jrs-0.0.0/richard-hendriks.json'], [], opts2, ' (richard-hendriks.json|JRS)' ], - [ 'validate', ['test/resumes/jrs-0.0.0/jane-incomplete.json'], [], opts2, ' (jane-incomplete.json|JRS)' ], - [ 'validate', [sb + 'new-1.json', sb + 'new-jrs-resume.json', sb + 'new-1.json', sb + 'new-2.json', sb + 'new-3.json'], [], opts, ' (5|BOTH)' ], - - [ 'analyze', [ft + 'jane-fullstacker.json'], [], opts, ' (jane-q-fullstacker|FRESH)' ], - [ 'analyze', ['test/resumes/jrs-0.0.0/richard-hendriks.json'], [], opts2, ' (richard-hendriks|JRS)' ], - - [ 'build', [ ft + 'jane-fullstacker.json', ft + 'override/jane-fullstacker-override.fresh.json' ], [ sb + 'merged/jane-fullstacker-gamedev.fresh.all'], opts, ' (jane-q-fullstacker w/ override|FRESH)' ], - [ '!build', [ ft + 'jane-fullstacker.json'], [ sb + 'shouldnt-exist.pdf' ], EXTEND(true, opts, { theme: 'awesome' }), ' (jane-q-fullstacker + Awesome + PDF|FRESH)' ] - - ].forEach( function(a) { - - run.apply( /* The players of */ null, a ); - - }); - - - function run( verb, src, dst, opts, msg ) { - msg = msg || '.'; - var shouldSucceed = true; - if( verb[0] === '!' ) { - verb = verb.substr(1); - shouldSucceed = false; - } - it( 'The ' + verb.toUpperCase() + ' command should ' + (shouldSucceed ? ' SUCCEED' : ' FAIL') + msg, function () { - function runIt() { - try { - var v = new FCMD.verbs[verb](); - v.on('hmr:error', function(ex) { - throw ex; - }); - v.invoke( src, dst, opts, opts.silent ? - function(){} : function(msg){ msg = msg || ''; console.log(msg); } ); - } - catch(ex) { - console.error(ex); - console.error(ex.stack); - throw ex; - } - } - if( shouldSucceed ) - runIt.should.not.Throw(); - else - runIt.should.Throw(); - }); - } - - - -}); diff --git a/test/test-converter.js b/test/test-converter.js deleted file mode 100644 index d7c55c1..0000000 --- a/test/test-converter.js +++ /dev/null @@ -1,44 +0,0 @@ - -var chai = require('chai') - , expect = chai.expect - , should = chai.should() - , path = require('path') - , parsePath = require('parse-filepath') - , _ = require('underscore') - , FRESHResume = require('../src/core/fresh-resume') - , JRSResume = require('../src/core/jrs-resume') - , CONVERTER = require('fresh-jrs-converter') - , FS = require('fs') - , MKDIRP = require('mkdirp') - , _ = require('underscore'); - -chai.config.includeStack = false; - -describe('FRESH/JRS converter', function () { - - var _sheet; - - it('should round-trip from JRS to FRESH to JRS without modifying or losing data', function () { - - var fileA = path.join( __dirname, 'resumes/jrs-0.0.0/richard-hendriks.json' ); - var fileB = path.join( __dirname, 'sandbox/richard-hendriks.converted.fresh.json' ); - var fileC = path.join( __dirname, 'sandbox/richard-hendriks.converted.jrs.json' ); - - _sheet = new JRSResume().open( fileA ); - MKDIRP.sync( parsePath( fileB ).dirname ); - _sheet.saveAs( fileB, 'FRESH' ); - - var freshSheet = new FRESHResume().open( fileB ); - freshSheet.saveAs( fileC, 'JRS' ); - - var rawA = FS.readFileSync( fileA, 'utf8' ); - var rawC = FS.readFileSync( fileC, 'utf8' ); - - var objA = JSON.parse( rawA ); - var objC = JSON.parse( rawC ); - - _.isEqual(objA, objC).should.equal(true); - - }); - -}); diff --git a/test/test-hmr.txt b/test/test-hmr.txt index 64cb982..21981b2 100644 --- a/test/test-hmr.txt +++ b/test/test-hmr.txt @@ -6,8 +6,8 @@ 5|notacommand 3|build 14|build doesnt-exist.json -1|build doesnt-exist.json -t not-a-theme -1|build doesnt-exist.json -t node_modules/not-a-theme +14|build doesnt-exist.json -t not-a-theme +14|build doesnt-exist.json -t node_modules/not-a-theme 8|new 0|new test/sandbox/cli-test/new-empty-resume.auto.json 0|new test/sandbox/cli-test/new-empty-resume.jrs.json -f jrs diff --git a/test/test-themes.js b/test/test-themes.js index 1da0336..be91523 100644 --- a/test/test-themes.js +++ b/test/test-themes.js @@ -32,18 +32,16 @@ function genThemes( title, src, fmt ) { format: fmt, prettify: true, silent: false, - css: 'embed' + css: 'embed', + debug: true }; try { var v = new HMR.verbs.build(); - v.invoke( src, dst, opts, function(msg) { - msg = msg || ''; - console.log(msg); - }); + v.invoke( src, dst, opts ); } catch(ex) { - console.log(ex); - console.log(ex.stack); + console.error( ex ); + console.error( ex.stack ); throw ex; } } @@ -70,7 +68,7 @@ function folderContains( needle, haystack ) { return _.some( READFILES( path.join(__dirname, haystack) ), function( absPath ) { if( FS.lstatSync( absPath ).isFile() ) { if( fileContains( absPath, needle ) ) { - console.log('Found invalid metadata in ' + absPath); + console.error('Found invalid metadata in ' + absPath); return true; } }