1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-22 08:20:11 +00:00
This commit is contained in:
hacksalot 2016-01-26 11:43:49 -05:00
parent f098ed507f
commit a07faf6d50
2 changed files with 122 additions and 189 deletions

301
dist/cli/out.js vendored
View File

@ -1,230 +1,163 @@
/** /**
Output routines for HackMyResume. Output routines for HackMyResume.
@license MIT. See LICENSE.md for details. @license MIT. See LICENSE.md for details.
@module out.js @module cli/out
*/ */
(function() { (function() {
var Class, EXTEND, FS, HANDLEBARS, HME, LO, M2C, OutputHandler, PATH, YAML, _, chalk, dbgStyle, pad, printf;
chalk = require('chalk');
HME = require('hackmycore/dist/core/event-codes');
_ = require('underscore');
Class = require('hackmycore/dist/utils/class.js');
M2C = require('hackmycore/dist/utils/md2chalk.js');
PATH = require('path');
LO = require('lodash');
FS = require('fs');
EXTEND = require('extend');
HANDLEBARS = require('handlebars');
YAML = require('yamljs');
printf = require('printf');
pad = require('string-padding');
dbgStyle = 'cyan';
/** A stateful output module. All HMR console output handled here. */
var chalk = require('chalk') OutputHandler = module.exports = Class.extend({
, HME = require('hackmycore/dist/core/event-codes') init: function(opts) {
, _ = require('underscore') this.opts = EXTEND(true, this.opts || {}, opts);
, Class = require('hackmycore/dist/utils/class.js') return this.msgs = YAML.load(PATH.join(__dirname, 'msg.yml')).events;
, M2C = require('hackmycore/dist/utils/md2chalk.js')
, PATH = require('path')
, LO = require('lodash')
, FS = require('fs')
, EXTEND = require('extend')
, HANDLEBARS = require('handlebars')
, YAML = require('yamljs')
, printf = require('printf')
, pad = require('string-padding')
, dbgStyle = 'cyan';
chalk.enabled = false;
/**
A stateful output module. All HMR console output handled here.
*/
var OutputHandler = module.exports = Class.extend({
init: function( opts ) {
this.opts = EXTEND( true, this.opts || { }, opts );
this.msgs = YAML.load(PATH.join( __dirname, 'msg.yml' )).events;
}, },
log: function(msg) {
var finished;
log: function( msg ) {
msg = msg || ''; msg = msg || '';
var printf = require('printf'); printf = require('printf');
var finished = printf.apply( printf, arguments ); finished = printf.apply(printf, arguments);
this.opts.silent || console.log( finished ); return this.opts.silent || console.log(finished);
}, },
"do": function(evt) {
var L, WRAP, info, msg, numFormats, output, rawTpl, ref, ref1, ref2, sty, style, suffix, template, that, themeName, tot;
that = this;
do: function( evt ) { L = function() {
return that.log.apply(that, arguments);
var that = this; };
function L() { switch (evt.sub) {
that.log.apply( that, arguments );
}
switch( evt.sub ) {
case HME.begin: case HME.begin:
this.opts.debug && return this.opts.debug && L(M2C(this.msgs.begin.msg, dbgStyle), evt.cmd.toUpperCase());
L( M2C( this.msgs.begin.msg, dbgStyle), evt.cmd.toUpperCase() );
break;
case HME.error:
break;
case HME.beforeCreate: case HME.beforeCreate:
L( M2C( this.msgs.beforeCreate.msg, 'green' ), evt.fmt, evt.file ); L(M2C(this.msgs.beforeCreate.msg, 'green'), evt.fmt, evt.file);
break; break;
case HME.beforeRead:
break;
case HME.afterRead:
break;
case HME.beforeTheme: case HME.beforeTheme:
this.opts.debug && return this.opts.debug && L(M2C(this.msgs.beforeTheme.msg, dbgStyle), evt.theme.toUpperCase());
L( M2C( this.msgs.beforeTheme.msg, dbgStyle), evt.theme.toUpperCase() );
break;
case HME.afterParse: case HME.afterParse:
L( return L(M2C(this.msgs.afterRead.msg, 'gray', 'white.dim'), evt.fmt.toUpperCase(), evt.file);
M2C( this.msgs.afterRead.msg, 'gray', 'white.dim'), evt.fmt.toUpperCase(), evt.file
);
break;
case HME.afterTheme:
break;
case HME.beforeMerge: case HME.beforeMerge:
var msg = ''; msg = '';
evt.f.reverse().forEach( function( a, idx ) { evt.f.reverse().forEach(function(a, idx) {
msg += printf( return msg += printf((idx === 0 ? this.msgs.beforeMerge.msg[0] : this.msgs.beforeMerge.msg[1]), a.file);
((idx === 0) ?
this.msgs.beforeMerge.msg[0] :
this.msgs.beforeMerge.msg[1] ), a.file
);
}, this); }, this);
L( M2C(msg, evt.mixed ? 'yellow' : 'gray', 'white.dim') ); return L(M2C(msg, (ref = evt.mixed) != null ? ref : {
break; 'yellow': 'gray'
}, 'white.dim'));
case HME.afterMerge:
break;
case HME.applyTheme: case HME.applyTheme:
this.theme = evt.theme; this.theme = evt.theme;
var numFormats = Object.keys( evt.theme.formats ).length; numFormats = Object.keys(evt.theme.formats).length;
L( M2C(this.msgs.applyTheme.msg, evt.status === 'error' ? 'red' : 'gray', evt.status === 'error' ? 'bold' : 'white.dim'), return L(M2C(this.msgs.applyTheme.msg, evt.status === 'error' ? 'red' : 'gray', evt.status === 'error' ? 'bold' : 'white.dim'), evt.theme.name.toUpperCase(), numFormats, (ref1 = numFormats === 1) != null ? ref1 : {
evt.theme.name.toUpperCase(), '': 's'
numFormats, ( numFormats === 1 ? '' : 's') ); });
break;
case HME.end: case HME.end:
if( evt.cmd === 'build' ) { if (evt.cmd === 'build') {
var themeName = this.theme.name.toUpperCase(); themeName = this.theme.name.toUpperCase();
if( this.opts.tips && (this.theme.message || this.theme.render) ) { if (this.opts.tips && (this.theme.message || this.theme.render)) {
var WRAP = require('word-wrap'); WRAP = require('word-wrap');
if( this.theme.message ) { if (this.theme.message) {
L( M2C( this.msgs.afterBuild.msg[0], 'cyan' ), themeName ); L(M2C(this.msgs.afterBuild.msg[0], 'cyan'), themeName);
L( M2C( this.theme.message, 'white' )); return L(M2C(this.theme.message, 'white'));
} } else if (this.theme.render) {
else if ( this.theme.render ) { L(M2C(this.msgs.afterBuild.msg[0], 'cyan'), themeName);
L( M2C( this.msgs.afterBuild.msg[0], 'cyan'), themeName); return L(M2C(this.msgs.afterBuild.msg[1], 'white'));
L( M2C( this.msgs.afterBuild.msg[1], 'white'));
} }
} }
} }
break; break;
case HME.afterGenerate: case HME.afterGenerate:
var suffix = ''; suffix = '';
if( evt.fmt === 'pdf' ) { if (evt.fmt === 'pdf') {
if( this.opts.pdf ) { if (this.opts.pdf) {
if( this.opts.pdf !== 'none' ) { if (this.opts.pdf !== 'none') {
suffix = printf( M2C( this.msgs.afterGenerate.msg[0], evt.error ? 'red' : 'green' ), this.opts.pdf ); suffix = printf(M2C(this.msgs.afterGenerate.msg[0], evt.error ? 'red' : 'green'), this.opts.pdf);
} } else {
else { L(M2C(this.msgs.afterGenerate.msg[1], 'gray'), evt.fmt.toUpperCase(), evt.file);
L( M2C( this.msgs.afterGenerate.msg[1], 'gray' ),
evt.fmt.toUpperCase(), evt.file );
return; return;
} }
} }
} }
return L(M2C(this.msgs.afterGenerate.msg[2] + suffix, evt.error ? 'red' : 'green'), pad(evt.fmt.toUpperCase(), 4, null, pad.RIGHT), PATH.relative(process.cwd(), evt.file));
L( M2C( this.msgs.afterGenerate.msg[2] + suffix, evt.error ? 'red' : 'green' ),
pad(evt.fmt.toUpperCase(),4,null,pad.RIGHT),
PATH.relative(process.cwd(), evt.file ));
break;
case HME.beforeAnalyze: case HME.beforeAnalyze:
L( M2C( this.msgs.beforeAnalyze.msg, 'green' ), evt.fmt, evt.file); return L(M2C(this.msgs.beforeAnalyze.msg, 'green'), evt.fmt, evt.file);
break;
case HME.afterAnalyze: case HME.afterAnalyze:
var info = evt.info; info = evt.info;
var rawTpl = FS.readFileSync( PATH.join( __dirname, 'analyze.hbs' ), 'utf8'); rawTpl = FS.readFileSync(PATH.join(__dirname, 'analyze.hbs'), 'utf8');
HANDLEBARS.registerHelper( require('hackmycore/dist/helpers/console-helpers') ); HANDLEBARS.registerHelper(require('hackmycore/dist/helpers/console-helpers'));
var template = HANDLEBARS.compile(rawTpl, { strict: false, assumeObjects: false }); template = HANDLEBARS.compile(rawTpl, {
var tot = 0; strict: false,
info.keywords.forEach(function(g) { tot += g.count; }); assumeObjects: false
});
tot = 0;
info.keywords.forEach(function(g) {
return tot += g.count;
});
info.keywords.totalKeywords = tot; info.keywords.totalKeywords = tot;
var output = template( info ); output = template(info);
this.log( chalk.cyan(output) ); return this.log(chalk.cyan(output));
break;
case HME.beforeConvert: case HME.beforeConvert:
L( M2C( this.msgs.beforeConvert.msg, 'green' ), return L(M2C(this.msgs.beforeConvert.msg, 'green'), evt.srcFile, evt.srcFmt, evt.dstFile, evt.dstFmt);
evt.srcFile, evt.srcFmt, evt.dstFile, evt.dstFmt
);
break;
case HME.afterInlineConvert: case HME.afterInlineConvert:
L( M2C( this.msgs.afterInlineConvert.msg, 'gray', 'white.dim' ), return L(M2C(this.msgs.afterInlineConvert.msg, 'gray', 'white.dim'), evt.file, evt.fmt);
evt.file, evt.fmt );
break;
case HME.afterValidate: case HME.afterValidate:
var style = evt.isValid ? 'green' : 'yellow'; style = (ref2 = evt.isValid) != null ? ref2 : {
L( 'green': 'yellow'
M2C( this.msgs.afterValidate.msg[0], 'white' ) + };
chalk[style].bold( evt.isValid ? L(M2C(this.msgs.afterValidate.msg[0], 'white') + chalk[style].bold(evt.isValid ? this.msgs.afterValidate.msg[1] : this.msgs.afterValidate.msg[2]), evt.file, evt.fmt);
this.msgs.afterValidate.msg[1] : if (evt.errors) {
this.msgs.afterValidate.msg[2] ), return _.each(evt.errors, function(err, idx) {
evt.file, evt.fmt return L(chalk.yellow.bold('--> ') + chalk.yellow(err.field.replace('data.', 'resume.').toUpperCase() + ' ' + err.message));
);
if( evt.errors ) {
_.each(evt.errors, function(err,idx) {
L( chalk.yellow.bold('--> ') +
chalk.yellow(err.field.replace('data.','resume.').toUpperCase() + ' ' +
err.message) );
}, this); }, this);
} }
break; break;
case HME.beforePeek:
// if( evt.target )
// L(M2C(this.msgs.beforePeek.msg[0], evt.isError ? 'red' : 'green'), evt.target, evt.file);
// else
// L(M2C(this.msgs.beforePeek.msg[1], evt.isError ? 'red' : 'green'), evt.file);
break;
case HME.afterPeek: case HME.afterPeek:
var sty = evt.error ? 'red' : ( evt.target !== undefined ? 'green' : 'yellow' ); sty = evt.error ? 'red' : (evt.target !== void 0 ? 'green' : 'yellow');
if( evt.requested ) if (evt.requested) {
L(M2C(this.msgs.beforePeek.msg[0], sty), evt.requested, evt.file); L(M2C(this.msgs.beforePeek.msg[0], sty), evt.requested, evt.file);
else } else {
L(M2C(this.msgs.beforePeek.msg[1], sty), evt.file); L(M2C(this.msgs.beforePeek.msg[1], sty), evt.file);
}
if( evt.target !== undefined ) if (evt.target !== void 0) {
console.dir( evt.target, { depth: null, colors: true } ); return console.dir(evt.target, {
else if( !evt.error ) depth: null,
L(M2C( this.msgs.afterPeek.msg, 'yellow'), evt.requested, evt.file); colors: true
break; });
} else if (!evt.error) {
return L(M2C(this.msgs.afterPeek.msg, 'yellow'), evt.requested, evt.file);
}
} }
} }
}); });
}).call(this);
}());

