1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-25 09:50:11 +00:00

Continue moving logging out of core.

This commit is contained in:
hacksalot 2016-01-09 15:49:08 -05:00
parent 732bc9809a
commit 3aabb5028d
5 changed files with 88 additions and 51 deletions

View File

@ -34,7 +34,13 @@ Event code definitions.
afterMerge: 10,
beforeGenerate: 11,
afterGenerate: 12
afterGenerate: 12,
beforeAnalyze: 13,
afterAnalyze: 14,
beforeConvert: 15,
afterConvert: 16
};

View File

@ -121,6 +121,59 @@ Output routines for HackMyResume.
chalk.green(' resume') + suffix + chalk.green(': ') +
chalk.green.bold( PATH.relative(process.cwd(), evt.file )) );
break;
case HME.beforeAnalyze:
this.log(chalk.cyan('Analyzing ') + chalk.cyan.bold(evt.fmt) +
chalk.cyan(' resume: ') + chalk.cyan.bold(evt.file));
break;
case HME.afterAnalyze:
var info = evt.info;
var padding = 20;
this.log(chalk.cyan.bold('\nSECTIONS') + chalk.cyan(' (') +
chalk.white.bold(_.keys(info.totals).length) + chalk.cyan('):\n'));
_.each( info.totals, function(tot, key) {
this.log(chalk.cyan(pad(key + ': ',20)) +
chalk.cyan.bold(pad(tot.toString(),5)));
}, this);
this.log();
this.log(chalk.cyan.bold('COVERAGE') + chalk.cyan(' (') + chalk.white.bold( info.coverage.pct ) + chalk.cyan('):\n'));
this.log(chalk.cyan(pad('Total Days: ', padding)) + chalk.cyan.bold( pad(info.coverage.duration.total.toString(),5) ));
this.log(chalk.cyan(pad('Employed: ', padding)) + chalk.cyan.bold( pad((info.coverage.duration.total - info.coverage.duration.gaps).toString(),5) ));
this.log(chalk.cyan(pad('Gaps: ', padding + 4)) + chalk.cyan.bold(info.coverage.gaps.length) + chalk.cyan(' [') + info.coverage.gaps.map(function(g) {
var clr = 'green';
if( g.duration > 35 ) clr = 'yellow';
if( g.duration > 90 ) clr = 'red';
return chalk[clr].bold( g.duration) ;
}).join(', ') + chalk.cyan(']') );
this.log(chalk.cyan(pad('Overlaps: ', padding + 4)) + chalk.cyan.bold(info.coverage.overlaps.length) + chalk.cyan(' [') + info.coverage.overlaps.map(function(ol) {
var clr = 'green';
if( ol.duration > 35 ) clr = 'yellow';
if( ol.duration > 90 ) clr = 'red';
return chalk[clr].bold( ol.duration) ;
}).join(', ') + chalk.cyan(']') );
var tot = 0;
this.log();
this.log( chalk.cyan.bold('KEYWORDS') + chalk.cyan(' (') + chalk.white.bold( info.keywords.length ) +
chalk.cyan('):\n\n') +
info.keywords.map(function(g) {
tot += g.count;
return chalk.cyan( pad(g.name + ': ', padding) ) + chalk.cyan.bold( pad( g.count.toString(), 5 )) + chalk.cyan(' mentions');
}).join('\n'));
this.log(chalk.cyan( pad('TOTAL: ', padding) ) + chalk.white.bold( pad( tot.toString(), 5 )) + chalk.cyan(' mentions'));
break;
case HME.beforeConvert:
// TODO: Core should not log
this.log( chalk.green('Converting ') + chalk.green.bold(evt.srcFile) +
chalk.green(' (' + evt.srcFmt + ') to ') + chalk.green.bold(evt.dstFile) +
chalk.green(' (' + evt.dstFmt + ').'));
break;
}
}

View File

