1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-06-27 22:30:06 +01:00
HackMyResume/src/verbs/convert.js
hacksalot 13fc903b2b Catch JSON syntax errors for all commands.
...and emit line/column info.
2016-01-01 17:20:42 -05:00

39 lines
1.4 KiB
JavaScript

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