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

Interim changes supporting v1.3.0.

This commit is contained in:
hacksalot
2015-12-31 03:34:41 -05:00
parent 1f6d77fc28
commit 069c02ddcc
10 changed files with 234 additions and 82 deletions

View File

@ -1,3 +1,9 @@
/**
Implementation of the 'convert' verb for HackMyResume.
@module convert.js
@license MIT. See LICENSE.md for details.
*/
(function(){
var ResumeFactory = require('../core/resume-factory');
@ -5,22 +11,23 @@
/**
Convert between FRESH and JRS formats.
*/
module.exports = function convert( src, dst, opts, logger ) {
module.exports = function convert( sources, dst, opts, logger ) {
var _log = logger || console.log;
if( !src || !src.length ) { throw { fluenterror: 6 }; }
if( !sources || !sources.length ) { throw { fluenterror: 6 }; }
if( !dst || !dst.length ) {
if( src.length === 1 ) { throw { fluenterror: 5 }; }
else if( src.length === 2 ) { dst = [ src[1] ]; src = [ src[0] ]; }
if( sources.length === 1 ) { throw { fluenterror: 5 }; }
else if( sources.length === 2 ) { dst = [ sources[1] ]; sources = [ sources[0] ]; }
else { throw { fluenterror: 5 }; }
}
if( src && dst && src.length && dst.length && src.length !== dst.length ) {
if( sources && dst && sources.length && dst.length && sources.length !== dst.length ) {
throw { fluenterror: 7 };
}
var sheets = ResumeFactory.load( src, _log );
sheets.forEach(function(sheet, idx){
var sourceFormat = sheet.imp.orgFormat === 'JRS' ? 'JRS' : 'FRESH';
var sourceResumes = ResumeFactory.load( sources, _log, null, true );
sourceResumes.forEach(function( src, idx ) {
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 + sheet.imp.fileName.useful.bold + (' (' +
_log( 'Converting '.useful + src.file.useful.bold + (' (' +
sourceFormat + ') to ').useful + dst[0].useful.bold +
(' (' + targetFormat + ').').useful );
sheet.saveAs( dst[idx], targetFormat );

View File

@ -1,3 +1,9 @@
/**
Implementation of the 'create' verb for HackMyResume.
@module create.js
@license MIT. See LICENSE.md for details.
*/
(function(){
var FLUENT = require('../hackmyapi')

View File

@ -54,28 +54,28 @@ Implementation of the 'generate' verb for HackMyResume.
// Load the theme...
var tFolder = verify_theme( _opts.theme );
var theTheme = load_theme( tFolder );
var theme = load_theme( tFolder );
// Load input resumes...
if( !src || !src.length ) { throw { fluenterror: 3 }; }
var sheets = ResumeFactory.load( src, _log, null,
theTheme.render ? 'JRS' : 'FRESH' );
var sheets = ResumeFactory.load(src, _log, theme.render ? 'JRS' : 'FRESH', true);
// Merge input resumes...
var msg = '';
rez = _.reduceRight( sheets, function( a, b, idx ) {
var rezRep = _.reduceRight( sheets, function( a, b, idx ) {
msg += ((idx == sheets.length - 2) ?
'Merging '.gray+ a.imp.fileName : '') + ' onto '.gray + b.imp.fileName;
return extend( true, b, a );
'Merging '.gray + a.rez.imp.fileName : '') + ' onto '.gray + b.rez.fileName;
return extend( true, b.rez, a.rez );
});
rez = rezRep.rez;
msg && _log(msg);
// Expand output resumes...
var targets = expand( dst, theTheme );
var targets = expand( dst, theme );
// Run the transformation!
targets.forEach( function(t) {
t.final = single( t, theTheme, targets );
t.final = single( t, theme, targets );
});
// Don't send the client back empty-handed

View File

@ -1,16 +1,23 @@
/**
Implementation of the 'validate' verb for HackMyResume.
@module validate.js
@license MIT. See LICENSE.md for details.
*/
(function() {
var FS = require('fs');
var ResumeFactory = require('../core/resume-factory');
var SyntaxErrorEx = require('../utils/syntax-error-ex');
module.exports =
/**
Validate 1 to N resumes in either FRESH or JSON Resume format.
*/
function validate( src, unused, opts, logger ) {
function validate( sources, unused, opts, logger ) {
var _log = logger || console.log;
if( !src || !src.length ) { throw { fluenterror: 6 }; }
if( !sources || !sources.length ) { throw { fluenterror: 6 }; }
var isValid = true;
var validator = require('is-my-json-valid');
@ -20,67 +27,51 @@
};
// Load input resumes...
var sheets = ResumeFactory.load(src, _log, function( res ) {
try {
return {
file: res,
raw: FS.readFileSync( res, 'utf8' )
};
}
catch( ex ) {
throw ex;
}
});
sources.forEach(function( src ) {
sheets.forEach( function( rep ) {
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 );
var rez;
try {
rez = JSON.parse( rep.raw );
}
catch( ex ) { // Note [1]
_log('Validating '.info + rep.file.infoBold +
' against FRESH/JRS schema: '.info + 'ERROR!'.error.bold);
if (ex instanceof SyntaxError) {
// Invalid JSON
_log( '--> '.bold.red + rep.file.toUpperCase().red +
' contains invalid JSON. Unable to validate.'.red );
_log( (' INTERNAL: ' + ex).red );
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 );
}
else {
_log(('ERROR: ' + ex.toString()).red.bold);
_log(('ERROR: ' + ex.toString()).warn.bold);
}
return;
}
var json = result.json;
var isValid = false;
var style = 'useful';
var errors = [];
var fmt = rez.meta &&
(rez.meta.format === 'FRESH@0.1.0') ? 'fresh':'jars';
var fmt = json.meta && (json.meta.format==='FRESH@0.1.0') ? 'fresh':'jars';
try {
var validate = validator( schemas[ fmt ], { // Note [1]
formats: {
date: /^\d{4}(?:-(?:0[0-9]{1}|1[0-2]{1})(?:-[0-9]{2})?)?$/
}
});
isValid = validate( rez );
isValid = validate( json );
if( !isValid ) {
style = 'warn';
errors = validate.errors;
}
}
catch(ex) {
catch(exc) {
return;
}
_log( 'Validating '.info + rep.file.infoBold + ' against '.info +
_log( 'Validating '.info + result.file.infoBold + ' against '.info +
fmt.replace('jars','JSON Resume').toUpperCase().infoBold +
' schema: '.info + (isValid ? 'VALID!' : 'INVALID')[style].bold );
@ -93,5 +84,4 @@
});
};
}());