2015-09-01 06:05:47 +01:00
|
|
|
#! /usr/bin/env node
|
|
|
|
|
|
|
|
/**
|
2015-11-19 06:57:15 +00:00
|
|
|
Command-line interface (CLI) for FluentCV:CLI.
|
|
|
|
@license MIT. Copyright (c) 2015 James M. Devlin / FluentDesk.
|
2015-12-17 15:15:59 +00:00
|
|
|
@module index.js
|
2015-09-01 06:05:47 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
var ARGS = require( 'minimist' )
|
2015-10-07 14:29:41 +01:00
|
|
|
, FCMD = require( './fluentcmd')
|
2015-10-26 17:17:58 +00:00
|
|
|
, PKG = require('../package.json')
|
2015-11-21 21:12:22 +00:00
|
|
|
, COLORS = require('colors')
|
|
|
|
, FS = require('fs')
|
|
|
|
, PATH = require('path')
|
2015-11-21 12:59:30 +00:00
|
|
|
, opts = { }
|
2015-11-21 21:12:22 +00:00
|
|
|
, title = ('*** FluentCV v' + PKG.version + ' ***').bold.white
|
2015-11-21 15:33:16 +00:00
|
|
|
, _ = require('underscore');
|
2015-10-26 17:17:58 +00:00
|
|
|
|
|
|
|
|
2015-09-01 06:05:47 +01:00
|
|
|
|
|
|
|
try {
|
2015-10-25 07:04:51 +00:00
|
|
|
main();
|
|
|
|
}
|
|
|
|
catch( ex ) {
|
|
|
|
handleError( ex );
|
|
|
|
}
|
|
|
|
|
2015-10-26 17:17:58 +00:00
|
|
|
|
|
|
|
|
2015-10-25 07:04:51 +00:00
|
|
|
function main() {
|
2015-10-26 12:01:01 +00:00
|
|
|
|
2015-11-21 21:12:22 +00:00
|
|
|
// Colorize
|
|
|
|
COLORS.setTheme({
|
|
|
|
title: ['white','bold'],
|
|
|
|
info: process.platform === 'win32' ? 'gray' : ['white','dim'],
|
|
|
|
infoBold: ['white','dim'],
|
|
|
|
warn: 'yellow',
|
|
|
|
error: 'red',
|
|
|
|
guide: 'yellow',
|
|
|
|
status: 'gray',//['white','dim'],
|
|
|
|
useful: 'green',
|
|
|
|
});
|
|
|
|
|
|
|
|
// Setup
|
2015-11-21 12:59:30 +00:00
|
|
|
if( process.argv.length <= 2 ) { throw { fluenterror: 4 }; }
|
2015-11-19 14:46:02 +00:00
|
|
|
var a = ARGS( process.argv.slice(2) );
|
|
|
|
opts = getOpts( a );
|
2015-10-26 17:17:58 +00:00
|
|
|
logMsg( title );
|
2015-10-25 07:04:51 +00:00
|
|
|
|
2015-11-21 21:12:22 +00:00
|
|
|
|
2015-11-19 14:46:02 +00:00
|
|
|
// Get the action to be performed
|
2015-11-21 15:33:16 +00:00
|
|
|
var params = a._.map( function(p){ return p.toLowerCase().trim(); });
|
|
|
|
var verb = params[0];
|
2015-11-19 14:46:02 +00:00
|
|
|
if( !FCMD.verbs[ verb ] ) {
|
2015-11-21 21:12:22 +00:00
|
|
|
logMsg('Invalid command: "'.warn + verb.warn.bold + '"'.warn);
|
2015-11-21 12:59:30 +00:00
|
|
|
return;
|
2015-11-19 14:46:02 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 15:33:16 +00:00
|
|
|
// Get source and dest params
|
|
|
|
var splitAt = _.indexOf( params, 'to' );
|
|
|
|
if( splitAt === a._.length - 1 ) {
|
|
|
|
// 'TO' cannot be the last argument
|
2015-12-02 19:56:36 +00:00
|
|
|
logMsg('Please '.warn + 'specify an output file'.warn.bold +
|
|
|
|
' for this operation or '.warn + 'omit the TO keyword'.warn.bold +
|
|
|
|
'.'.warn );
|
2015-11-21 15:33:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var src = a._.slice(1, splitAt === -1 ? undefined : splitAt );
|
|
|
|
var dst = splitAt === -1 ? [] : a._.slice( splitAt + 1 );
|
|
|
|
var parms = [ src, dst, opts, logMsg ];
|
2015-11-19 14:46:02 +00:00
|
|
|
|
|
|
|
// Invoke the action
|
|
|
|
FCMD.verbs[ verb ].apply( null, parms );
|
2015-10-25 07:04:51 +00:00
|
|
|
|
2015-09-01 06:05:47 +01:00
|
|
|
}
|
2015-10-07 14:29:41 +01:00
|
|
|
|
2015-10-26 12:01:01 +00:00
|
|
|
function logMsg( msg ) {
|
|
|
|
opts.silent || console.log( msg );
|
|
|
|
}
|
|
|
|
|
2015-10-25 07:04:51 +00:00
|
|
|
function getOpts( args ) {
|
2015-12-10 02:44:35 +00:00
|
|
|
var noPretty = args.nopretty || args.n;
|
2015-10-25 07:04:51 +00:00
|
|
|
noPretty = noPretty && (noPretty === true || noPretty === 'true');
|
|
|
|
return {
|
|
|
|
theme: args.t || 'modern',
|
2015-12-02 19:56:36 +00:00
|
|
|
format: args.f || 'FRESH',
|
2015-10-26 12:01:01 +00:00
|
|
|
prettify: !noPretty,
|
|
|
|
silent: args.s || args.silent
|
2015-10-25 07:04:51 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleError( ex ) {
|
2015-10-26 17:17:58 +00:00
|
|
|
var msg = '', exitCode;
|
2015-11-21 21:12:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-07 14:29:41 +01:00
|
|
|
if( ex.fluenterror ){
|
2015-10-11 02:39:32 +01:00
|
|
|
switch( ex.fluenterror ) { // TODO: Remove magic numbers
|
2015-10-07 14:29:41 +01:00
|
|
|
case 1: msg = "The specified theme couldn't be found: " + ex.data; break;
|
|
|
|
case 2: msg = "Couldn't copy CSS file to destination folder"; break;
|
2015-11-21 21:12:22 +00:00
|
|
|
case 3: msg = 'Please '.guide + 'specify a valid input resume'.guide.bold + ' in FRESH or JSON Resume format.'.guide; break;
|
|
|
|
case 4: msg = title + "\nPlease ".guide + "specify a command".guide.bold + " (".guide +
|
2015-11-21 12:59:30 +00:00
|
|
|
Object.keys( FCMD.verbs ).map( function(v, idx, ar) {
|
2015-12-10 02:44:35 +00:00
|
|
|
return (idx === ar.length - 1 ? 'or '.guide : '') +
|
|
|
|
v.toUpperCase().guide;
|
2015-12-02 19:56:36 +00:00
|
|
|
}).join(', '.guide) + ").\n\n".guide + FS.readFileSync( PATH.join(__dirname, 'use.txt'), 'utf8' ).info.bold;
|
2015-11-21 15:33:16 +00:00
|
|
|
break;
|
2015-11-21 21:12:22 +00:00
|
|
|
//case 4: msg = title + '\n' + ; break;
|
|
|
|
case 5: msg = 'Please '.guide + 'specify the output resume file'.guide.bold + ' that should be created in the new format.'.guide; break;
|
|
|
|
case 6: msg = 'Please '.guide + 'specify a valid input resume'.guide.bold + ' in either FRESH or JSON Resume format.'.guide; break;
|
|
|
|
case 7: msg = 'Please '.guide + 'specify an output file name'.guide.bold + ' for every input file you wish to convert.'.guide; break;
|
2015-12-10 02:44:35 +00:00
|
|
|
}
|
2015-10-26 17:17:58 +00:00
|
|
|
exitCode = ex.fluenterror;
|
2015-11-21 21:12:22 +00:00
|
|
|
|
2015-10-07 14:29:41 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
msg = ex.toString();
|
2015-10-26 17:17:58 +00:00
|
|
|
exitCode = 4;
|
2015-10-07 14:29:41 +01:00
|
|
|
}
|
|
|
|
|
2015-09-01 06:05:47 +01:00
|
|
|
var idx = msg.indexOf('Error: ');
|
|
|
|
var trimmed = idx === -1 ? msg : msg.substring( idx + 7 );
|
2015-11-21 15:33:16 +00:00
|
|
|
if( !ex.fluenterror || ex.fluenterror < 3 )
|
2015-11-21 12:59:30 +00:00
|
|
|
console.log( ('ERROR: ' + trimmed.toString()).red.bold );
|
|
|
|
else
|
|
|
|
console.log( trimmed.toString() );
|
2015-11-21 21:12:22 +00:00
|
|
|
|
2015-10-26 17:17:58 +00:00
|
|
|
process.exit( exitCode );
|
|
|
|
|
2015-09-01 06:05:47 +01:00
|
|
|
}
|