mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-05 01:56:21 +00:00
Replace colors with chalk.
Chalk has a few more options and doesn't mess around with String.prototype.
This commit is contained in:
parent
d54b9a6d6c
commit
cb14452df3
@ -45,7 +45,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/hacksalot/HackMyResume",
|
||||
"dependencies": {
|
||||
"colors": "^1.1.2",
|
||||
"chalk": "^1.1.1",
|
||||
"copy": "^0.1.3",
|
||||
"fresca": "~0.2.4",
|
||||
"fresh-themes": "~0.9.3-beta",
|
||||
|
@ -9,7 +9,8 @@
|
||||
, FS = require('fs')
|
||||
, FCMD = require('../hackmycmd')
|
||||
, PATH = require('path')
|
||||
, title = ('\n*** HackMyResume v' + PKG.version + ' ***').bold.white;
|
||||
, chalk = require('chalk')
|
||||
, title = chalk.white.bold('\n*** HackMyResume v' + PKG.version + ' ***');
|
||||
|
||||
var ErrorHandler = module.exports = {
|
||||
|
||||
@ -29,46 +30,45 @@
|
||||
break;
|
||||
|
||||
case HACKMYSTATUS.resumeNotFound:
|
||||
msg = 'Please '.guide + 'feed me a resume'.guide.bold +
|
||||
' in FRESH or JSON Resume format.'.guide;
|
||||
msg = chalk.yellow('Please ') + chalk.yellow.bold('feed me a resume') +
|
||||
chalk.yellow(' in FRESH or JSON Resume format.');
|
||||
break;
|
||||
|
||||
case HACKMYSTATUS.missingCommand:
|
||||
msg = title + "\nPlease ".guide + "give me a command".guide.bold +
|
||||
" (".guide;
|
||||
msg = title + chalk.yellow("\nPlease ") + chalk.yellow.bold("give me a command") +
|
||||
chalk.yellow(" (");
|
||||
|
||||
msg += Object.keys( FCMD.verbs ).map( function(v, idx, ar) {
|
||||
return (idx === ar.length - 1 ? 'or '.guide : '') +
|
||||
v.toUpperCase().guide;
|
||||
}).join(', '.guide) + ").\n\n".guide;
|
||||
return (idx === ar.length - 1 ? chalk.yellow('or ') : '') +
|
||||
chalk.yellow.bold(v.toUpperCase());
|
||||
}).join( chalk.yellow(', ')) + chalk.yellow(").\n\n");
|
||||
|
||||
msg += FS.readFileSync(
|
||||
PATH.resolve(__dirname, '../use.txt'), 'utf8' ).info.bold;
|
||||
msg += chalk.gray(FS.readFileSync( PATH.resolve(__dirname, '../use.txt'), 'utf8' ));
|
||||
break;
|
||||
|
||||
case HACKMYSTATUS.invalidCommand:
|
||||
msg = 'Please '.guide + 'specify the output resume file'.guide.bold +
|
||||
' that should be created.'.guide;
|
||||
msg = chalk.yellow('Please ') + chalk.yellow.bold('specify the output resume file') +
|
||||
chalk.yellow(' that should be created.');
|
||||
break;
|
||||
|
||||
case HACKMYSTATUS.resumeNotFoundAlt:
|
||||
msg = 'Please '.guide + 'feed me a resume'.guide.bold +
|
||||
' in either FRESH or JSON Resume format.'.guide;
|
||||
msg = chalk.yellow('Please ') + chalk.yellow.bold('feed me a resume') +
|
||||
chalk.yellow(' in either FRESH or JSON Resume format.');
|
||||
break;
|
||||
|
||||
case HACKMYSTATUS.inputOutputParity:
|
||||
msg = 'Please '.guide + 'specify an output file name'.guide.bold +
|
||||
' for every input file you wish to convert.'.guide;
|
||||
msg = chalk.yellow('Please ') + chalk.yellow.bold('specify an output file name') +
|
||||
chalk.yellow(' for every input file you wish to convert.');
|
||||
break;
|
||||
|
||||
case HACKMYSTATUS.createNameMissing:
|
||||
msg = 'Please '.guide + 'specify the filename of the resume'.guide.bold +
|
||||
' to create.'.guide;
|
||||
msg = chalk.yellow('Please ') + chalk.yellow.bold('specify the filename of the resume') +
|
||||
chalk.yellow(' to create.');
|
||||
break;
|
||||
|
||||
case HACKMYSTATUS.wkhtmltopdf:
|
||||
msg = 'ERROR: PDF generation failed. '.red.bold + ('Make sure wkhtmltopdf is ' +
|
||||
'installed and accessible from your path.').red;
|
||||
msg = chalk.red.bold('ERROR: PDF generation failed. ') + chalk.red('Make sure wkhtmltopdf is ' +
|
||||
'installed and accessible from your path.');
|
||||
break;
|
||||
|
||||
}
|
||||
@ -83,8 +83,8 @@
|
||||
var idx = msg.indexOf('Error: ');
|
||||
var trimmed = idx === -1 ? msg : msg.substring( idx + 7 );
|
||||
if( !ex.fluenterror || ex.fluenterror < 3 ) { // TODO: magic #s
|
||||
console.log( ('ERROR: ' + trimmed.toString()).red.bold );
|
||||
console.log( ex.stack.gray);
|
||||
console.log( chalk.red.bold('ERROR: ' + trimmed.toString()) );
|
||||
console.log( chalk.gray(ex.stack) );
|
||||
}
|
||||
else {
|
||||
console.log( trimmed.toString() );
|
||||
|
@ -13,6 +13,7 @@ Definition of the ResumeFactory class.
|
||||
require('string.prototype.startswith');
|
||||
var FS = require('fs');
|
||||
var ResumeConverter = require('./convert');
|
||||
var chalk = require('chalk');
|
||||
|
||||
|
||||
|
||||
@ -85,8 +86,7 @@ Definition of the ResumeFactory class.
|
||||
try {
|
||||
|
||||
// TODO: Core should not log
|
||||
log( 'Reading '.info + /*orgFormat.toUpperCase().infoBold +*/
|
||||
'resume: '.info + fileName.cyan.bold );
|
||||
log( chalk.gray('Reading resume: ') + chalk.cyan.bold(fileName) );
|
||||
|
||||
rawData = FS.readFileSync( fileName, 'utf8' );
|
||||
return {
|
||||
|
@ -9,7 +9,8 @@ Internal resume generation logic for HackMyResume.
|
||||
|
||||
var unused = require('./utils/string')
|
||||
, PATH = require('path')
|
||||
, FS = require('fs');
|
||||
, FS = require('fs')
|
||||
, chalk = require('chalk');
|
||||
|
||||
|
||||
/**
|
||||
@ -17,7 +18,7 @@ Internal resume generation logic for HackMyResume.
|
||||
*/
|
||||
function help() {
|
||||
var manPage = FS.readFileSync( PATH.join(__dirname, 'use.txt'), 'utf8' );
|
||||
console.log( manPage.useful.bold );
|
||||
console.log( chalk.green.bold(manPage) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -25,7 +26,7 @@ Internal resume generation logic for HackMyResume.
|
||||
*/
|
||||
var v = {
|
||||
build: require('./verbs/generate'),
|
||||
analyze: require('./verbs/analyze'),
|
||||
analyze: require('./verbs/analyze'),
|
||||
validate: require('./verbs/validate'),
|
||||
convert: require('./verbs/convert'),
|
||||
new: require('./verbs/create'),
|
||||
|
26
src/index.js
26
src/index.js
@ -12,12 +12,12 @@ var SPAWNW = require('./core/spawn-watch')
|
||||
, ARGS = require( 'minimist' )
|
||||
, FCMD = require( './hackmycmd')
|
||||
, PKG = require('../package.json')
|
||||
, COLORS = require('colors')
|
||||
, FS = require('fs')
|
||||
, chalk = require('chalk')
|
||||
, PATH = require('path')
|
||||
, HACKMYSTATUS = require('./core/status-codes')
|
||||
, opts = { }
|
||||
, title = ('\n*** HackMyResume v' + PKG.version + ' ***').bold.white
|
||||
, title = chalk.white('\n*** HackMyResume v' + PKG.version + ' ***')
|
||||
, _ = require('underscore');
|
||||
|
||||
|
||||
@ -35,16 +35,16 @@ catch( ex ) {
|
||||
function main() {
|
||||
|
||||
// Colorize
|
||||
COLORS.setTheme({
|
||||
title: ['white','bold'],
|
||||
info: process.platform === 'win32' ? 'gray' : ['white','dim'],
|
||||
infoBold: ['white','dim'],
|
||||
warn: 'yellow',
|
||||
error: 'red',
|
||||
guide: 'yellow',
|
||||
status: 'gray',//['white','dim'],
|
||||
useful: 'green',
|
||||
});
|
||||
// COLORS.setTheme({
|
||||
// title: ['white','bold'],
|
||||
// info: process.platform === 'win32' ? 'gray' : ['white','dim'],
|
||||
// infoBold: ['white','dim'],
|
||||
// warn: 'yellow',
|
||||
// error: 'red',
|
||||
// guide: 'yellow',
|
||||
// status: 'gray',//['white','dim'],
|
||||
// useful: 'green',
|
||||
// });
|
||||
|
||||
// Setup
|
||||
if( process.argv.length <= 2 ) { throw { fluenterror: 4 }; }
|
||||
@ -56,7 +56,7 @@ function main() {
|
||||
var params = a._.map( function(p){ return p.toLowerCase().trim(); });
|
||||
var verb = params[0];
|
||||
if( !FCMD.verbs[ verb ] && !FCMD.alias[ verb ] ) {
|
||||
logMsg('Invalid command: "'.warn + verb.warn.bold + '"'.warn);
|
||||
logMsg(chalk.yellow('Invalid command: "') + chalk.yellow.bold(verb) + chalk.yellow('"'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,8 @@ Implementation of the 'analyze' verb for HackMyResume.
|
||||
function _analyze( resumeObject, nlzrs, opts, log ) {
|
||||
var rez = resumeObject.rez;
|
||||
var safeFormat = rez.meta.format.startsWith('FRESH') ? 'FRESH' : 'JRS';
|
||||
log('Analyzing '.useful + safeFormat.useful.bold +
|
||||
' resume: '.useful + resumeObject.file.useful.bold);
|
||||
log(chalk.cyan('Analyzing ') + chalk.cyan.bold(safeFormat) +
|
||||
chalk.cyan(' resume: ') + chalk.cyan.bold(resumeObject.file));
|
||||
var info = _.mapObject( nlzrs, function(val, key) {
|
||||
return val.run( resumeObject.rez );
|
||||
});
|
||||
|
@ -27,9 +27,9 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
var sheet = src.rez;
|
||||
var sourceFormat = ((sheet.basics && sheet.basics.imp) || sheet.imp).orgFormat === 'JRS' ? 'JRS' : 'FRESH';
|
||||
var targetFormat = sourceFormat === 'JRS' ? 'FRESH' : 'JRS';
|
||||
_log( 'Converting '.useful + src.file.useful.bold + (' (' +
|
||||
sourceFormat + ') to ').useful + dst[0].useful.bold +
|
||||
(' (' + targetFormat + ').').useful );
|
||||
_log( chalk.green('Converting ') + chalk.green.bold(src.file) + chalk.green(' (' +
|
||||
sourceFormat + ') to ') + chalk.green.bold(dst[0]) +
|
||||
chalk.green(' (' + targetFormat + ').') );
|
||||
sheet.saveAs( dst[idx], targetFormat );
|
||||
});
|
||||
};
|
||||
|
@ -18,8 +18,8 @@ Implementation of the 'create' verb for HackMyResume.
|
||||
if( !src || !src.length ) throw { fluenterror: 8 };
|
||||
src.forEach( function( t ) {
|
||||
var safeFormat = opts.format.toUpperCase();
|
||||
_log('Creating new '.useful +safeFormat.useful.bold +
|
||||
' resume: '.useful + t.useful.bold);
|
||||
_log(chalk.green('Creating new ') + chalk.green.bold(safeFormat) +
|
||||
chalk.green(' resume: ') + chalk.green.bold(t));
|
||||
MKDIRP.sync( PATH.dirname( t ) ); // Ensure dest folder exists;
|
||||
FLUENT[ safeFormat + 'Resume' ].default().save( t );
|
||||
});
|
||||
|
@ -21,6 +21,7 @@ Implementation of the 'generate' verb for HackMyResume.
|
||||
, _ = require('underscore')
|
||||
, _fmts = require('../core/default-formats')
|
||||
, extend = require('../utils/extend')
|
||||
, chalk = require('chalk')
|
||||
, _err, _log, rez;
|
||||
|
||||
|
||||
@ -64,9 +65,10 @@ Implementation of the 'generate' verb for HackMyResume.
|
||||
var msg = '';
|
||||
var rezRep = _.reduceRight( sheets, function( a, b, idx ) {
|
||||
msg += ((idx == sheets.length - 2) ?
|
||||
'Merging '.gray + a.rez.imp.fileName : '') + ' onto '.gray + b.rez.fileName;
|
||||
chalk.gray('Merging ') + a.rez.imp.fileName : '') + chalk.gray(' onto ') + b.rez.fileName;
|
||||
return extend( true, b.rez, a.rez );
|
||||
});
|
||||
|
||||
rez = rezRep.rez;
|
||||
msg && _log(msg);
|
||||
|
||||
@ -102,9 +104,9 @@ Implementation of the 'generate' verb for HackMyResume.
|
||||
, fName = PATH.basename(f, '.' + fType)
|
||||
, theFormat;
|
||||
|
||||
_log( 'Generating '.useful +
|
||||
targInfo.fmt.outFormat.toUpperCase().useful.bold +
|
||||
' resume: '.useful + PATH.relative(process.cwd(), f ).useful.bold );
|
||||
_log( chalk.green('Generating ') +
|
||||
chalk.green.bold(targInfo.fmt.outFormat.toUpperCase()) +
|
||||
chalk.green(' resume: ') + chalk.green.bold( PATH.relative(process.cwd(), f )) );
|
||||
|
||||
// If targInfo.fmt.files exists, this format is backed by a document.
|
||||
// Fluent/FRESH themes are handled here.
|
||||
@ -273,8 +275,8 @@ Implementation of the 'generate' verb for HackMyResume.
|
||||
|
||||
// Output a message TODO: core should not log
|
||||
var numFormats = Object.keys(theTheme.formats).length;
|
||||
_log( 'Applying '.info + theTheme.name.toUpperCase().infoBold +
|
||||
(' theme (' + numFormats + ' formats)').info);
|
||||
_log( chalk.gray('Applying ') + chalk.gray.bold(theTheme.name.toUpperCase()) +
|
||||
chalk.gray(' theme (' + numFormats + ' formats)'));
|
||||
return theTheme;
|
||||
}
|
||||
|
||||
|
@ -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) );
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user