mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 08:20:11 +00:00
Code cleanup.
Use _.reduceRight in lieue of Array.prototype.reduce to ease logging during resume merge and clean up code, comments, and whitespace throughout.
This commit is contained in:
parent
7f930283c6
commit
11f76d920f
@ -10,58 +10,50 @@ module.exports = function () {
|
|||||||
, extend = require( './utils/extend' )
|
, extend = require( './utils/extend' )
|
||||||
, unused = require('./utils/string')
|
, unused = require('./utils/string')
|
||||||
, FLUENT = require('fluentlib')
|
, FLUENT = require('fluentlib')
|
||||||
|
, _ = require('underscore')
|
||||||
, rez, _log;
|
, rez, _log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Core workhorse method for FluentCMD. Given a source JSON resume, a destination
|
Given a source JSON resume, a destination resume path, and a theme file,
|
||||||
resume path, and a theme file, generate 0..N resumes in the desired formats.
|
generate 0..N resumes in the desired formats.
|
||||||
@param src Path to the source JSON resume file: "rez/resume.json".
|
@param src Path to the source JSON resume file: "rez/resume.json".
|
||||||
@param dst An array of paths to the destination resume file(s): "rez/resume.all".
|
@param dst An array of paths to the target resume file(s).
|
||||||
@param theme Friendly name of the resume theme. Defaults to "default".
|
@param theme Friendly name of the resume theme. Defaults to "informatic".
|
||||||
@param logger Optional logging override.
|
@param logger Optional logging override.
|
||||||
*/
|
*/
|
||||||
function gen( src, dst, theme, logger ) {
|
function gen( src, dst, theme, logger ) {
|
||||||
|
|
||||||
_log = logger || console.log;
|
_log = logger || console.log;
|
||||||
_opts.theme = theme;
|
_opts.theme = theme;
|
||||||
dst = (dst && dst.length && dst) || ['resume.all'];
|
var msg = '';
|
||||||
|
|
||||||
// Assemble output resume targets
|
// Load input resumes...
|
||||||
var targets = [];
|
|
||||||
dst.forEach( function(t) {
|
|
||||||
t = path.resolve(t);
|
|
||||||
var dot = t.lastIndexOf('.');
|
|
||||||
var format = ( dot === -1 ) ? 'all' : t.substring( dot + 1 );
|
|
||||||
var temp = ( format === 'all' ) ?
|
|
||||||
_fmts.map( function( fmt ) { return t.replace( /all$/g, fmt.name ); }) :
|
|
||||||
( format === 'doc' ? [ 'doc' ] : [ t ] ); // interim code
|
|
||||||
targets.push.apply(targets, temp);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Assemble input resumes
|
|
||||||
var sheets = src.map( function( res ) {
|
var sheets = src.map( function( res ) {
|
||||||
_log( 'Reading JSON resume: ' + res );
|
_log( 'Reading JSON resume: ' + res );
|
||||||
return (new FLUENT.Sheet()).open( res );
|
return (new FLUENT.Sheet()).open( res );
|
||||||
});
|
});
|
||||||
|
|
||||||
// Merge input resumes
|
// Merge input resumes...
|
||||||
var msg = '';
|
rez = _.reduceRight( sheets, function( a, b, idx ) {
|
||||||
sheets.length > 1 && (msg += ('Merging ' + sheets[ sheets.length - 1].meta.fileName));
|
msg += ((idx == sheets.length - 2) ? 'Merging ' + a.meta.fileName : '')
|
||||||
rez = sheets.reduce( function( acc, elem ) {
|
+ ' onto ' + b.meta.fileName;
|
||||||
msg += (' onto ' + acc.meta.fileName);
|
return extend( true, b, a );
|
||||||
return extend( true, acc, elem );
|
|
||||||
});
|
});
|
||||||
sheets.length > 1 && _log( msg );
|
msg && _log(msg);
|
||||||
|
|
||||||
|
// Expand output resumes... (can't use map() here)
|
||||||
|
var targets = [];
|
||||||
|
( (dst && dst.length && dst) || ['resume.all'] ).forEach( function(t) {
|
||||||
|
var to = path.resolve(t), pa = path.parse(to), fmat = pa.ext || '.all';
|
||||||
|
targets.push.apply(targets, fmat === '.all' ?
|
||||||
|
_fmts.map(function(z){ return to.replace(/all$/g,z.name); }) : [to]);
|
||||||
|
});
|
||||||
|
|
||||||
// Run the transformation!
|
// Run the transformation!
|
||||||
var finished = targets.map( single );
|
var finished = targets.map( single );
|
||||||
|
|
||||||
return {
|
// Don't send the client back empty-handed
|
||||||
sheet: rez,//.rep,
|
return { sheet: rez, targets: targets, processed: finished };
|
||||||
targets: targets,
|
|
||||||
processed: finished
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,7 +63,6 @@ module.exports = function () {
|
|||||||
*/
|
*/
|
||||||
function single( f ) {
|
function single( f ) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Get the output file type (pdf, html, txt, etc)
|
// Get the output file type (pdf, html, txt, etc)
|
||||||
var fType = path.extname( f ).trim().toLowerCase().substr(1);
|
var fType = path.extname( f ).trim().toLowerCase().substr(1);
|
||||||
var fName = path.basename( f, '.' + fType );
|
var fName = path.basename( f, '.' + fType );
|
||||||
@ -114,11 +105,11 @@ module.exports = function () {
|
|||||||
Default options.
|
Default options.
|
||||||
*/
|
*/
|
||||||
var _opts = {
|
var _opts = {
|
||||||
theme: 'default',
|
theme: 'informatic',
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Module public interface. Used by FCV Desktop.
|
Internal module interface. Used by FCV Desktop and HMR.
|
||||||
*/
|
*/
|
||||||
return {
|
return {
|
||||||
generate: gen,
|
generate: gen,
|
||||||
|
@ -9,22 +9,17 @@ var ARGS = require( 'minimist' )
|
|||||||
, FCMD = require( './fluentcmd');
|
, FCMD = require( './fluentcmd');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
console.log( '*** FluentCMD v0.1.0 ***' );
|
console.log( '*** FluentCMD v0.1.0 ***' );
|
||||||
if( process.argv.length <= 2 ) { throw 'Please specify a JSON resume file.'; }
|
if( process.argv.length <= 2 ) { throw 'Please specify a JSON resume file.'; }
|
||||||
|
|
||||||
var args = ARGS( process.argv.slice(2) );
|
var args = ARGS( process.argv.slice(2) );
|
||||||
var src = args._.filter( function( a ) { return a.endsWith('.json'); });
|
var src = args._.filter( function( a ) { return a.endsWith('.json'); });
|
||||||
var dst = args._.filter( function( a ) { return !a.endsWith('.json'); });
|
var dst = args._.filter( function( a ) { return !a.endsWith('.json'); });
|
||||||
FCMD.generate( src, dst, args.t || 'informatic' );
|
FCMD.generate( src, dst, args.t || 'informatic' );
|
||||||
process.platform !== 'win32' && console.log('\n');
|
process.platform !== 'win32' && console.log('\n');
|
||||||
|
|
||||||
}
|
}
|
||||||
catch( ex ) {
|
catch( ex ) {
|
||||||
|
|
||||||
var msg = ex.toString();
|
var msg = ex.toString();
|
||||||
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() );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user