@ -12,15 +12,20 @@ Implementation of the 'analyze' verb for HackMyResume.
var MKDIRP = require('mkdirp')
, PATH = require('path')
, HME = require('../core/event-codes')
, _ = require('underscore')
, ResumeFactory = require('../core/resume-factory')
, Verb = require('../core/verb')
, Verb = require('../core/verb')
, chalk = require('chalk');
var AnalyzeVerb = module.exports = Verb.extend({
init: function() {
this._super('analyze');
},
invoke: function() {
analyze.apply( this, arguments );
}
@ -33,17 +38,17 @@ Implementation of the 'analyze' verb for HackMyResume.
Run the 'analyze' command.
*/
function analyze( sources, dst, opts, logger ) {
this.stat('begin');
var _log = logger || console.log;
if( !sources || !sources.length ) throw { fluenterror: 3 };
var nlzrs = _loadInspectors();
sources.forEach( function(src) {
_.each(sources, function(src) {
var result = ResumeFactory.loadOne( src, {
log: _log, format: 'FRESH', objectify: true, throw: false
});
result.error || _analyze( result, nlzrs, opts, _log );
});
result.error || _analyze.call(this, result, nlzrs, opts, _log );
}, this);
this.stat('end');
}
@ -58,45 +63,11 @@ Implementation of the 'analyze' verb for HackMyResume.
'FRESH' : 'JRS';
var padding = 20;
log(chalk.cyan('Analyzing ') + chalk.cyan.bold(safeFormat) +
chalk.cyan(' resume: ') + chalk.cyan.bold(resumeObject.file));
this.stat( HME.beforeAnalyze, { fmt: safeFormat, file: resumeObject.file });
var info = _.mapObject( nlzrs, function(val, key) {
return val.run( resumeObject.rez );
});
log(chalk.cyan.bold('\nSECTIONS') + chalk.cyan(' (') + chalk.white.bold(_.keys(info.totals).length) + chalk.cyan('):\n'));
var pad = require('string-padding');
_.each( info.totals, function(tot, key) {
log(chalk.cyan(pad(key + ': ',20)) + chalk.cyan.bold(pad(tot.toString(),5)));
});
log();
log(chalk.cyan.bold('COVERAGE') + chalk.cyan(' (') + chalk.white.bold( info.coverage.pct ) + chalk.cyan('):\n'));
log(chalk.cyan(pad('Total Days: ', padding)) + chalk.cyan.bold( pad(info.coverage.duration.total.toString(),5) ));
log(chalk.cyan(pad('Employed: ', padding)) + chalk.cyan.bold( pad((info.coverage.duration.total - info.coverage.duration.gaps).toString(),5) ));
log(chalk.cyan(pad('Gaps: ', padding + 4)) + chalk.cyan.bold(info.coverage.gaps.length) + chalk.cyan(' [') + info.coverage.gaps.map(function(g) {
var clr = 'green';
if( g.duration > 35 ) clr = 'yellow';
if( g.duration > 90 ) clr = 'red';
return chalk[clr].bold( g.duration) ;
}).join(', ') + chalk.cyan(']') );
log(chalk.cyan(pad('Overlaps: ', padding + 4)) + chalk.cyan.bold(info.coverage.overlaps.length) + chalk.cyan(' [') + info.coverage.overlaps.map(function(ol) {
var clr = 'green';
if( ol.duration > 35 ) clr = 'yellow';
if( ol.duration > 90 ) clr = 'red';
return chalk[clr].bold( ol.duration) ;
}).join(', ') + chalk.cyan(']') );
var tot = 0;
log();
log( chalk.cyan.bold('KEYWORDS') + chalk.cyan(' (') + chalk.white.bold( info.keywords.length ) +
chalk.cyan('):\n\n') +
info.keywords.map(function(g) {
tot += g.count;
return chalk.cyan( pad(g.name + ': ', padding) ) + chalk.cyan.bold( pad( g.count.toString(), 5 )) + chalk.cyan(' mentions');
}).join('\n'));
log(chalk.cyan( pad('TOTAL: ', padding) ) + chalk.white.bold( pad( tot.toString(), 5 )) + chalk.cyan(' mentions'));
this.stat( HME.afterAnalyze, { info: info } );
}

View File

@ -12,12 +12,18 @@ Implementation of the 'convert' verb for HackMyResume.
var ResumeFactory = require('../core/resume-factory')
, chalk = require('chalk')
, Verb = require('../core/verb')
, HACKMYSTATUS = require('../core/status-codes');
, Verb = require('../core/verb')
, HACKMYSTATUS = require('../core/status-codes')
, _ = require('underscore')
, HME = require('../core/event-codes');
var ConvertVerb = module.exports = Verb.extend({
init: function() {
this._super('convert');
},
invoke: function() {
convert.apply( this, arguments );
}
@ -50,7 +56,7 @@ Implementation of the 'convert' verb for HackMyResume.
}
// Load source resumes
srcs.forEach( function( src, idx ) {
_.each(srcs, function( src, idx ) {
// Load the resume
var rinfo = ResumeFactory.loadOne( src, {
@ -62,15 +68,12 @@ Implementation of the 'convert' verb for HackMyResume.
'JRS' : 'FRESH'
, targetFormat = srcFmt === 'JRS' ? 'FRESH' : 'JRS';
// TODO: Core should not log
_log( chalk.green('Converting ') + chalk.green.bold(rinfo.file) +
chalk.green(' (' + srcFmt + ') to ') + chalk.green.bold(dst[idx]) +
chalk.green(' (' + targetFormat + ').'));
this.stat(HME.beforeConvert, { srcFile: rinfo.file, srcFmt: srcFmt, dstFile: dst[idx], dstFmt: targetFormat });
// Save it to the destination format
s.saveAs( dst[idx], targetFormat );
});
}, this);
}

View File

@ -17,6 +17,10 @@ Implementation of the 'validate' verb for HackMyResume.
var ValidateVerb = module.exports = Verb.extend({
init: function() {
this._super('validate');
},
invoke: function() {
validate.apply( this, arguments );
}