1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-07-02 08:20:05 +01:00
HackMyResume/src/verbs/convert.js

62 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-12-31 08:34:41 +00:00
/**
Implementation of the 'convert' verb for HackMyResume.
@module convert.js
@license MIT. See LICENSE.md for details.
*/
2016-01-01 22:30:57 +00:00
2015-12-21 07:56:02 +00:00
(function(){
2016-01-01 22:30:57 +00:00
var ResumeFactory = require('../core/resume-factory')
, chalk = require('chalk');
2015-12-21 07:56:02 +00:00
/**
Convert between FRESH and JRS formats.
*/
2015-12-31 08:34:41 +00:00
module.exports = function convert( sources, dst, opts, logger ) {
2016-01-01 22:30:57 +00:00
// Housekeeping
2015-12-21 07:56:02 +00:00
var _log = logger || console.log;
2015-12-31 08:34:41 +00:00
if( !sources || !sources.length ) { throw { fluenterror: 6 }; }
2015-12-21 07:56:02 +00:00
if( !dst || !dst.length ) {
2015-12-31 08:34:41 +00:00
if( sources.length === 1 ) { throw { fluenterror: 5 }; }
2016-01-01 22:30:57 +00:00
else if( sources.length === 2 ) {
dst = [ sources[1] ]; sources = [ sources[0] ];
}
2015-12-21 07:56:02 +00:00
else { throw { fluenterror: 5 }; }
}
2016-01-01 22:30:57 +00:00
if( sources && dst && sources.length && dst.length &&
sources.length !== dst.length ) { throw { fluenterror: 7 }; }
// Load source resumes
var sourceResumes = ResumeFactory.load( sources, {
log: _log, format: null, objectify: true, throw: true
});
// Apply the conversion to each
2015-12-31 08:34:41 +00:00
sourceResumes.forEach(function( src, idx ) {
2016-01-01 22:30:57 +00:00
var s = src.rez
, srcFmt = ((s.basics && s.basics.imp) || s.imp).orgFormat === 'JRS' ?
'JRS' : 'FRESH';
var 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]) +
chalk.green(' (' + targetFormat + ').'));
s.saveAs( dst[idx], targetFormat );
2015-12-21 07:56:02 +00:00
});
};
2016-01-01 22:30:57 +00:00
2015-12-21 07:56:02 +00:00
}());