1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-15 10:07:07 +01:00

Replace colors with chalk.

Chalk has a few more options and doesn't mess around with
String.prototype.
This commit is contained in:
hacksalot
2016-01-01 04:44:14 -05:00
parent d54b9a6d6c
commit cb14452df3
10 changed files with 72 additions and 68 deletions

View File

@ -9,6 +9,7 @@ Implementation of the 'validate' verb for HackMyResume.
var FS = require('fs');
var ResumeFactory = require('../core/resume-factory');
var SyntaxErrorEx = require('../utils/syntax-error-ex');
var chalk = require('chalk');
module.exports =
@ -31,25 +32,25 @@ Implementation of the 'validate' verb for HackMyResume.
var result = ResumeFactory.loadOne( src, function(){}, null, false );
if( result.error ) {
_log( 'Validating '.info + src.infoBold + ' against '.info + 'AUTO'.infoBold + ' schema:'.info + ' BROKEN'.red.bold );
_log( chalk.white('Validating ') + chalk.gray.bold(src) + chalk.white(' against ') + chalk.gray.bold('AUTO') + chalk.white(' schema:') + chalk.red.bold(' BROKEN') );
var ex = result.error; // alias
if ( ex instanceof SyntaxError) {
var info = new SyntaxErrorEx( ex, result.raw );
_log( ('--> '.warn.bold + src.toUpperCase() + ' contains invalid JSON on line ' +
info.line + ' column ' + info.col + '.').warn +
' Unable to validate.'.warn );
_log( (' INTERNAL: ' + ex).warn );
_log( chalk.red.bold('--> ') + chalk.red(src.toUpperCase() + ' contains invalid JSON on line ' +
info.line + ' column ' + info.col + '.') +
chalk.red(' Unable to validate.') );
_log( chalk.red(' INTERNAL: ' + ex) );
}
else {
_log(('ERROR: ' + ex.toString()).warn.bold);
_log(chalk.red.bold('ERROR: ' + ex.toString()));
}
return;
}
var json = result.json;
var isValid = false;
var style = 'useful';
var style = 'green';
var errors = [];
var fmt = json.meta && (json.meta.format==='FRESH@0.1.0') ? 'fresh':'jars';
@ -62,7 +63,7 @@ Implementation of the 'validate' verb for HackMyResume.
isValid = validate( json );
if( !isValid ) {
style = 'warn';
style = 'yellow';
errors = validate.errors;
}
@ -71,14 +72,14 @@ Implementation of the 'validate' verb for HackMyResume.
return;
}
_log( 'Validating '.info + result.file.infoBold + ' against '.info +
fmt.replace('jars','JSON Resume').toUpperCase().infoBold +
' schema: '.info + (isValid ? 'VALID!' : 'INVALID')[style].bold );
_log( chalk.white('Validating ') + chalk.white.bold(result.file) + chalk.white(' against ') +
chalk.white.bold(fmt.replace('jars','JSON Resume').toUpperCase()) +
chalk.white(' schema: ') + chalk[style].bold(isValid ? 'VALID!' : 'INVALID') );
errors.forEach(function(err,idx) {
_log( '--> '.bold.yellow +
(err.field.replace('data.','resume.').toUpperCase() + ' ' +
err.message).yellow );
_log( chalk.yellow.bold('--> ') +
chalk.yellow(err.field.replace('data.','resume.').toUpperCase() + ' ' +
err.message) );
});
});