View File

@ -93,14 +93,14 @@ OutputHandler = module.exports = Class.extend
if evt.fmt == 'pdf' if evt.fmt == 'pdf'
if this.opts.pdf if this.opts.pdf
if this.opts.pdf != 'none' if this.opts.pdf != 'none'
suffix = printf( M2C( this.msgs.afterGenerate.msg[0], evt.error ? 'red' : 'green' ), this.opts.pdf ) suffix = printf( M2C( this.msgs.afterGenerate.msg[0], if evt.error then 'red' else 'green' ), this.opts.pdf )
else else
L( M2C( this.msgs.afterGenerate.msg[1], 'gray' ), evt.fmt.toUpperCase(), evt.file ); L( M2C( this.msgs.afterGenerate.msg[1], 'gray' ), evt.fmt.toUpperCase(), evt.file )
return return
L( M2C( this.msgs.afterGenerate.msg[2] + suffix, evt.error ? 'red' : 'green' ), L( M2C( this.msgs.afterGenerate.msg[2] + suffix, if evt.error then 'red' else 'green' ),
pad(evt.fmt.toUpperCase(),4,null,pad.RIGHT), pad( evt.fmt.toUpperCase(),4,null,pad.RIGHT ),
PATH.relative(process.cwd(), evt.file )); PATH.relative( process.cwd(), evt.file ) );
when HME.beforeAnalyze when HME.beforeAnalyze
L( M2C( this.msgs.beforeAnalyze.msg, 'green' ), evt.fmt, evt.file) L( M2C( this.msgs.beforeAnalyze.msg, 'green' ), evt.fmt, evt.file)