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