1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-07-05 09:30:04 +01:00
HackMyResume/src/index.js

86 lines
2.2 KiB
JavaScript
Raw Normal View History

#! /usr/bin/env node
/**
2015-12-19 17:37:42 +00:00
Command-line interface (CLI) for HackMyResume.
@license MIT. Copyright (c) 2015 hacksalot (https://github.com/hacksalot)
2015-12-17 15:15:59 +00:00
@module index.js
*/
var SPAWNW = require('./core/spawn-watch')
, ARGS = require( 'minimist' )
2015-12-19 17:37:42 +00:00
, FCMD = require( './hackmycmd')
2015-10-26 17:17:58 +00:00
, PKG = require('../package.json')
, FS = require('fs')
, chalk = require('chalk')
, PATH = require('path')
2015-12-29 10:09:05 +00:00
, HACKMYSTATUS = require('./core/status-codes')
2015-11-21 12:59:30 +00:00
, opts = { }
2016-01-02 05:15:46 +00:00
, title = chalk.white.bold('\n*** HackMyResume v' + PKG.version + ' ***')
2015-11-21 15:33:16 +00:00
, _ = require('underscore');
2015-10-26 17:17:58 +00:00
try {
main();
}
catch( ex ) {
require('./core/error-handler').err( ex, true );
}
2015-10-26 17:17:58 +00:00
function main() {
// Setup
var a = ARGS( process.argv.slice(2) );
2016-01-01 20:06:16 +00:00
if( a._.length === 0 ) { throw { fluenterror: 4 }; }
opts = getOpts( a );
2015-10-26 17:17:58 +00:00
logMsg( title );
// 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 = opts.help ? 'help' : params[0];
if( !FCMD.verbs[ verb ] && !FCMD.alias[ verb ] ) {
logMsg(chalk.yellow('Invalid command: "') + chalk.yellow.bold(verb) + chalk.yellow('"'));
2015-11-21 12:59:30 +00:00
return;
}
// Find the TO keyword, if any
2015-11-21 15:33:16 +00:00
var splitAt = _.indexOf( params, 'to' );
if( splitAt === a._.length - 1 && splitAt !== -1 ) {
2015-11-21 15:33:16 +00:00
// 'TO' cannot be the last argument
logMsg(chalk.yellow('Please ') + chalk.yellow.bold('specify an output file') +
chalk.yellow(' for this operation or ') + chalk.yellow.bold('omit the TO keyword') +
chalk.yellow('.') );
2015-11-21 15:33:16 +00:00
return;
}
// Massage inputs and outputs
2015-11-21 15:33:16 +00:00
var src = a._.slice(1, splitAt === -1 ? undefined : splitAt );
var dst = splitAt === -1 ? [] : a._.slice( splitAt + 1 );
// Invoke the action
(FCMD.verbs[verb] || FCMD.alias[verb]).apply(null, [src, dst, opts, logMsg]);
}
2015-10-07 14:29:41 +01:00
function logMsg( msg ) {
opts.silent || console.log( msg );
}
function getOpts( args ) {
2015-12-10 02:44:35 +00:00
var noPretty = args.nopretty || args.n;
noPretty = noPretty && (noPretty === true || noPretty === 'true');
return {
theme: args.t || 'modern',
2015-12-02 19:56:36 +00:00
format: args.f || 'FRESH',
prettify: !noPretty,
2015-12-31 00:45:50 +00:00
silent: args.s || args.silent,
css: args.css || 'embed',
help: args.help || undefined
};
}