mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 16:30:11 +00:00
Improve validation and color-coding.
This commit is contained in:
parent
e44239b24a
commit
9fbab27d73
@ -33,6 +33,7 @@
|
|||||||
"homepage": "https://github.com/fluentdesk/fluentcv",
|
"homepage": "https://github.com/fluentdesk/fluentcv",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"FRESCA": "fluentdesk/FRESCA",
|
"FRESCA": "fluentdesk/FRESCA",
|
||||||
|
"colors": "^1.1.2",
|
||||||
"fluent-themes": "0.4.0-beta",
|
"fluent-themes": "0.4.0-beta",
|
||||||
"fs-extra": "^0.24.0",
|
"fs-extra": "^0.24.0",
|
||||||
"html": "0.0.10",
|
"html": "0.0.10",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
Internal resume generation logic for FluentCV.
|
Internal resume generation logic for FluentCV.
|
||||||
@license MIT. Copyright (c) 2015 James M. Devlin / FluentDesk
|
@license MIT. Copyright (c) 2015 James M. Devlin / FluentDesk
|
||||||
|
@module fluentcmd.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
@ -14,6 +15,7 @@ module.exports = function () {
|
|||||||
, FLUENT = require('./fluentlib')
|
, FLUENT = require('./fluentlib')
|
||||||
, PATH = require('path')
|
, PATH = require('path')
|
||||||
, MKDIRP = require('mkdirp')
|
, MKDIRP = require('mkdirp')
|
||||||
|
, COLORS = require('colors')
|
||||||
, rez, _log, _err;
|
, rez, _log, _err;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,15 +38,15 @@ module.exports = function () {
|
|||||||
// Load input resumes...
|
// Load input resumes...
|
||||||
if(!src || !src.length) { throw { fluenterror: 3 }; }
|
if(!src || !src.length) { throw { fluenterror: 3 }; }
|
||||||
var sheets = src.map( function( res ) {
|
var sheets = src.map( function( res ) {
|
||||||
_log( 'Reading JSON resume: ' + res );
|
_log( 'Reading '.gray + 'SOURCE' + ' resume: '.gray + res.cyan.bold );
|
||||||
return (new FLUENT.FRESHResume()).open( res );
|
return (new FLUENT.FRESHResume()).open( res );
|
||||||
});
|
});
|
||||||
|
|
||||||
// Merge input resumes...
|
// Merge input resumes...
|
||||||
var msg = '';
|
var msg = '';
|
||||||
rez = _.reduceRight( sheets, function( a, b, idx ) {
|
rez = _.reduceRight( sheets, function( a, b, idx ) {
|
||||||
msg += ((idx == sheets.length - 2) ? 'Merging ' + a.imp.fileName : '')
|
msg += ((idx == sheets.length - 2) ? 'Merging '.gray + a.imp.fileName : '')
|
||||||
+ ' onto ' + b.imp.fileName;
|
+ ' onto '.gray + b.imp.fileName;
|
||||||
return extend( true, b, a );
|
return extend( true, b, a );
|
||||||
});
|
});
|
||||||
msg && _log(msg);
|
msg && _log(msg);
|
||||||
@ -63,8 +65,8 @@ module.exports = function () {
|
|||||||
// Load the theme
|
// Load the theme
|
||||||
var theTheme = new FLUENT.Theme().open( tFolder );
|
var theTheme = new FLUENT.Theme().open( tFolder );
|
||||||
_opts.themeObj = theTheme;
|
_opts.themeObj = theTheme;
|
||||||
_log( 'Applying ' + theTheme.name.toUpperCase() + ' theme (' +
|
_log( 'Applying '.yellow + theTheme.name.toUpperCase().yellow.bold + (' theme (' +
|
||||||
Object.keys(theTheme.formats).length + ' formats)' );
|
Object.keys(theTheme.formats).length + ' formats)').yellow );
|
||||||
|
|
||||||
// Expand output resumes... (can't use map() here)
|
// Expand output resumes... (can't use map() here)
|
||||||
var targets = [], that = this;
|
var targets = [], that = this;
|
||||||
@ -100,8 +102,8 @@ module.exports = function () {
|
|||||||
var fObj = _.property( fi.fmt.pre )( theme.formats );
|
var fObj = _.property( fi.fmt.pre )( theme.formats );
|
||||||
var fOut = path.join( f.substring( 0, f.lastIndexOf('.')+1 ) + fObj.pre);
|
var fOut = path.join( f.substring( 0, f.lastIndexOf('.')+1 ) + fObj.pre);
|
||||||
|
|
||||||
_log( 'Generating ' + fi.fmt.title.toUpperCase() + ' resume: ' +
|
_log( 'Generating '.green + fi.fmt.title.toUpperCase().green.bold + ' resume: '.green +
|
||||||
path.relative(process.cwd(), f ) );
|
path.relative(process.cwd(), f ).green.bold );
|
||||||
|
|
||||||
var theFormat = _fmts.filter(
|
var theFormat = _fmts.filter(
|
||||||
function( fmt ) { return fmt.name === fi.fmt.pre; })[0];
|
function( fmt ) { return fmt.name === fi.fmt.pre; })[0];
|
||||||
@ -127,14 +129,57 @@ module.exports = function () {
|
|||||||
_log = logger || console.log;
|
_log = logger || console.log;
|
||||||
if( !src || !src.length ) { throw { fluenterror: 3 }; }
|
if( !src || !src.length ) { throw { fluenterror: 3 }; }
|
||||||
var isValid = true;
|
var isValid = true;
|
||||||
var sheets = src.map( function( res ) {
|
|
||||||
var sheet = (new FLUENT.FRESHResume()).open( res );
|
var validator = require('is-my-json-valid');
|
||||||
var valid = sheet.isValid();
|
var schemas = {
|
||||||
_log( 'Validating JSON resume: ' + res +
|
fresh: require('FRESCA'),
|
||||||
(valid ? ' (VALID)' : ' (INVALID)'));
|
jars: require('./core/resume.json')
|
||||||
if( !valid ) {
|
};
|
||||||
_log( sheet.imp.validationErrors );
|
|
||||||
|
var sheets = src.map( function( file ) {
|
||||||
|
|
||||||
|
var textData = '';
|
||||||
|
try {
|
||||||
|
textData = FS.readFileSync( file, 'utf8' );
|
||||||
|
var rez = JSON.parse( textData );
|
||||||
}
|
}
|
||||||
|
catch( ex ) {
|
||||||
|
_log('Validating ' + file.cyan.bold + ' against FRESH/JRS schema: ' + 'ERROR!'.red.bold);
|
||||||
|
|
||||||
|
if (ex instanceof SyntaxError) {
|
||||||
|
// Invalid JSON
|
||||||
|
_log( '--> '.bold.red + file.toUpperCase().red + ' contains invalid JSON. Unable to validate.'.red );
|
||||||
|
_log( (' INTERNAL: ' + ex).red );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
_log(('ERROR: ' + ex.toString()).red.bold);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var fmt = rez.meta && rez.meta.format === 'FRESH@0.1.0' ? 'fresh':'jars';
|
||||||
|
process.stdout.write( 'Validating ' + file.cyan.bold + ' against ' +
|
||||||
|
fmt.replace('jars','JSON Resume').toUpperCase() + ' schema: ' );
|
||||||
|
|
||||||
|
var validate = validator( schemas[ fmt ], { // Note [1]
|
||||||
|
formats: { date: /^\d{4}(?:-(?:0[0-9]{1}|1[0-2]{1})(?:-[0-9]{2})?)?$/ }
|
||||||
|
});
|
||||||
|
|
||||||
|
var ret = validate( rez );
|
||||||
|
if( !ret ) {
|
||||||
|
rez.imp = rez.imp || { };
|
||||||
|
rez.imp.validationErrors = validate.errors;
|
||||||
|
_log('INVALID'.bold.yellow);
|
||||||
|
rez.imp.validationErrors.forEach(function(err,idx){
|
||||||
|
_log( '--> '.bold.yellow + ( err.field.replace('data.','resume.').toUpperCase()
|
||||||
|
+ ' ' + err.message).yellow );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_log('VALID!'.bold.green);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ catch( ex ) {
|
|||||||
function main() {
|
function main() {
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
var title = '*** FluentCV v' + PKG.version + ' ***';
|
var title = ('*** FluentCV v' + PKG.version + ' ***').bold;
|
||||||
if( process.argv.length <= 2 ) { logMsg(title); throw { fluenterror: 4 }; }
|
if( process.argv.length <= 2 ) { logMsg(title); throw { fluenterror: 4 }; }
|
||||||
var a = ARGS( process.argv.slice(2) );
|
var a = ARGS( process.argv.slice(2) );
|
||||||
opts = getOpts( a );
|
opts = getOpts( a );
|
||||||
@ -78,7 +78,7 @@ function handleError( ex ) {
|
|||||||
|
|
||||||
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 );
|
||||||
console.log( 'ERROR: ' + trimmed.toString() );
|
console.log( ('ERROR: ' + trimmed.toString()).red.bold );
|
||||||
process.exit( exitCode );
|
process.exit( exitCode );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user