mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 16:30:11 +00:00
Move commands to Verb hierarchy
Move flat command functions (BUILD, ANALYZE, etc.) to a shallow Verb hierarchy. Allow command verbs to inherit common functionality and prep for better debugging/logging as well as test mocks.
This commit is contained in:
parent
47e8605f50
commit
88c71f6e9c
28
src/core/verb.js
Normal file
28
src/core/verb.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/**
|
||||||
|
Definition of the Verb class.
|
||||||
|
@module verb.js
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Use J. Resig's nifty class implementation
|
||||||
|
var Class = require( '../utils/class' );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
An instantiation of a HackMyResume command.
|
||||||
|
@class Verb
|
||||||
|
*/
|
||||||
|
var Verb = module.exports = Class.extend({
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
@ -165,7 +165,9 @@
|
|||||||
function execVerb( src, dst, opts, log ) {
|
function execVerb( src, dst, opts, log ) {
|
||||||
loadOptions.call( this, opts );
|
loadOptions.call( this, opts );
|
||||||
require('./core/error-handler').init( _opts.debug );
|
require('./core/error-handler').init( _opts.debug );
|
||||||
HMR.verbs[ this.name() ].call( null, src, dst, _opts, log );
|
|
||||||
|
var v = new HMR.verbs[ this.name() ]();
|
||||||
|
v.invoke.call( null, src, dst, _opts, log );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,14 +14,25 @@ Implementation of the 'analyze' verb for HackMyResume.
|
|||||||
, PATH = require('path')
|
, PATH = require('path')
|
||||||
, _ = require('underscore')
|
, _ = require('underscore')
|
||||||
, ResumeFactory = require('../core/resume-factory')
|
, ResumeFactory = require('../core/resume-factory')
|
||||||
|
, Verb = require('../core/verb')
|
||||||
, chalk = require('chalk');
|
, chalk = require('chalk');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var AnalyzeVerb = module.exports = Verb.extend({
|
||||||
|
|
||||||
|
invoke: function() {
|
||||||
|
analyze.apply( this, arguments );
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Run the 'analyze' command.
|
Run the 'analyze' command.
|
||||||
*/
|
*/
|
||||||
module.exports = function analyze( sources, dst, opts, logger ) {
|
function analyze( sources, dst, opts, logger ) {
|
||||||
var _log = logger || console.log;
|
var _log = logger || console.log;
|
||||||
if( !sources || !sources.length ) throw { fluenterror: 3 };
|
if( !sources || !sources.length ) throw { fluenterror: 3 };
|
||||||
|
|
||||||
@ -33,8 +44,7 @@ Implementation of the 'analyze' verb for HackMyResume.
|
|||||||
});
|
});
|
||||||
result.error || _analyze( result, nlzrs, opts, _log );
|
result.error || _analyze( result, nlzrs, opts, _log );
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,9 +26,17 @@ Implementation of the 'generate' verb for HackMyResume.
|
|||||||
, extend = require('../utils/extend')
|
, extend = require('../utils/extend')
|
||||||
, chalk = require('chalk')
|
, chalk = require('chalk')
|
||||||
, pad = require('string-padding')
|
, pad = require('string-padding')
|
||||||
|
, Verb = require('../core/verb')
|
||||||
, _err, _log, rez;
|
, _err, _log, rez;
|
||||||
|
|
||||||
|
|
||||||
|
var BuildVerb = module.exports = Verb.extend({
|
||||||
|
|
||||||
|
invoke: function() {
|
||||||
|
build.apply( this, arguments );
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Given a source resume in FRESH or JRS format, a destination resume path, and a
|
Given a source resume in FRESH or JRS format, a destination resume path, and a
|
||||||
@ -349,8 +357,4 @@ Implementation of the 'generate' verb for HackMyResume.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = build;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
@ -12,14 +12,24 @@ Implementation of the 'convert' verb for HackMyResume.
|
|||||||
|
|
||||||
var ResumeFactory = require('../core/resume-factory')
|
var ResumeFactory = require('../core/resume-factory')
|
||||||
, chalk = require('chalk')
|
, chalk = require('chalk')
|
||||||
|
, Verb = require('../core/verb')
|
||||||
, HACKMYSTATUS = require('../core/status-codes');
|
, HACKMYSTATUS = require('../core/status-codes');
|
||||||
|
|
||||||
|
|
||||||
|
var ConvertVerb = module.exports = Verb.extend({
|
||||||
|
|
||||||
|
invoke: function() {
|
||||||
|
convert.apply( this, arguments );
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Convert between FRESH and JRS formats.
|
Convert between FRESH and JRS formats.
|
||||||
*/
|
*/
|
||||||
module.exports = function convert( srcs, dst, opts, logger ) {
|
function convert( srcs, dst, opts, logger ) {
|
||||||
|
|
||||||
// Housekeeping
|
// Housekeeping
|
||||||
var _log = logger || console.log;
|
var _log = logger || console.log;
|
||||||
@ -62,7 +72,7 @@ Implementation of the 'convert' verb for HackMyResume.
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,12 +9,23 @@ Implementation of the 'create' verb for HackMyResume.
|
|||||||
var MKDIRP = require('mkdirp')
|
var MKDIRP = require('mkdirp')
|
||||||
, PATH = require('path')
|
, PATH = require('path')
|
||||||
, chalk = require('chalk')
|
, chalk = require('chalk')
|
||||||
|
, Verb = require('../core/verb')
|
||||||
, HACKMYSTATUS = require('../core/status-codes');
|
, HACKMYSTATUS = require('../core/status-codes');
|
||||||
|
|
||||||
|
|
||||||
|
var CreateVerb = module.exports = Verb.extend({
|
||||||
|
|
||||||
|
invoke: function() {
|
||||||
|
create.apply( this, arguments );
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Create a new empty resume in either FRESH or JRS format.
|
Create a new empty resume in either FRESH or JRS format.
|
||||||
*/
|
*/
|
||||||
module.exports = function create( src, dst, opts, logger ) {
|
function create( src, dst, opts, logger ) {
|
||||||
var _log = logger || console.log;
|
var _log = logger || console.log;
|
||||||
if( !src || !src.length ) throw { fluenterror: HACKMYSTATUS.createNameMissing };
|
if( !src || !src.length ) throw { fluenterror: HACKMYSTATUS.createNameMissing };
|
||||||
src.forEach( function( t ) {
|
src.forEach( function( t ) {
|
||||||
@ -26,6 +37,6 @@ Implementation of the 'create' verb for HackMyResume.
|
|||||||
RezClass.default().save(t);
|
RezClass.default().save(t);
|
||||||
//FLUENT[ safeFormat + 'Resume' ].default().save( t );
|
//FLUENT[ safeFormat + 'Resume' ].default().save( t );
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
@ -10,9 +10,20 @@ Implementation of the 'validate' verb for HackMyResume.
|
|||||||
var ResumeFactory = require('../core/resume-factory');
|
var ResumeFactory = require('../core/resume-factory');
|
||||||
var SyntaxErrorEx = require('../utils/syntax-error-ex');
|
var SyntaxErrorEx = require('../utils/syntax-error-ex');
|
||||||
var chalk = require('chalk');
|
var chalk = require('chalk');
|
||||||
|
var Verb = require('../core/verb');
|
||||||
var HACKMYSTATUS = require('../core/status-codes');
|
var HACKMYSTATUS = require('../core/status-codes');
|
||||||
|
|
||||||
module.exports =
|
|
||||||
|
|
||||||
|
var ValidateVerb = module.exports = Verb.extend({
|
||||||
|
|
||||||
|
invoke: function() {
|
||||||
|
validate.apply( this, arguments );
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Validate 1 to N resumes in either FRESH or JSON Resume format.
|
Validate 1 to N resumes in either FRESH or JSON Resume format.
|
||||||
@ -99,6 +110,6 @@ Implementation of the 'validate' verb for HackMyResume.
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
Loading…
Reference in New Issue
Block a user