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

Refactor command processing.

This commit is contained in:
hacksalot
2016-01-02 00:15:46 -05:00
parent 47553b6def
commit a95b52acd0
8 changed files with 74 additions and 60 deletions

View File

@ -18,42 +18,42 @@ Implementation of the 'convert' verb for HackMyResume.
/**
Convert between FRESH and JRS formats.
*/
module.exports = function convert( sources, dst, opts, logger ) {
module.exports = function convert( srcs, dst, opts, logger ) {
// Housekeeping
var _log = logger || console.log;
if( !sources || !sources.length ) { throw { fluenterror: 6 }; }
if( !srcs || !srcs.length ) { throw { fluenterror: 6 }; }
if( !dst || !dst.length ) {
if( sources.length === 1 ) { throw { fluenterror: 5 }; }
else if( sources.length === 2 ) {
dst = [ sources[1] ]; sources = [ sources[0] ];
}
if( srcs.length === 1 ) { throw { fluenterror: 5 }; }
else if( srcs.length === 2 ) { dst = dst || []; dst.push( srcs.pop() ); }
else { throw { fluenterror: 5 }; }
}
if( sources && dst && sources.length && dst.length &&
sources.length !== dst.length ) { throw { fluenterror: 7 }; }
if( srcs && dst && srcs.length && dst.length &&
srcs.length !== dst.length ) { throw { fluenterror: 7 }; }
// Load source resumes
var sourceResumes = ResumeFactory.load( sources, {
log: _log, format: null, objectify: true, throw: true
});
srcs.forEach( function( src, idx ) {
// Apply the conversion to each
sourceResumes.forEach(function( src, idx ) {
// Load the resume
var rinfo = ResumeFactory.loadOne( src, {
log: _log, format: null, objectify: true, throw: true
});
var s = src.rez
var s = rinfo.rez
, srcFmt = ((s.basics && s.basics.imp) || s.imp).orgFormat === 'JRS' ?
'JRS' : 'FRESH';
var targetFormat = srcFmt === 'JRS' ? 'FRESH' : 'JRS';
'JRS' : 'FRESH'
, targetFormat = srcFmt === 'JRS' ? 'FRESH' : 'JRS';
// TODO: Core should not log
_log( chalk.green('Converting ') + chalk.green.bold(src.file) +
chalk.green(' (' + sourceFormat + ') to ') + chalk.green.bold(dst[0]) +
_log( chalk.green('Converting ') + chalk.green.bold(rinfo.file) +
chalk.green(' (' + srcFmt + ') to ') + chalk.green.bold(dst[0]) +
chalk.green(' (' + targetFormat + ').'));
// Save it to the destination format
s.saveAs( dst[idx], targetFormat );
});
};