mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 08:20:11 +00:00
Modularize messages.
...and move strings out of error.js.
This commit is contained in:
parent
fc67f680ee
commit
17f2ebb753
@ -18,6 +18,8 @@ Error-handling routines for HackMyResume.
|
|||||||
, WRAP = require('word-wrap')
|
, WRAP = require('word-wrap')
|
||||||
, M2C = require('../utils/md2chalk.js')
|
, M2C = require('../utils/md2chalk.js')
|
||||||
, chalk = require('chalk')
|
, chalk = require('chalk')
|
||||||
|
, YAML = require('yamljs')
|
||||||
|
, printf = require('printf')
|
||||||
, SyntaxErrorEx = require('../utils/syntax-error-ex');
|
, SyntaxErrorEx = require('../utils/syntax-error-ex');
|
||||||
require('string.prototype.startswith');
|
require('string.prototype.startswith');
|
||||||
|
|
||||||
@ -32,18 +34,23 @@ Error-handling routines for HackMyResume.
|
|||||||
init: function( debug, assert ) {
|
init: function( debug, assert ) {
|
||||||
this.debug = debug;
|
this.debug = debug;
|
||||||
this.assert = assert;
|
this.assert = assert;
|
||||||
|
this.msgs = require('./msg.js').errors;
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
err: function( ex, shouldExit ) {
|
err: function( ex, shouldExit ) {
|
||||||
|
|
||||||
|
if( !this.msgs ) {
|
||||||
|
this.msgs = require('./msg.js').errors;
|
||||||
|
}
|
||||||
|
|
||||||
if( ex.pass )
|
if( ex.pass )
|
||||||
throw ex;
|
throw ex;
|
||||||
|
|
||||||
if( ex.fluenterror ) {
|
if( ex.fluenterror ) {
|
||||||
|
|
||||||
// Output the error message
|
// Output the error message
|
||||||
var objError = assembleError( ex );
|
var objError = assembleError.call( this, ex );
|
||||||
o( this[ 'format' + (objError.warning ? 'Warning' : 'Error')](
|
o( this[ 'format' + (objError.warning ? 'Warning' : 'Error')](
|
||||||
objError.msg
|
objError.msg
|
||||||
));
|
));
|
||||||
@ -95,25 +102,20 @@ Error-handling routines for HackMyResume.
|
|||||||
switch( ex.fluenterror ) {
|
switch( ex.fluenterror ) {
|
||||||
|
|
||||||
case HACKMYSTATUS.themeNotFound:
|
case HACKMYSTATUS.themeNotFound:
|
||||||
msg =
|
msg = printf( M2C( this.msgs.themeNotFound.msg, 'yellow' ), ex.data);
|
||||||
chalk.bold("Couldn't find the '" + ex.data + "' theme."),
|
|
||||||
" Please specify the name of a preinstalled FRESH theme " +
|
|
||||||
"or the path to a locally installed FRESH or JSON Resume theme.";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HACKMYSTATUS.copyCSS:
|
case HACKMYSTATUS.copyCSS:
|
||||||
msg = "Couldn't copy CSS file to destination folder.";
|
msg = M2C( this.msgs.copyCSS.msg, 'red' );
|
||||||
quit = false;
|
quit = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HACKMYSTATUS.resumeNotFound:
|
case HACKMYSTATUS.resumeNotFound:
|
||||||
msg = 'Please ' + chalk.bold('feed me a resume') +
|
msg = M2C( this.msgs.resumeNotFound.msg, 'yellow' );
|
||||||
' in FRESH or JSON Resume format.';
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HACKMYSTATUS.missingCommand:
|
case HACKMYSTATUS.missingCommand:
|
||||||
msg = "Please " +chalk.bold("give me a command") + " (";
|
msg = M2C( this.msgs.missingCommand.msg + " (", '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 ? chalk.yellow('or ') : '') +
|
return (idx === ar.length - 1 ? chalk.yellow('or ') : '') +
|
||||||
chalk.yellow.bold(v.toUpperCase());
|
chalk.yellow.bold(v.toUpperCase());
|
||||||
@ -124,49 +126,41 @@ Error-handling routines for HackMyResume.
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case HACKMYSTATUS.invalidCommand:
|
case HACKMYSTATUS.invalidCommand:
|
||||||
msg = 'Invalid command: "'+chalk.bold(ex.attempted)+'"';
|
msg = printf( M2C( this.msgs.invalidCommand.msg, 'yellow'), ex.attempted );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HACKMYSTATUS.resumeNotFoundAlt:
|
case HACKMYSTATUS.resumeNotFoundAlt:
|
||||||
msg = 'Please ' + chalk.bold('feed me a resume') +
|
msg = M2C( this.msgs.resumeNotFoundAlt.msg, 'yellow' );
|
||||||
' in either FRESH or JSON Resume format.';
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HACKMYSTATUS.inputOutputParity:
|
case HACKMYSTATUS.inputOutputParity:
|
||||||
msg = 'Please ' +
|
msg = M2C( this.msgs.inputOutputParity.msg );
|
||||||
chalk.bold('specify an output file name') +
|
|
||||||
' for every input file you wish to convert.';
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HACKMYSTATUS.createNameMissing:
|
case HACKMYSTATUS.createNameMissing:
|
||||||
msg = 'Please ' +
|
msg = M2C( this.msgs.createNameMissing.msg );
|
||||||
chalk.bold('specify the filename of the resume') + ' to create.';
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HACKMYSTATUS.pdfGeneration:
|
case HACKMYSTATUS.pdfGeneration:
|
||||||
msg = chalk.bold('PDF generation failed. ') +
|
msg = M2C( this.msgs.pdfGeneration.msg, 'bold' );
|
||||||
'Make sure wkhtmltopdf is installed and accessible from your path.';
|
|
||||||
if( ex.inner ) msg += chalk.red('\n' + ex.inner);
|
if( ex.inner ) msg += chalk.red('\n' + ex.inner);
|
||||||
withStack = true; quit = false; warn = false;
|
withStack = true; quit = false; warn = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HACKMYSTATUS.invalid:
|
case HACKMYSTATUS.invalid:
|
||||||
msg = 'Validation failed and the --assert option was ' +
|
msg = M2C( this.msgs.invalid.msg, 'red' );
|
||||||
'specified.';
|
|
||||||
warn = false;
|
warn = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HACKMYSTATUS.invalidFormat:
|
case HACKMYSTATUS.invalidFormat:
|
||||||
ex.data.forEach(function(d){ msg +=
|
ex.data.forEach(function(d){
|
||||||
'The ' + chalk.bold(ex.theme.name.toUpperCase()) +
|
msg += printf( M2C( this.msgs.invalidFormat.msg, 'bold' ),
|
||||||
" theme doesn't support the " + chalk.bold(d.format.toUpperCase()) +
|
ex.theme.name.toUpperCase(), d.format.toUpperCase());
|
||||||
" format.\n";
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HACKMYSTATUS.notOnPath:
|
case HACKMYSTATUS.notOnPath:
|
||||||
msg = ex.engine + " wasn't found on your system path or" +
|
msg = printf( M2C(this.msgs.notOnPath, 'bold'), ex.engine);
|
||||||
" is inaccessible. PDF not generated.";
|
|
||||||
quit = false;
|
quit = false;
|
||||||
warn = false;
|
warn = false;
|
||||||
break;
|
break;
|
||||||
@ -179,8 +173,8 @@ Error-handling routines for HackMyResume.
|
|||||||
case HACKMYSTATUS.parseError:
|
case HACKMYSTATUS.parseError:
|
||||||
if( SyntaxErrorEx.is( ex.inner )) {
|
if( SyntaxErrorEx.is( ex.inner )) {
|
||||||
var se = new SyntaxErrorEx( ex, ex.raw );
|
var se = new SyntaxErrorEx( ex, ex.raw );
|
||||||
msg = 'Invalid or corrupt JSON on line ' + se.line +
|
msg = printf( M2C( this.msgs.parseError.msg, 'red' ),
|
||||||
' column ' + se.col + '.';
|
se.line, se.col);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg = ex;
|
msg = ex;
|
||||||
|
18
src/cli/msg.js
Normal file
18
src/cli/msg.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
Message-handling routines for HackMyResume.
|
||||||
|
@module msg.js
|
||||||
|
@license MIT. See LICENSE.md for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
var PATH = require('path');
|
||||||
|
var YAML = require('yamljs');
|
||||||
|
|
||||||
|
var cache = module.exports = function() {
|
||||||
|
return cache ? cache : YAML.load( PATH.join(__dirname, 'msg.yml') );
|
||||||
|
}();
|
||||||
|
|
||||||
|
}());
|
@ -1,18 +1,19 @@
|
|||||||
beforeCreate:
|
events:
|
||||||
|
beforeCreate:
|
||||||
msg: Creating new **%s** resume: **%s**
|
msg: Creating new **%s** resume: **%s**
|
||||||
beforeRead:
|
beforeRead:
|
||||||
msg: Reading resume: **%s**
|
msg: Reading resume: **%s**
|
||||||
beforeTheme:
|
beforeTheme:
|
||||||
msg: Verifying theme: **%s**
|
msg: Verifying theme: **%s**
|
||||||
afterTheme:
|
afterTheme:
|
||||||
msg: Verifying outputs: ???
|
msg: Verifying outputs: ???
|
||||||
beforeMerge:
|
beforeMerge:
|
||||||
msg:
|
msg:
|
||||||
- Merging **%s**
|
- Merging **%s**
|
||||||
- " onto **%s**"
|
- " onto **%s**"
|
||||||
afterMerge:
|
afterMerge:
|
||||||
msg: Applying **%s** theme (%s format%s)
|
msg: Applying **%s** theme (%s format%s)
|
||||||
afterBuild:
|
afterBuild:
|
||||||
msg:
|
msg:
|
||||||
- "The **%s** theme says:"
|
- "The **%s** theme says:"
|
||||||
- |
|
- |
|
||||||
@ -23,24 +24,53 @@ afterBuild:
|
|||||||
http-server <resume-folder>
|
http-server <resume-folder>
|
||||||
|
|
||||||
For more information, see the README."
|
For more information, see the README."
|
||||||
beforeGenerate:
|
beforeGenerate:
|
||||||
msg:
|
msg:
|
||||||
- " (with %s)"
|
- " (with %s)"
|
||||||
- "Skipping %s resume: %s"
|
- "Skipping %s resume: %s"
|
||||||
- "Generating **%s** resume: **%s**"
|
- "Generating **%s** resume: **%s**"
|
||||||
beforeAnalyze:
|
beforeAnalyze:
|
||||||
msg: "Analyzing **%s** resume: **%s**"
|
msg: "Analyzing **%s** resume: **%s**"
|
||||||
beforeConvert:
|
beforeConvert:
|
||||||
msg: "Converting **%s** (**%s**) to **%s** (**%s**)"
|
msg: "Converting **%s** (**%s**) to **%s** (**%s**)"
|
||||||
afterValidate:
|
afterValidate:
|
||||||
msg:
|
msg:
|
||||||
- "Validating **%s** against the **%s** schema: "
|
- "Validating **%s** against the **%s** schema: "
|
||||||
- "VALID!"
|
- "VALID!"
|
||||||
- "INVALID"
|
- "INVALID"
|
||||||
- "BROKEN"
|
- "BROKEN"
|
||||||
beforePeek:
|
beforePeek:
|
||||||
msg:
|
msg:
|
||||||
- Peeking at **%s** in **%s**
|
- Peeking at **%s** in **%s**
|
||||||
- Peeking at **%s**
|
- Peeking at **%s**
|
||||||
afterPeek:
|
afterPeek:
|
||||||
msg: "The specified key **%s** was not found in **%s**."
|
msg: "The specified key **%s** was not found in **%s**."
|
||||||
|
errors:
|
||||||
|
themeNotFound:
|
||||||
|
msg: >
|
||||||
|
Couldn't find the '%s' theme. Please specify the name of a preinstalled
|
||||||
|
FRESH theme or the path to a locally installed FRESH or JSON Resume theme.
|
||||||
|
copyCSS:
|
||||||
|
msg: Couldn't copy CSS file to destination folder.
|
||||||
|
resumeNotFound:
|
||||||
|
msg: Please **feed me a resume** in FRESH or JSON Resume format.
|
||||||
|
missingCommand:
|
||||||
|
msg: Please **give me a command**
|
||||||
|
invalidCommand:
|
||||||
|
msg: Invalid command: '%s'
|
||||||
|
resumeNotFoundAlt:
|
||||||
|
msg: Please **feed me a resume** in either FRESH or JSON Resume format.
|
||||||
|
inputOutputParity:
|
||||||
|
msg: Please **specify an output file name** for every input file you wish to convert.
|
||||||
|
createNameMissing:
|
||||||
|
msg: Please **specify the filename** of the resume to create.
|
||||||
|
pdfGeneration:
|
||||||
|
msg: PDF generation failed. Make sure wkhtmltopdf is installed and accessible from your path.
|
||||||
|
invalid:
|
||||||
|
msg: Validation failed and the --assert option was specified.
|
||||||
|
invalidFormat:
|
||||||
|
msg: The **%s** theme doesn't support the **%s** format.
|
||||||
|
notOnPath:
|
||||||
|
msg: %s wasn't found on your system path or is inaccessible. PDF not generated.
|
||||||
|
parseError:
|
||||||
|
msg: Invalid or corrupt JSON on line %s column %s.
|
||||||
|
@ -35,7 +35,7 @@ Output routines for HackMyResume.
|
|||||||
|
|
||||||
init: function( opts ) {
|
init: function( opts ) {
|
||||||
this.opts = EXTEND( true, this.opts || { }, opts );
|
this.opts = EXTEND( true, this.opts || { }, opts );
|
||||||
this.msgs = YAML.load(PATH.join( __dirname, 'msg.yml' ));
|
this.msgs = YAML.load(PATH.join( __dirname, 'msg.yml' )).events;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user