mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-12-22 21:37:21 +00:00
Introduce CoffeeScript and build step.
This commit is contained in:
parent
5838b085c7
commit
d007bd9bf6
44
Gruntfile.js
44
Gruntfile.js
@ -6,6 +6,25 @@ module.exports = function (grunt) {
|
||||
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
|
||||
copy: {
|
||||
main: {
|
||||
expand: true,
|
||||
cwd: 'src',
|
||||
src: ['**/*','!**/*.coffee'],
|
||||
dest: 'dist/',
|
||||
},
|
||||
},
|
||||
|
||||
coffee: {
|
||||
main: {
|
||||
expand: true,
|
||||
cwd: 'src',
|
||||
src: ['**/*.coffee'],
|
||||
dest: 'dist/',
|
||||
ext: '.js'
|
||||
}
|
||||
},
|
||||
|
||||
simplemocha: {
|
||||
options: {
|
||||
globals: ['expect', 'should'],
|
||||
@ -27,7 +46,7 @@ module.exports = function (grunt) {
|
||||
}
|
||||
},
|
||||
|
||||
clean: ['test/sandbox'],
|
||||
clean: ['dist','test/sandbox'],
|
||||
|
||||
yuidoc: {
|
||||
compile: {
|
||||
@ -37,7 +56,6 @@ module.exports = function (grunt) {
|
||||
url: '<%= pkg.homepage %>',
|
||||
options: {
|
||||
paths: 'src/',
|
||||
//themedir: 'path/to/custom/theme/',
|
||||
outdir: 'docs/'
|
||||
}
|
||||
}
|
||||
@ -54,17 +72,29 @@ module.exports = function (grunt) {
|
||||
};
|
||||
|
||||
grunt.initConfig( opts );
|
||||
|
||||
grunt.loadNpmTasks('grunt-contrib-coffee');
|
||||
grunt.loadNpmTasks('grunt-contrib-copy');
|
||||
grunt.loadNpmTasks('grunt-simple-mocha');
|
||||
grunt.loadNpmTasks('grunt-contrib-yuidoc');
|
||||
grunt.loadNpmTasks('grunt-jsdoc');
|
||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
grunt.loadNpmTasks('grunt-contrib-clean');
|
||||
|
||||
grunt.registerTask('test', 'Test the HackMyResume library.',
|
||||
function( config ) { grunt.task.run(['clean','jshint','simplemocha:all']); });
|
||||
grunt.registerTask('document', 'Generate HackMyResume library documentation.',
|
||||
function( config ) { grunt.task.run( ['jsdoc'] ); });
|
||||
grunt.registerTask('test', 'Test the HackMyResume application.',
|
||||
function( config ) {
|
||||
grunt.task.run(['build','jshint','simplemocha:all']);
|
||||
});
|
||||
|
||||
grunt.registerTask('document', 'Generate HackMyResume documentation.',
|
||||
function( config ) {
|
||||
grunt.task.run( ['jsdoc'] );
|
||||
});
|
||||
|
||||
grunt.registerTask('build', 'Build the HackMyResume application.',
|
||||
function( config ) {
|
||||
grunt.task.run( ['clean','copy','coffee'] );
|
||||
});
|
||||
|
||||
grunt.registerTask('default', [ 'test', 'jsdoc' ]);
|
||||
|
||||
};
|
||||
|
30
dist/cli/analyze.hbs
vendored
Normal file
30
dist/cli/analyze.hbs
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
{{style "SECTIONS (" "bold"}}{{style totals.numSections "white" }}{{style ")" "bold"}}
|
||||
|
||||
employment: {{v totals.totals.employment "-" 2 "bold" }}
|
||||
projects: {{v totals.totals.projects "-" 2 "bold" }}
|
||||
education: {{v totals.totals.education "-" 2 "bold" }}
|
||||
service: {{v totals.totals.service "-" 2 "bold" }}
|
||||
skills: {{v totals.totals.skills "-" 2 "bold" }}
|
||||
writing: {{v totals.totals.writing "-" 2 "bold" }}
|
||||
speaking: {{v totals.totals.speaking "-" 2 "bold" }}
|
||||
reading: {{v totals.totals.reading "-" 2 "bold" }}
|
||||
social: {{v totals.totals.social "-" 2 "bold" }}
|
||||
references: {{v totals.totals.references "-" 2 "bold" }}
|
||||
testimonials: {{v totals.totals.testimonials "-" 2 "bold" }}
|
||||
languages: {{v totals.totals.languages "-" 2 "bold" }}
|
||||
interests: {{v totals.totals.interests "-" 2 "bold" }}
|
||||
|
||||
{{style "COVERAGE (" "bold"}}{{style coverage.pct "white"}}{{style ")" "bold"}}
|
||||
|
||||
Total Days: {{v coverage.duration.total "-" 5 "bold" }}
|
||||
Employed: {{v coverage.duration.work "-" 5 "bold" }}
|
||||
Gaps: {{v coverage.gaps.length "-" 5 "bold" }} [{{#if coverage.gaps.length }}{{#each coverage.gaps }}{{#unless @first}} {{/unless}}{{gapLength duration }}{{/each}}{{/if}}]
|
||||
Overlaps: {{v coverage.overlaps.length "-" 5 "bold" }} [{{#if coverage.overlaps.length }}{{#each coverage.overlaps }}{{#unless @first}} {{/unless}}{{gapLength duration }}{{/each}}{{/if}}]
|
||||
|
||||
{{style "KEYWORDS (" "bold"}}{{style keywords.length "white" }}{{style ")" "bold"}}
|
||||
|
||||
{{#each keywords }}{{{pad name 18}}}: {{v count "-" 5 "bold"}} mention{{#isPlural count}}s{{/isPlural}}
|
||||
{{/each}}
|
||||
-------------------------------
|
||||
{{v keywords.length "0" 9 "bold"}} {{style "KEYWORDS" "bold"}} {{v keywords.totalKeywords "0" 5 "bold"}} {{style "mentions" "bold"}}
|
280
dist/cli/error.js
vendored
Normal file
280
dist/cli/error.js
vendored
Normal file
@ -0,0 +1,280 @@
|
||||
/**
|
||||
Error-handling routines for HackMyResume.
|
||||
@module cli/error
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var HMSTATUS = require('hackmycore/src/core/status-codes')
|
||||
, PKG = require('../../package.json')
|
||||
, FS = require('fs')
|
||||
, FCMD = require('hackmycore')
|
||||
, PATH = require('path')
|
||||
, WRAP = require('word-wrap')
|
||||
, M2C = require('hackmycore/src/utils/md2chalk.js')
|
||||
, chalk = require('chalk')
|
||||
, extend = require('extend')
|
||||
, YAML = require('yamljs')
|
||||
, printf = require('printf')
|
||||
, SyntaxErrorEx = require('hackmycore/src/utils/syntax-error-ex');
|
||||
require('string.prototype.startswith');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Error handler for HackMyResume. All errors are handled here.
|
||||
@class ErrorHandler
|
||||
*/
|
||||
var ErrorHandler = module.exports = {
|
||||
|
||||
|
||||
|
||||
init: function( debug, assert, silent ) {
|
||||
this.debug = debug;
|
||||
this.assert = assert;
|
||||
this.silent = silent;
|
||||
this.msgs = require('./msg.js').errors;
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
|
||||
err: function( ex, shouldExit ) {
|
||||
|
||||
// Short-circuit logging output if --silent is on
|
||||
var o = this.silent ? function() { } : _defaultLog;
|
||||
|
||||
// Special case; can probably be removed.
|
||||
if( ex.pass ) throw ex;
|
||||
|
||||
// Load error messages
|
||||
this.msgs = this.msgs || require('./msg.js').errors;
|
||||
|
||||
// Handle packaged HMR exceptions
|
||||
if( ex.fluenterror ) {
|
||||
|
||||
// Output the error message
|
||||
var objError = assembleError.call( this, ex );
|
||||
o( this[ 'format_' + objError.etype ]( objError.msg ));
|
||||
|
||||
// Output the stack (sometimes)
|
||||
if( objError.withStack ) {
|
||||
var stack = ex.stack || (ex.inner && ex.inner.stack);
|
||||
stack && o( chalk.gray( stack ) );
|
||||
}
|
||||
|
||||
// Quit if necessary
|
||||
if( ex.quit || objError.quit ) {
|
||||
this.debug && o(
|
||||
chalk.cyan('Exiting with error code ' + ex.fluenterror.toString()));
|
||||
if( this.assert ) { ex.pass = true; throw ex; }
|
||||
process.exit( ex.fluenterror );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Handle raw exceptions
|
||||
else {
|
||||
o( ex );
|
||||
var stackTrace = ex.stack || (ex.inner && ex.inner.stack);
|
||||
if( stackTrace && this.debug )
|
||||
o( M2C(ex.stack || ex.inner.stack, 'gray') );
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
|
||||
format_error: function( msg ) {
|
||||
msg = msg || '';
|
||||
return chalk.red.bold(
|
||||
msg.toUpperCase().startsWith('ERROR:') ? msg : 'Error: ' + msg );
|
||||
},
|
||||
|
||||
|
||||
|
||||
format_warning: function( brief, msg ) {
|
||||
return chalk.yellow(brief) + chalk.yellow(msg || '');
|
||||
},
|
||||
|
||||
|
||||
format_custom: function( msg ) {
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
function _defaultLog() {
|
||||
console.log.apply( console.log, arguments );
|
||||
}
|
||||
|
||||
|
||||
|
||||
function assembleError( ex ) {
|
||||
|
||||
var msg = '', withStack = false, quit = false, etype = 'warning';
|
||||
if( this.debug ) withStack = true;
|
||||
|
||||
switch( ex.fluenterror ) {
|
||||
|
||||
case HMSTATUS.themeNotFound:
|
||||
msg = printf( M2C( this.msgs.themeNotFound.msg, 'yellow' ), ex.data);
|
||||
break;
|
||||
|
||||
case HMSTATUS.copyCSS:
|
||||
msg = M2C( this.msgs.copyCSS.msg, 'red' );
|
||||
quit = false;
|
||||
break;
|
||||
|
||||
case HMSTATUS.resumeNotFound:
|
||||
msg = M2C( this.msgs.resumeNotFound.msg, 'yellow' );
|
||||
break;
|
||||
|
||||
case HMSTATUS.missingCommand:
|
||||
msg = M2C( this.msgs.missingCommand.msg + " (", 'yellow');
|
||||
msg += Object.keys( FCMD.verbs ).map( function(v, idx, ar) {
|
||||
return (idx === ar.length - 1 ? chalk.yellow('or ') : '') +
|
||||
chalk.yellow.bold(v.toUpperCase());
|
||||
}).join( chalk.yellow(', ')) + chalk.yellow(").\n\n");
|
||||
|
||||
msg += chalk.gray(FS.readFileSync(
|
||||
PATH.resolve(__dirname, '../cli/use.txt'), 'utf8' ));
|
||||
break;
|
||||
|
||||
case HMSTATUS.invalidCommand:
|
||||
msg = printf( M2C( this.msgs.invalidCommand.msg, 'yellow'), ex.attempted );
|
||||
break;
|
||||
|
||||
case HMSTATUS.resumeNotFoundAlt:
|
||||
msg = M2C( this.msgs.resumeNotFoundAlt.msg, 'yellow' );
|
||||
break;
|
||||
|
||||
case HMSTATUS.inputOutputParity:
|
||||
msg = M2C( this.msgs.inputOutputParity.msg );
|
||||
break;
|
||||
|
||||
case HMSTATUS.createNameMissing:
|
||||
msg = M2C( this.msgs.createNameMissing.msg );
|
||||
break;
|
||||
|
||||
case HMSTATUS.pdfGeneration:
|
||||
msg = M2C( this.msgs.pdfGeneration.msg, 'bold' );
|
||||
if( ex.inner ) msg += chalk.red('\n' + ex.inner);
|
||||
withStack = true; quit = false; etype = 'error';
|
||||
break;
|
||||
|
||||
case HMSTATUS.invalid:
|
||||
msg = M2C( this.msgs.invalid.msg, 'red' );
|
||||
etype = 'error';
|
||||
break;
|
||||
|
||||
case HMSTATUS.generateError:
|
||||
msg = (ex.inner && ex.inner.toString()) || ex;
|
||||
quit = false;
|
||||
etype = 'error';
|
||||
break;
|
||||
|
||||
case HMSTATUS.fileSaveError:
|
||||
msg = printf( M2C( this.msgs.fileSaveError.msg ), (ex.inner || ex).toString() );
|
||||
etype = 'error';
|
||||
quit = false;
|
||||
break;
|
||||
|
||||
case HMSTATUS.invalidFormat:
|
||||
ex.data.forEach(function(d){
|
||||
msg += printf( M2C( this.msgs.invalidFormat.msg, 'bold' ),
|
||||
ex.theme.name.toUpperCase(), d.format.toUpperCase());
|
||||
}, this);
|
||||
break;
|
||||
|
||||
case HMSTATUS.missingParam:
|
||||
msg = printf( M2C( this.msgs.missingParam.msg ), ex.expected, ex.helper );
|
||||
break;
|
||||
|
||||
case HMSTATUS.invalidHelperUse:
|
||||
msg = printf( M2C( this.msgs.invalidHelperUse.msg ), ex.helper );
|
||||
if( ex.error ) {
|
||||
msg += '\n--> ' + assembleError.call( this, extend( true, {}, ex, {fluenterror: ex.error} )).msg;
|
||||
//msg += printf( '\n--> ' + M2C( this.msgs.invalidParamCount.msg ), ex.expected );
|
||||
}
|
||||
quit = false;
|
||||
etype = 'warning';
|
||||
break;
|
||||
|
||||
case HMSTATUS.notOnPath:
|
||||
msg = printf( M2C(this.msgs.notOnPath.msg, 'bold'), ex.engine);
|
||||
quit = false;
|
||||
etype = 'error';
|
||||
break;
|
||||
|
||||
case HMSTATUS.readError:
|
||||
if( !ex.quiet )
|
||||
console.error(printf( M2C(this.msgs.readError.msg, 'red'), ex.file));
|
||||
msg = ex.inner.toString();
|
||||
etype = 'error';
|
||||
break;
|
||||
|
||||
case HMSTATUS.mixedMerge:
|
||||
msg = M2C( this.msgs.mixedMerge.msg );
|
||||
quit = false;
|
||||
break;
|
||||
|
||||
case HMSTATUS.invokeTemplate:
|
||||
msg = M2C( this.msgs.invokeTemplate.msg, 'red' );
|
||||
msg += M2C( '\n' + WRAP(ex.inner.toString(), { width: 60, indent: ' ' }), 'gray' );
|
||||
etype = 'custom';
|
||||
break;
|
||||
|
||||
case HMSTATUS.compileTemplate:
|
||||
etype = 'error';
|
||||
break;
|
||||
|
||||
case HMSTATUS.themeLoad:
|
||||
msg = M2C( printf( this.msgs.themeLoad.msg, ex.attempted.toUpperCase() ), 'red');
|
||||
if( ex.inner && ex.inner.fluenterror ) {
|
||||
msg += M2C('\nError: ', 'red') + assembleError.call( this, ex.inner ).msg;
|
||||
}
|
||||
quit = true;
|
||||
etype = 'custom';
|
||||
break;
|
||||
|
||||
case HMSTATUS.parseError:
|
||||
if( SyntaxErrorEx.is( ex.inner )) {
|
||||
console.error( printf( M2C(this.msgs.readError.msg, 'red'), ex.file ) );
|
||||
var se = new SyntaxErrorEx( ex, ex.raw );
|
||||
msg = printf( M2C( this.msgs.parseError.msg, 'red' ),
|
||||
se.line, se.col);
|
||||
}
|
||||
else if( ex.inner && ex.inner.line !== undefined && ex.inner.col !== undefined ) {
|
||||
msg = printf( M2C( this.msgs.parseError.msg, 'red' ),
|
||||
ex.inner.line, ex.inner.col);
|
||||
}
|
||||
else {
|
||||
msg = ex;
|
||||
}
|
||||
etype = 'error';
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
msg: msg, // The error message to display
|
||||
withStack: withStack, // Whether to include the stack
|
||||
quit: quit,
|
||||
etype: etype
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}());
|
279
dist/cli/main.js
vendored
Normal file
279
dist/cli/main.js
vendored
Normal file
@ -0,0 +1,279 @@
|
||||
|
||||
/**
|
||||
Definition of the `main` function.
|
||||
@module cli/main
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var Command, EXTEND, FS, HME, HMR, HMSTATUS, OUTPUT, PAD, PATH, PKG, StringUtils, _, _opts, _out, _title, chalk, execute, initOptions, initialize, loadOptions, logMsg, main, safeLoadJSON, splitSrcDest;
|
||||
|
||||
HMR = require('hackmycore');
|
||||
|
||||
PKG = require('../../package.json');
|
||||
|
||||
FS = require('fs');
|
||||
|
||||
EXTEND = require('extend');
|
||||
|
||||
chalk = require('chalk');
|
||||
|
||||
PATH = require('path');
|
||||
|
||||
HMSTATUS = require('hackmycore/src/core/status-codes');
|
||||
|
||||
HME = require('hackmycore/src/core/event-codes');
|
||||
|
||||
safeLoadJSON = require('hackmycore/src/utils/safe-json-loader');
|
||||
|
||||
StringUtils = require('hackmycore/src/utils/string.js');
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
OUTPUT = require('./out');
|
||||
|
||||
PAD = require('string-padding');
|
||||
|
||||
Command = require('commander').Command;
|
||||
|
||||
_opts = {};
|
||||
|
||||
_title = chalk.white.bold('\n*** HackMyResume v' + PKG.version + ' ***');
|
||||
|
||||
_out = new OUTPUT(_opts);
|
||||
|
||||
|
||||
/*
|
||||
A callable implementation of the HackMyResume CLI. Encapsulates the command
|
||||
line interface as a single method accepting a parameter array.
|
||||
@alias module:cli/main.main
|
||||
@param rawArgs {Array} An array of command-line parameters. Will either be
|
||||
process.argv (in production) or custom parameters (in test).
|
||||
*/
|
||||
|
||||
main = module.exports = function(rawArgs) {
|
||||
var args, initInfo, program;
|
||||
initInfo = initialize(rawArgs);
|
||||
args = initInfo.args;
|
||||
program = new Command('hackmyresume').version(PKG.version).description(chalk.yellow.bold('*** HackMyResume ***')).option('-s --silent', 'Run in silent mode').option('--no-color', 'Disable colors').option('--color', 'Enable colors').option('-d --debug', 'Enable diagnostics', false).option('-a --assert', 'Treat warnings as errors', false).option('-v --version', 'Show the version').allowUnknownOption();
|
||||
program.jsonArgs = initInfo.options;
|
||||
program.command('new')["arguments"]('<sources...>').option('-f --format <fmt>', 'FRESH or JRS format', 'FRESH').alias('create').description('Create resume(s) in FRESH or JSON RESUME format.').action((function(sources) {
|
||||
execute.call(this, sources, [], this.opts(), logMsg);
|
||||
}));
|
||||
program.command('validate')["arguments"]('<sources...>').description('Validate a resume in FRESH or JSON RESUME format.').action(function(sources) {
|
||||
execute.call(this, sources, [], this.opts(), logMsg);
|
||||
});
|
||||
program.command('convert').description('Convert a resume to/from FRESH or JSON RESUME format.').action(function() {
|
||||
var x;
|
||||
x = splitSrcDest.call(this);
|
||||
execute.call(this, x.src, x.dst, this.opts(), logMsg);
|
||||
});
|
||||
program.command('analyze')["arguments"]('<sources...>').description('Analyze one or more resumes.').action(function(sources) {
|
||||
execute.call(this, sources, [], this.opts(), logMsg);
|
||||
});
|
||||
program.command('peek')["arguments"]('<sources...>').description('Peek at a resume field or section').action(function(sources, sectionOrField) {
|
||||
var dst;
|
||||
dst = sources && sources.length > 1 ? [sources.pop()] : [];
|
||||
execute.call(this, sources, dst, this.opts(), logMsg);
|
||||
});
|
||||
program.command('build').alias('generate').option('-t --theme <theme>', 'Theme name or path').option('-n --no-prettify', 'Disable HTML prettification', true).option('-c --css <option>', 'CSS linking / embedding').option('-p --pdf <engine>', 'PDF generation engine').option('--no-sort', 'Sort resume sections by date', false).option('--tips', 'Display theme tips and warnings.', false).description('Generate resume to multiple formats').action(function(sources, targets, options) {
|
||||
var x;
|
||||
x = splitSrcDest.call(this);
|
||||
execute.call(this, x.src, x.dst, this.opts(), logMsg);
|
||||
});
|
||||
program.parse(args);
|
||||
if (!program.args.length) {
|
||||
throw {
|
||||
fluenterror: 4
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* Massage command-line args and setup Commander.js. */
|
||||
|
||||
initialize = function(ar) {
|
||||
var o;
|
||||
o = initOptions(ar);
|
||||
o.silent || logMsg(_title);
|
||||
if (o.debug) {
|
||||
_out.log(chalk.cyan('The -d or --debug switch was specified. DEBUG mode engaged.'));
|
||||
_out.log('');
|
||||
_out.log(chalk.cyan(PAD(' Platform:', 25, null, PAD.RIGHT)) + chalk.cyan.bold(process.platform === 'win32' ? 'windows' : process.platform));
|
||||
_out.log(chalk.cyan(PAD(' Node.js:', 25, null, PAD.RIGHT)) + chalk.cyan.bold(process.version));
|
||||
_out.log(chalk.cyan(PAD(' HackMyResume:', 25, null, PAD.RIGHT)) + chalk.cyan.bold('v' + PKG.version));
|
||||
_out.log(chalk.cyan(PAD(' FRESCA:', 25, null, PAD.RIGHT)) + chalk.cyan.bold(PKG.dependencies.fresca));
|
||||
_out.log('');
|
||||
}
|
||||
if (o.verb && !HMR.verbs[o.verb] && !HMR.alias[o.verb]) {
|
||||
throw {
|
||||
fluenterror: HMSTATUS.invalidCommand,
|
||||
quit: true,
|
||||
attempted: o.orgVerb
|
||||
};
|
||||
}
|
||||
Command.prototype.missingArgument = function(name) {
|
||||
if (this.name() !== 'new') {
|
||||
throw {
|
||||
fluenterror: HMSTATUS.resumeNotFound,
|
||||
quit: true
|
||||
};
|
||||
}
|
||||
};
|
||||
Command.prototype.helpInformation = function() {
|
||||
var manPage;
|
||||
manPage = FS.readFileSync(PATH.join(__dirname, 'use.txt'), 'utf8');
|
||||
return chalk.green.bold(manPage);
|
||||
};
|
||||
return {
|
||||
args: o.args,
|
||||
options: o.json
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/* Init options prior to setting up command infrastructure. */
|
||||
|
||||
initOptions = function(ar) {
|
||||
oVerb;
|
||||
var args, cleanArgs, inf, isDebug, isSilent, oJSON, oVerb, optStr, optsIdx, verb, vidx;
|
||||
verb = '';
|
||||
args = ar.slice();
|
||||
cleanArgs = args.slice(2);
|
||||
oJSON;
|
||||
if (cleanArgs.length) {
|
||||
vidx = _.findIndex(cleanArgs, function(v) {
|
||||
return v[0] !== '-';
|
||||
});
|
||||
if (vidx !== -1) {
|
||||
oVerb = cleanArgs[vidx];
|
||||
verb = args[vidx + 2] = oVerb.trim().toLowerCase();
|
||||
}
|
||||
optsIdx = _.findIndex(cleanArgs, function(v) {
|
||||
return v === '-o' || v === '--options' || v === '--opts';
|
||||
});
|
||||
if (optsIdx !== -1) {
|
||||
optStr = cleanArgs[optsIdx + 1];
|
||||
args.splice(optsIdx + 2, 2);
|
||||
if (optStr && (optStr = optStr.trim())) {
|
||||
if (optStr[0] === '{') {
|
||||
|
||||
/* jshint ignore:start */
|
||||
oJSON = eval('(' + optStr + ')');
|
||||
|
||||
/* jshint ignore:end */
|
||||
} else {
|
||||
inf = safeLoadJSON(optStr);
|
||||
if (!inf.ex) {
|
||||
oJSON = inf.json;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
isDebug = _.some(args, function(v) {
|
||||
return v === '-d' || v === '--debug';
|
||||
});
|
||||
isSilent = _.some(args, function(v) {
|
||||
return v === '-s' || v === '--silent';
|
||||
});
|
||||
return {
|
||||
debug: isDebug,
|
||||
silent: isSilent,
|
||||
orgVerb: oVerb,
|
||||
verb: verb,
|
||||
json: oJSON,
|
||||
args: args
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/* Invoke a HackMyResume verb. */
|
||||
|
||||
execute = function(src, dst, opts, log) {
|
||||
var hand, v;
|
||||
loadOptions.call(this, opts, this.parent.jsonArgs);
|
||||
hand = require('./error');
|
||||
hand.init(_opts.debug, _opts.assert, _opts.silent);
|
||||
v = new HMR.verbs[this.name()]();
|
||||
_opts.errHandler = v;
|
||||
_out.init(_opts);
|
||||
v.on('hmr:status', function() {
|
||||
return _out["do"].apply(_out, arguments);
|
||||
});
|
||||
v.on('hmr:error', function() {
|
||||
return hand.err.apply(hand, arguments);
|
||||
});
|
||||
v.invoke.call(v, src, dst, _opts, log);
|
||||
if (v.errorCode) {
|
||||
return process.exit(v.errorCode);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Initialize HackMyResume options.
|
||||
TODO: Options loading is a little hacky, for two reasons:
|
||||
- Commander.js idiosyncracies
|
||||
- Need to accept JSON inputs from the command line.
|
||||
*/
|
||||
|
||||
loadOptions = function(o, cmdO) {
|
||||
if (cmdO) {
|
||||
o = EXTEND(true, o, cmdO);
|
||||
}
|
||||
o = EXTEND(true, o, this.opts());
|
||||
if (this.parent.silent !== void 0 && this.parent.silent !== null) {
|
||||
o.silent = this.parent.silent;
|
||||
}
|
||||
if (this.parent.debug !== void 0 && this.parent.debug !== null) {
|
||||
o.debug = this.parent.debug;
|
||||
}
|
||||
if (this.parent.assert !== void 0 && this.parent.assert !== null) {
|
||||
o.assert = this.parent.assert;
|
||||
}
|
||||
if (o.debug) {
|
||||
logMsg(chalk.cyan('OPTIONS:') + '\n');
|
||||
_.each(o, function(val, key) {
|
||||
return logMsg(chalk.cyan(' %s') + chalk.cyan.bold(' %s'), PAD(key, 22, null, PAD.RIGHT), val);
|
||||
});
|
||||
logMsg('');
|
||||
}
|
||||
EXTEND(true, _opts, o);
|
||||
};
|
||||
|
||||
|
||||
/* Split multiple command-line filenames by the 'TO' keyword */
|
||||
|
||||
splitSrcDest = function() {
|
||||
var params, splitAt;
|
||||
params = this.parent.args.filter(function(j) {
|
||||
return String.is(j);
|
||||
});
|
||||
if (params.length === 0) {
|
||||
throw {
|
||||
fluenterror: HMSTATUS.resumeNotFound,
|
||||
quit: true
|
||||
};
|
||||
}
|
||||
splitAt = _.findIndex(params, function(p) {
|
||||
return p.toLowerCase() === 'to';
|
||||
});
|
||||
if (splitAt === params.length - 1 && splitAt !== -1) {
|
||||
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('.'));
|
||||
return;
|
||||
}
|
||||
return {
|
||||
src: params.slice(0, splitAt === -1 ? void 0 : splitAt),
|
||||
dst: splitAt === -1 ? [] : params.slice(splitAt + 1)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/* Simple logging placeholder. */
|
||||
|
||||
logMsg = function() {
|
||||
return _opts.silent || console.log.apply(console.log, arguments);
|
||||
};
|
||||
|
||||
}).call(this);
|
18
dist/cli/msg.js
vendored
Normal file
18
dist/cli/msg.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
/**
|
||||
Message-handling routines for HackMyResume.
|
||||
@module msg.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
var PATH = require('path');
|
||||
var YAML = require('yamljs');
|
||||
|
||||
var cache = module.exports = function() {
|
||||
return cache ? cache : YAML.load( PATH.join(__dirname, 'msg.yml') );
|
||||
}();
|
||||
|
||||
}());
|
98
dist/cli/msg.yml
vendored
Normal file
98
dist/cli/msg.yml
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
events:
|
||||
begin:
|
||||
msg: Invoking **%s** command.
|
||||
beforeCreate:
|
||||
msg: Creating new **%s** resume: **%s**
|
||||
afterRead:
|
||||
msg: Reading **%s** resume: **%s**
|
||||
beforeTheme:
|
||||
msg: Verifying **%s** theme.
|
||||
afterTheme:
|
||||
msg: Verifying outputs: ???
|
||||
beforeMerge:
|
||||
msg:
|
||||
- "Merging **%s**"
|
||||
- " onto **%s**"
|
||||
applyTheme:
|
||||
msg: Applying **%s** theme (**%s** format%s)
|
||||
afterBuild:
|
||||
msg:
|
||||
- "The **%s** theme says:"
|
||||
- |
|
||||
"For best results view JSON Resume themes over a
|
||||
local or remote HTTP connection. For example:
|
||||
|
||||
npm install http-server -g
|
||||
http-server <resume-folder>
|
||||
|
||||
For more information, see the README."
|
||||
afterGenerate:
|
||||
msg:
|
||||
- " (with %s)"
|
||||
- "Skipping %s resume: %s"
|
||||
- "Generating **%s** resume: **%s**"
|
||||
beforeAnalyze:
|
||||
msg: "Analyzing **%s** resume: **%s**"
|
||||
beforeConvert:
|
||||
msg: "Converting **%s** (**%s**) to **%s** (**%s**)"
|
||||
afterValidate:
|
||||
msg:
|
||||
- "Validating **%s** against the **%s** schema: "
|
||||
- "VALID!"
|
||||
- "INVALID"
|
||||
- "BROKEN"
|
||||
beforePeek:
|
||||
msg:
|
||||
- Peeking at **%s** in **%s**
|
||||
- Peeking at **%s**
|
||||
afterPeek:
|
||||
msg: "The specified key **%s** was not found in **%s**."
|
||||
afterInlineConvert:
|
||||
msg: Converting **%s** to **%s** format.
|
||||
errors:
|
||||
themeNotFound:
|
||||
msg: >
|
||||
**Couldn't find the '%s' theme.** Please specify the name of a preinstalled
|
||||
FRESH theme or the path to a locally installed FRESH or JSON Resume theme.
|
||||
copyCSS:
|
||||
msg: Couldn't copy CSS file to destination folder.
|
||||
resumeNotFound:
|
||||
msg: Please **feed me a resume** in FRESH or JSON Resume format.
|
||||
missingCommand:
|
||||
msg: Please **give me a command**
|
||||
invalidCommand:
|
||||
msg: Invalid command: '%s'
|
||||
resumeNotFoundAlt:
|
||||
msg: Please **feed me a resume** in either FRESH or JSON Resume format.
|
||||
inputOutputParity:
|
||||
msg: Please **specify an output file name** for every input file you wish to convert.
|
||||
createNameMissing:
|
||||
msg: Please **specify the filename** of the resume to create.
|
||||
pdfGeneration:
|
||||
msg: PDF generation failed. Make sure wkhtmltopdf is installed and accessible from your path.
|
||||
invalid:
|
||||
msg: Validation failed and the --assert option was specified.
|
||||
invalidFormat:
|
||||
msg: The **%s** theme doesn't support the **%s** format.
|
||||
notOnPath:
|
||||
msg: %s wasn't found on your system path or is inaccessible. PDF not generated.
|
||||
readError:
|
||||
msg: Reading **???** resume: **%s**
|
||||
parseError:
|
||||
msg: Invalid or corrupt JSON on line %s column %s.
|
||||
invalidHelperUse:
|
||||
msg: "**Warning**: Incorrect use of the **%s** theme helper."
|
||||
fileSaveError:
|
||||
msg: An error occurred while writing %s to disk: %s.
|
||||
mixedMerge:
|
||||
msg: "**Warning:** merging mixed resume types. Errors may occur."
|
||||
invokeTemplate:
|
||||
msg: "An error occurred during template invocation."
|
||||
compileTemplate:
|
||||
msg: "An error occurred during template compilation."
|
||||
themeLoad:
|
||||
msg: "Applying **%s** theme (? formats)"
|
||||
invalidParamCount:
|
||||
msg: "Invalid number of parameters. Expected: **%s**."
|
||||
missingParam:
|
||||
msg: The '**%s**' parameter was needed but not supplied.
|
229
dist/cli/out.js
vendored
Normal file
229
dist/cli/out.js
vendored
Normal file
@ -0,0 +1,229 @@
|
||||
/**
|
||||
Output routines for HackMyResume.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module out.js
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var chalk = require('chalk')
|
||||
, HME = require('hackmycore/src/core/event-codes')
|
||||
, _ = require('underscore')
|
||||
, Class = require('hackmycore/src/utils/class.js')
|
||||
, M2C = require('hackmycore/src/utils/md2chalk.js')
|
||||
, PATH = require('path')
|
||||
, LO = require('lodash')
|
||||
, FS = require('fs')
|
||||
, EXTEND = require('extend')
|
||||
, HANDLEBARS = require('handlebars')
|
||||
, YAML = require('yamljs')
|
||||
, printf = require('printf')
|
||||
, pad = require('string-padding')
|
||||
, dbgStyle = 'cyan';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
A stateful output module. All HMR console output handled here.
|
||||
*/
|
||||
var OutputHandler = module.exports = Class.extend({
|
||||
|
||||
|
||||
|
||||
init: function( opts ) {
|
||||
this.opts = EXTEND( true, this.opts || { }, opts );
|
||||
this.msgs = YAML.load(PATH.join( __dirname, 'msg.yml' )).events;
|
||||
},
|
||||
|
||||
|
||||
|
||||
log: function( msg ) {
|
||||
msg = msg || '';
|
||||
var printf = require('printf');
|
||||
var finished = printf.apply( printf, arguments );
|
||||
this.opts.silent || console.log( finished );
|
||||
},
|
||||
|
||||
|
||||
|
||||
do: function( evt ) {
|
||||
|
||||
var that = this;
|
||||
function L() {
|
||||
that.log.apply( that, arguments );
|
||||
}
|
||||
|
||||
switch( evt.sub ) {
|
||||
|
||||
case HME.begin:
|
||||
this.opts.debug &&
|
||||
L( M2C( this.msgs.begin.msg, dbgStyle), evt.cmd.toUpperCase() );
|
||||
break;
|
||||
|
||||
case HME.error:
|
||||
break;
|
||||
|
||||
case HME.beforeCreate:
|
||||
L( M2C( this.msgs.beforeCreate.msg, 'green' ), evt.fmt, evt.file );
|
||||
break;
|
||||
|
||||
case HME.beforeRead:
|
||||
break;
|
||||
|
||||
case HME.afterRead:
|
||||
break;
|
||||
|
||||
case HME.beforeTheme:
|
||||
this.opts.debug &&
|
||||
L( M2C( this.msgs.beforeTheme.msg, dbgStyle), evt.theme.toUpperCase() );
|
||||
break;
|
||||
|
||||
case HME.afterParse:
|
||||
L(
|
||||
M2C( this.msgs.afterRead.msg, 'gray', 'white.dim'), evt.fmt.toUpperCase(), evt.file
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
case HME.afterTheme:
|
||||
break;
|
||||
|
||||
case HME.beforeMerge:
|
||||
var msg = '';
|
||||
evt.f.reverse().forEach( function( a, idx ) {
|
||||
msg += printf(
|
||||
((idx === 0) ?
|
||||
this.msgs.beforeMerge.msg[0] :
|
||||
this.msgs.beforeMerge.msg[1] ), a.file
|
||||
);
|
||||
}, this);
|
||||
L( M2C(msg, evt.mixed ? 'yellow' : 'gray', 'white.dim') );
|
||||
break;
|
||||
|
||||
case HME.afterMerge:
|
||||
break;
|
||||
|
||||
case HME.applyTheme:
|
||||
this.theme = evt.theme;
|
||||
var numFormats = Object.keys( evt.theme.formats ).length;
|
||||
L( M2C(this.msgs.applyTheme.msg, evt.status === 'error' ? 'red' : 'gray', evt.status === 'error' ? 'bold' : 'white.dim'),
|
||||
evt.theme.name.toUpperCase(),
|
||||
numFormats, ( numFormats === 1 ? '' : 's') );
|
||||
break;
|
||||
|
||||
case HME.end:
|
||||
if( evt.cmd === 'build' ) {
|
||||
var themeName = this.theme.name.toUpperCase();
|
||||
if( this.opts.tips && (this.theme.message || this.theme.render) ) {
|
||||
var WRAP = require('word-wrap');
|
||||
if( this.theme.message ) {
|
||||
L( M2C( this.msgs.afterBuild.msg[0], 'cyan' ), themeName );
|
||||
L( M2C( this.theme.message, 'white' ));
|
||||
}
|
||||
else if ( this.theme.render ) {
|
||||
L( M2C( this.msgs.afterBuild.msg[0], 'cyan'), themeName);
|
||||
L( M2C( this.msgs.afterBuild.msg[1], 'white'));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case HME.afterGenerate:
|
||||
var suffix = '';
|
||||
if( evt.fmt === 'pdf' ) {
|
||||
if( this.opts.pdf ) {
|
||||
if( this.opts.pdf !== 'none' ) {
|
||||
suffix = printf( M2C( this.msgs.afterGenerate.msg[0], evt.error ? 'red' : 'green' ), this.opts.pdf );
|
||||
}
|
||||
else {
|
||||
L( M2C( this.msgs.afterGenerate.msg[1], 'gray' ),
|
||||
evt.fmt.toUpperCase(), evt.file );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
L( M2C( this.msgs.afterGenerate.msg[2] + suffix, evt.error ? 'red' : 'green' ),
|
||||
pad(evt.fmt.toUpperCase(),4,null,pad.RIGHT),
|
||||
PATH.relative(process.cwd(), evt.file ));
|
||||
break;
|
||||
|
||||
case HME.beforeAnalyze:
|
||||
L( M2C( this.msgs.beforeAnalyze.msg, 'green' ), evt.fmt, evt.file);
|
||||
break;
|
||||
|
||||
case HME.afterAnalyze:
|
||||
var info = evt.info;
|
||||
var rawTpl = FS.readFileSync( PATH.join( __dirname, 'analyze.hbs' ), 'utf8');
|
||||
HANDLEBARS.registerHelper( require('hackmycore/src/helpers/console-helpers') );
|
||||
var template = HANDLEBARS.compile(rawTpl, { strict: false, assumeObjects: false });
|
||||
var tot = 0;
|
||||
info.keywords.forEach(function(g) { tot += g.count; });
|
||||
info.keywords.totalKeywords = tot;
|
||||
var output = template( info );
|
||||
this.log( chalk.cyan(output) );
|
||||
break;
|
||||
|
||||
case HME.beforeConvert:
|
||||
L( M2C( this.msgs.beforeConvert.msg, 'green' ),
|
||||
evt.srcFile, evt.srcFmt, evt.dstFile, evt.dstFmt
|
||||
);
|
||||
break;
|
||||
|
||||
case HME.afterInlineConvert:
|
||||
L( M2C( this.msgs.afterInlineConvert.msg, 'gray', 'white.dim' ),
|
||||
evt.file, evt.fmt );
|
||||
break;
|
||||
|
||||
case HME.afterValidate:
|
||||
var style = evt.isValid ? 'green' : 'yellow';
|
||||
L(
|
||||
M2C( this.msgs.afterValidate.msg[0], 'white' ) +
|
||||
chalk[style].bold( evt.isValid ?
|
||||
this.msgs.afterValidate.msg[1] :
|
||||
this.msgs.afterValidate.msg[2] ),
|
||||
evt.file, evt.fmt
|
||||
);
|
||||
|
||||
if( evt.errors ) {
|
||||
_.each(evt.errors, function(err,idx) {
|
||||
L( chalk.yellow.bold('--> ') +
|
||||
chalk.yellow(err.field.replace('data.','resume.').toUpperCase() + ' ' +
|
||||
err.message) );
|
||||
}, this);
|
||||
}
|
||||
break;
|
||||
|
||||
case HME.beforePeek:
|
||||
// if( evt.target )
|
||||
// L(M2C(this.msgs.beforePeek.msg[0], evt.isError ? 'red' : 'green'), evt.target, evt.file);
|
||||
// else
|
||||
// L(M2C(this.msgs.beforePeek.msg[1], evt.isError ? 'red' : 'green'), evt.file);
|
||||
break;
|
||||
|
||||
case HME.afterPeek:
|
||||
var sty = evt.error ? 'red' : ( evt.target !== undefined ? 'green' : 'yellow' );
|
||||
if( evt.requested )
|
||||
L(M2C(this.msgs.beforePeek.msg[0], sty), evt.requested, evt.file);
|
||||
else
|
||||
L(M2C(this.msgs.beforePeek.msg[1], sty), evt.file);
|
||||
|
||||
if( evt.target !== undefined )
|
||||
console.dir( evt.target, { depth: null, colors: true } );
|
||||
else if( !evt.error )
|
||||
L(M2C( this.msgs.afterPeek.msg, 'yellow'), evt.requested, evt.file);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
}());
|
51
dist/cli/use.txt
vendored
Normal file
51
dist/cli/use.txt
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
Usage:
|
||||
|
||||
hackmyresume <command> <sources> [TO <targets>] [<options>]
|
||||
|
||||
Available commands:
|
||||
|
||||
BUILD Build your resume to the destination format(s).
|
||||
ANALYZE Analyze your resume for keywords, gaps, and metrics.
|
||||
VALIDATE Validate your resume for errors and typos.
|
||||
CONVERT Convert your resume between FRESH and JSON Resume.
|
||||
NEW Create a new resume in FRESH or JSON Resume format.
|
||||
PEEK View a specific field or element on your resume.
|
||||
|
||||
Available options:
|
||||
|
||||
--theme -t Path to a FRESH or JSON Resume theme.
|
||||
--pdf -p Specify the PDF engine to use (wkhtmltopdf or phantom).
|
||||
--options -o Load options from an external JSON file.
|
||||
--format -f The format (FRESH or JSON Resume) to use.
|
||||
--debug -d Emit extended debugging info.
|
||||
--assert -a Treat resume validation warnings as errors.
|
||||
--no-colors Disable terminal colors.
|
||||
--tips Display theme messages and tips.
|
||||
--help -h Display help documentation.
|
||||
--version -v Display the current version.
|
||||
|
||||
Not all options are supported for all commands. For example, the
|
||||
--theme option is only supported for the BUILD command.
|
||||
|
||||
Examples:
|
||||
|
||||
hackmyresume BUILD resume.json TO out/resume.all --theme modern
|
||||
hackmyresume ANALYZE resume.json
|
||||
hackmyresume NEW my-new-resume.json --format JRS
|
||||
hackmyresume CONVERT resume-fresh.json TO resume-jrs.json
|
||||
hackmyresume VALIDATE resume.json
|
||||
hackmyresume PEEK resume.json employment[2].summary
|
||||
|
||||
Tips:
|
||||
|
||||
- You can specify multiple sources and/or targets for all commands.
|
||||
- You can use any FRESH or JSON Resume theme with HackMyResume.
|
||||
- Specify a file extension of .all to generate your resume to all
|
||||
available formats supported by the theme. (BUILD command.)
|
||||
- The --theme parameter can specify either the name of a preinstalled
|
||||
theme, or the path to a local FRESH or JSON Resume theme.
|
||||
- Visit https://www.npmjs.com/search?q=jsonresume-theme for a full
|
||||
listing of all available JSON Resume themes.
|
||||
- Visit https://github.com/fluentdesk/fresh-themes for a complete
|
||||
listing of all available FRESH themes.
|
||||
- Report bugs to https://githut.com/hacksalot/HackMyResume/issues.
|
24
dist/index.js
vendored
Normal file
24
dist/index.js
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
#! /usr/bin/env node
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Command-line interface (CLI) for HackMyResume.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module index.js
|
||||
*/
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
require('./cli/main')( process.argv );
|
||||
|
||||
}
|
||||
catch( ex ) {
|
||||
|
||||
console.log(ex);
|
||||
if(ex.stack) console.log(ex.stack);
|
||||
require('./cli/error').err( ex, true );
|
||||
|
||||
}
|
@ -43,7 +43,7 @@
|
||||
"url": "https://github.com/hacksalot/HackMyResume/issues"
|
||||
},
|
||||
"bin": {
|
||||
"hackmyresume": "src/index.js"
|
||||
"hackmyresume": "dist/index.js"
|
||||
},
|
||||
"homepage": "https://github.com/hacksalot/HackMyResume",
|
||||
"dependencies": {
|
||||
@ -68,6 +68,8 @@
|
||||
"grunt": "*",
|
||||
"grunt-cli": "^0.1.13",
|
||||
"grunt-contrib-clean": "^0.7.0",
|
||||
"grunt-contrib-coffee": "^0.13.0",
|
||||
"grunt-contrib-copy": "^0.8.2",
|
||||
"grunt-contrib-jshint": "^0.11.3",
|
||||
"grunt-contrib-yuidoc": "^0.10.0",
|
||||
"grunt-jsdoc": "^1.1.0",
|
||||
|
313
src/cli/main.coffee
Normal file
313
src/cli/main.coffee
Normal file
@ -0,0 +1,313 @@
|
||||
###*
|
||||
Definition of the `main` function.
|
||||
@module cli/main
|
||||
@license MIT. See LICENSE.md for details.
|
||||
###
|
||||
|
||||
|
||||
|
||||
HMR = require 'hackmycore'
|
||||
PKG = require '../../package.json'
|
||||
FS = require 'fs'
|
||||
EXTEND = require 'extend'
|
||||
chalk = require 'chalk'
|
||||
PATH = require 'path'
|
||||
HMSTATUS = require 'hackmycore/src/core/status-codes'
|
||||
HME = require 'hackmycore/src/core/event-codes'
|
||||
safeLoadJSON = require 'hackmycore/src/utils/safe-json-loader'
|
||||
StringUtils = require 'hackmycore/src/utils/string.js'
|
||||
_ = require 'underscore'
|
||||
OUTPUT = require './out'
|
||||
PAD = require 'string-padding'
|
||||
Command = require('commander').Command
|
||||
_opts = { }
|
||||
_title = chalk.white.bold('\n*** HackMyResume v' +PKG.version+ ' ***')
|
||||
_out = new OUTPUT( _opts )
|
||||
|
||||
|
||||
|
||||
###
|
||||
A callable implementation of the HackMyResume CLI. Encapsulates the command
|
||||
line interface as a single method accepting a parameter array.
|
||||
@alias module:cli/main.main
|
||||
@param rawArgs {Array} An array of command-line parameters. Will either be
|
||||
process.argv (in production) or custom parameters (in test).
|
||||
###
|
||||
main = module.exports = (rawArgs ) ->
|
||||
|
||||
initInfo = initialize( rawArgs )
|
||||
args = initInfo.args
|
||||
|
||||
# Create the top-level (application) command...
|
||||
program = new Command('hackmyresume')
|
||||
.version(PKG.version)
|
||||
.description(chalk.yellow.bold('*** HackMyResume ***'))
|
||||
.option('-s --silent', 'Run in silent mode')
|
||||
.option('--no-color', 'Disable colors')
|
||||
.option('--color', 'Enable colors')
|
||||
.option('-d --debug', 'Enable diagnostics', false)
|
||||
.option('-a --assert', 'Treat warnings as errors', false)
|
||||
.option('-v --version', 'Show the version')
|
||||
.allowUnknownOption();
|
||||
program.jsonArgs = initInfo.options
|
||||
|
||||
# Create the NEW command
|
||||
program
|
||||
.command 'new'
|
||||
.arguments '<sources...>'
|
||||
.option '-f --format <fmt>', 'FRESH or JRS format', 'FRESH'
|
||||
.alias 'create'
|
||||
.description 'Create resume(s) in FRESH or JSON RESUME format.'
|
||||
.action (( sources ) ->
|
||||
execute.call( this, sources, [], this.opts(), logMsg)
|
||||
return
|
||||
)
|
||||
|
||||
# Create the VALIDATE command
|
||||
program
|
||||
.command('validate')
|
||||
.arguments('<sources...>')
|
||||
.description('Validate a resume in FRESH or JSON RESUME format.')
|
||||
.action((sources) ->
|
||||
execute.call( this, sources, [], this.opts(), logMsg)
|
||||
return
|
||||
)
|
||||
|
||||
# Create the CONVERT command
|
||||
program
|
||||
.command('convert')
|
||||
.description('Convert a resume to/from FRESH or JSON RESUME format.')
|
||||
.action(->
|
||||
x = splitSrcDest.call( this );
|
||||
execute.call( this, x.src, x.dst, this.opts(), logMsg)
|
||||
return
|
||||
)
|
||||
|
||||
# Create the ANALYZE command
|
||||
program
|
||||
.command('analyze')
|
||||
.arguments('<sources...>')
|
||||
.description('Analyze one or more resumes.')
|
||||
.action(( sources ) ->
|
||||
execute.call( this, sources, [], this.opts(), logMsg)
|
||||
return
|
||||
)
|
||||
|
||||
# Create the PEEK command
|
||||
program
|
||||
.command('peek')
|
||||
.arguments('<sources...>')
|
||||
.description('Peek at a resume field or section')
|
||||
.action(( sources, sectionOrField ) ->
|
||||
dst = if (sources && sources.length > 1) then [sources.pop()] else []
|
||||
execute.call( this, sources, dst, this.opts(), logMsg)
|
||||
return
|
||||
)
|
||||
|
||||
# Create the BUILD command
|
||||
program
|
||||
.command('build')
|
||||
.alias('generate')
|
||||
.option('-t --theme <theme>', 'Theme name or path')
|
||||
.option('-n --no-prettify', 'Disable HTML prettification', true)
|
||||
.option('-c --css <option>', 'CSS linking / embedding')
|
||||
.option('-p --pdf <engine>', 'PDF generation engine')
|
||||
.option('--no-sort', 'Sort resume sections by date', false)
|
||||
.option('--tips', 'Display theme tips and warnings.', false)
|
||||
.description('Generate resume to multiple formats')
|
||||
.action(( sources, targets, options ) ->
|
||||
x = splitSrcDest.call( this );
|
||||
execute.call( this, x.src, x.dst, this.opts(), logMsg)
|
||||
return
|
||||
)
|
||||
|
||||
program.parse( args )
|
||||
|
||||
if !program.args.length
|
||||
throw { fluenterror: 4 }
|
||||
|
||||
|
||||
|
||||
### Massage command-line args and setup Commander.js. ###
|
||||
initialize = ( ar ) ->
|
||||
|
||||
o = initOptions( ar );
|
||||
|
||||
o.silent || logMsg( _title )
|
||||
|
||||
# Emit debug prelude if --debug was specified
|
||||
if o.debug
|
||||
_out.log(chalk.cyan('The -d or --debug switch was specified. DEBUG mode engaged.'))
|
||||
_out.log('')
|
||||
_out.log(chalk.cyan(PAD(' Platform:',25, null, PAD.RIGHT)) + chalk.cyan.bold( if process.platform == 'win32' then 'windows' else process.platform ))
|
||||
_out.log(chalk.cyan(PAD(' Node.js:',25, null, PAD.RIGHT)) + chalk.cyan.bold( process.version ))
|
||||
_out.log(chalk.cyan(PAD(' HackMyResume:',25, null, PAD.RIGHT)) + chalk.cyan.bold('v' + PKG.version ))
|
||||
_out.log(chalk.cyan(PAD(' FRESCA:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies.fresca ))
|
||||
#_out.log(chalk.cyan(PAD(' fresh-themes:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies['fresh-themes'] ))
|
||||
#_out.log(chalk.cyan(PAD(' fresh-jrs-converter:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies['fresh-jrs-converter'] ))
|
||||
_out.log('')
|
||||
|
||||
# Handle invalid verbs here (a bit easier here than in commander.js)...
|
||||
if o.verb && !HMR.verbs[ o.verb ] && !HMR.alias[ o.verb ]
|
||||
throw { fluenterror: HMSTATUS.invalidCommand, quit: true, attempted: o.orgVerb }
|
||||
|
||||
# Override the .missingArgument behavior
|
||||
Command.prototype.missingArgument = (name) ->
|
||||
if this.name() != 'new'
|
||||
throw { fluenterror: HMSTATUS.resumeNotFound, quit: true }
|
||||
|
||||
# Override the .helpInformation behavior
|
||||
Command.prototype.helpInformation = ->
|
||||
manPage = FS.readFileSync(
|
||||
PATH.join(__dirname, 'use.txt'), 'utf8' )
|
||||
return chalk.green.bold(manPage)
|
||||
|
||||
return {
|
||||
args: o.args,
|
||||
options: o.json
|
||||
}
|
||||
|
||||
|
||||
|
||||
### Init options prior to setting up command infrastructure. ###
|
||||
initOptions = ( ar ) ->
|
||||
|
||||
oVerb
|
||||
verb = ''
|
||||
args = ar.slice()
|
||||
cleanArgs = args.slice(2)
|
||||
oJSON
|
||||
|
||||
if cleanArgs.length
|
||||
|
||||
# Support case-insensitive sub-commands (build, generate, validate, etc)
|
||||
vidx = _.findIndex( cleanArgs, (v) -> return v[0] != '-' )
|
||||
if vidx != -1
|
||||
oVerb = cleanArgs[ vidx ]
|
||||
verb = args[ vidx + 2 ] = oVerb.trim().toLowerCase()
|
||||
|
||||
# Remove --options --opts -o and process separately
|
||||
optsIdx = _.findIndex( cleanArgs, (v) ->
|
||||
return v == '-o' || v == '--options' || v == '--opts'
|
||||
);
|
||||
|
||||
if optsIdx != -1
|
||||
optStr = cleanArgs[ optsIdx + 1]
|
||||
args.splice( optsIdx + 2, 2 )
|
||||
if optStr && (optStr = optStr.trim())
|
||||
#var myJSON = JSON.parse(optStr);
|
||||
if( optStr[0] == '{')
|
||||
### jshint ignore:start ###
|
||||
oJSON = eval('(' + optStr + ')') # jshint ignore:line <-- no worky
|
||||
### jshint ignore:end ###
|
||||
else
|
||||
inf = safeLoadJSON( optStr )
|
||||
if( !inf.ex )
|
||||
oJSON = inf.json
|
||||
# TODO: Error handling
|
||||
|
||||
|
||||
# Grab the --debug flag
|
||||
isDebug = _.some( args, (v) ->
|
||||
return v == '-d' || v == '--debug'
|
||||
)
|
||||
|
||||
# Grab the --silent flag
|
||||
isSilent = _.some( args, (v) ->
|
||||
return v == '-s' || v == '--silent'
|
||||
)
|
||||
|
||||
return {
|
||||
debug: isDebug,
|
||||
silent: isSilent,
|
||||
orgVerb: oVerb,
|
||||
verb: verb,
|
||||
json: oJSON,
|
||||
args: args
|
||||
}
|
||||
|
||||
|
||||
|
||||
### Invoke a HackMyResume verb. ###
|
||||
execute = ( src, dst, opts, log ) ->
|
||||
|
||||
loadOptions.call( this, opts, this.parent.jsonArgs )
|
||||
hand = require( './error' )
|
||||
hand.init( _opts.debug, _opts.assert, _opts.silent )
|
||||
v = new HMR.verbs[ this.name() ]()
|
||||
_opts.errHandler = v
|
||||
_out.init( _opts )
|
||||
v.on( 'hmr:status', -> _out.do.apply( _out, arguments ) )
|
||||
v.on( 'hmr:error', -> hand.err.apply( hand, arguments ) )
|
||||
v.invoke.call( v, src, dst, _opts, log )
|
||||
if v.errorCode
|
||||
process.exit(v.errorCode)
|
||||
|
||||
|
||||
|
||||
###
|
||||
Initialize HackMyResume options.
|
||||
TODO: Options loading is a little hacky, for two reasons:
|
||||
- Commander.js idiosyncracies
|
||||
- Need to accept JSON inputs from the command line.
|
||||
###
|
||||
loadOptions = ( o, cmdO ) ->
|
||||
|
||||
# o and this.opts() seem to be the same (command-specific options)
|
||||
|
||||
# Load the specified options file (if any) and apply options
|
||||
if( cmdO )
|
||||
o = EXTEND(true, o, cmdO)
|
||||
|
||||
# Merge in command-line options
|
||||
o = EXTEND( true, o, this.opts() )
|
||||
|
||||
# Kludge parent-level options until piping issue is resolved
|
||||
if this.parent.silent != undefined && this.parent.silent != null
|
||||
o.silent = this.parent.silent
|
||||
if this.parent.debug != undefined && this.parent.debug != null
|
||||
o.debug = this.parent.debug
|
||||
if this.parent.assert != undefined && this.parent.assert != null
|
||||
o.assert = this.parent.assert
|
||||
|
||||
if o.debug
|
||||
logMsg(chalk.cyan('OPTIONS:') + '\n')
|
||||
_.each(o, (val, key) ->
|
||||
logMsg(chalk.cyan(' %s') + chalk.cyan.bold(' %s'),
|
||||
PAD(key,22,null,PAD.RIGHT), val)
|
||||
);
|
||||
logMsg('');
|
||||
|
||||
# Cache
|
||||
EXTEND(true, _opts, o)
|
||||
return
|
||||
|
||||
### Split multiple command-line filenames by the 'TO' keyword ###
|
||||
splitSrcDest = ->
|
||||
|
||||
params = this.parent.args.filter((j) -> return String.is(j) )
|
||||
if params.length == 0
|
||||
throw { fluenterror: HMSTATUS.resumeNotFound, quit: true }
|
||||
|
||||
# Find the TO keyword, if any
|
||||
splitAt = _.findIndex( params, (p) -> return p.toLowerCase() == 'to'; )
|
||||
|
||||
# TO can't be the last keyword
|
||||
if splitAt == params.length - 1 && splitAt != -1
|
||||
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('.') )
|
||||
return
|
||||
|
||||
return {
|
||||
src: params.slice(0, if splitAt == -1 then undefined else splitAt ),
|
||||
dst: if splitAt == -1 then [] else params.slice( splitAt + 1 )
|
||||
}
|
||||
|
||||
|
||||
|
||||
### Simple logging placeholder. ###
|
||||
logMsg = ->
|
||||
_opts.silent || console.log.apply( console.log, arguments )
|
331
src/cli/main.js
331
src/cli/main.js
@ -1,331 +0,0 @@
|
||||
/**
|
||||
Definition of the `main` function.
|
||||
@module cli/main
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function(){
|
||||
|
||||
|
||||
|
||||
var HMR = require( 'hackmycore')
|
||||
, PKG = require('../../package.json')
|
||||
, FS = require('fs')
|
||||
, EXTEND = require('extend')
|
||||
, chalk = require('chalk')
|
||||
, PATH = require('path')
|
||||
, HMSTATUS = require('hackmycore/src/core/status-codes')
|
||||
, HME = require('hackmycore/src/core/event-codes')
|
||||
, safeLoadJSON = require('hackmycore/src/utils/safe-json-loader')
|
||||
, StringUtils = require('hackmycore/src/utils/string.js')
|
||||
, _ = require('underscore')
|
||||
, OUTPUT = require('./out')
|
||||
, PAD = require('string-padding')
|
||||
, Command = require('commander').Command;
|
||||
|
||||
var _opts = { };
|
||||
var _title = chalk.white.bold('\n*** HackMyResume v' +PKG.version+ ' ***');
|
||||
var _out = new OUTPUT( _opts );
|
||||
|
||||
|
||||
|
||||
/**
|
||||
A callable implementation of the HackMyResume CLI. Encapsulates the command
|
||||
line interface as a single method accepting a parameter array.
|
||||
@alias module:cli/main.main
|
||||
@param rawArgs {Array} An array of command-line parameters. Will either be
|
||||
process.argv (in production) or custom parameters (in test).
|
||||
*/
|
||||
var main = module.exports = function( rawArgs ) {
|
||||
|
||||
var initInfo = initialize( rawArgs );
|
||||
var args = initInfo.args;
|
||||
|
||||
// Create the top-level (application) command...
|
||||
var program = new Command('hackmyresume')
|
||||
.version(PKG.version)
|
||||
.description(chalk.yellow.bold('*** HackMyResume ***'))
|
||||
.option('-s --silent', 'Run in silent mode')
|
||||
.option('--no-color', 'Disable colors')
|
||||
.option('--color', 'Enable colors')
|
||||
.option('-d --debug', 'Enable diagnostics', false)
|
||||
.option('-a --assert', 'Treat warnings as errors', false)
|
||||
.option('-v --version', 'Show the version')
|
||||
.allowUnknownOption();
|
||||
program.jsonArgs = initInfo.options;
|
||||
|
||||
// Create the NEW command
|
||||
program
|
||||
.command('new')
|
||||
.arguments('<sources...>')
|
||||
.option('-f --format <fmt>', 'FRESH or JRS format', 'FRESH')
|
||||
.alias('create')
|
||||
.description('Create resume(s) in FRESH or JSON RESUME format.')
|
||||
.action(function( sources ) {
|
||||
execute.call( this, sources, [], this.opts(), logMsg);
|
||||
});
|
||||
|
||||
// Create the VALIDATE command
|
||||
program
|
||||
.command('validate')
|
||||
.arguments('<sources...>')
|
||||
.description('Validate a resume in FRESH or JSON RESUME format.')
|
||||
.action(function(sources) {
|
||||
execute.call( this, sources, [], this.opts(), logMsg);
|
||||
});
|
||||
|
||||
// Create the CONVERT command
|
||||
program
|
||||
.command('convert')
|
||||
.description('Convert a resume to/from FRESH or JSON RESUME format.')
|
||||
.action(function() {
|
||||
var x = splitSrcDest.call( this );
|
||||
execute.call( this, x.src, x.dst, this.opts(), logMsg);
|
||||
});
|
||||
|
||||
// Create the ANALYZE command
|
||||
program
|
||||
.command('analyze')
|
||||
.arguments('<sources...>')
|
||||
.description('Analyze one or more resumes.')
|
||||
.action(function( sources ) {
|
||||
execute.call( this, sources, [], this.opts(), logMsg);
|
||||
});
|
||||
|
||||
// Create the PEEK command
|
||||
program
|
||||
.command('peek')
|
||||
.arguments('<sources...>')
|
||||
.description('Peek at a resume field or section')
|
||||
.action(function( sources, sectionOrField ) {
|
||||
var dst = (sources && sources.length > 1) ? [sources.pop()] : [];
|
||||
execute.call( this, sources, dst, this.opts(), logMsg);
|
||||
});
|
||||
|
||||
// Create the BUILD command
|
||||
program
|
||||
.command('build')
|
||||
.alias('generate')
|
||||
.option('-t --theme <theme>', 'Theme name or path')
|
||||
.option('-n --no-prettify', 'Disable HTML prettification', true)
|
||||
.option('-c --css <option>', 'CSS linking / embedding')
|
||||
.option('-p --pdf <engine>', 'PDF generation engine')
|
||||
.option('--no-sort', 'Sort resume sections by date', false)
|
||||
.option('--tips', 'Display theme tips and warnings.', false)
|
||||
.description('Generate resume to multiple formats')
|
||||
.action(function( sources, targets, options ) {
|
||||
var x = splitSrcDest.call( this );
|
||||
execute.call( this, x.src, x.dst, this.opts(), logMsg);
|
||||
});
|
||||
|
||||
program.parse( args );
|
||||
|
||||
if (!program.args.length) { throw { fluenterror: 4 }; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Massage command-line args and setup Commander.js. */
|
||||
function initialize( ar ) {
|
||||
|
||||
var o = initOptions( ar );
|
||||
|
||||
o.silent || logMsg( _title );
|
||||
|
||||
// Emit debug prelude if --debug was specified
|
||||
if( o.debug ) {
|
||||
_out.log(chalk.cyan('The -d or --debug switch was specified. DEBUG mode engaged.'));
|
||||
_out.log('');
|
||||
_out.log(chalk.cyan(PAD(' Platform:',25, null, PAD.RIGHT)) + chalk.cyan.bold( process.platform === 'win32' ? 'windows' : process.platform ));
|
||||
_out.log(chalk.cyan(PAD(' Node.js:',25, null, PAD.RIGHT)) + chalk.cyan.bold( process.version ));
|
||||
_out.log(chalk.cyan(PAD(' HackMyResume:',25, null, PAD.RIGHT)) + chalk.cyan.bold('v' + PKG.version ));
|
||||
_out.log(chalk.cyan(PAD(' FRESCA:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies.fresca ));
|
||||
//_out.log(chalk.cyan(PAD(' fresh-themes:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies['fresh-themes'] ));
|
||||
//_out.log(chalk.cyan(PAD(' fresh-jrs-converter:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies['fresh-jrs-converter'] ));
|
||||
_out.log('');
|
||||
}
|
||||
|
||||
// Handle invalid verbs here (a bit easier here than in commander.js)...
|
||||
if( o.verb && !HMR.verbs[ o.verb ] && !HMR.alias[ o.verb ] ) {
|
||||
throw { fluenterror: HMSTATUS.invalidCommand, quit: true,
|
||||
attempted: o.orgVerb };
|
||||
}
|
||||
|
||||
// Override the .missingArgument behavior
|
||||
Command.prototype.missingArgument = function(name) {
|
||||
if( this.name() !== 'new' ) {
|
||||
throw { fluenterror: HMSTATUS.resumeNotFound, quit: true };
|
||||
}
|
||||
};
|
||||
|
||||
// Override the .helpInformation behavior
|
||||
Command.prototype.helpInformation = function() {
|
||||
var manPage = FS.readFileSync(
|
||||
PATH.join(__dirname, 'use.txt'), 'utf8' );
|
||||
return chalk.green.bold(manPage);
|
||||
};
|
||||
|
||||
return {
|
||||
args: o.args,
|
||||
options: o.json
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Init options prior to setting up command infrastructure. */
|
||||
function initOptions( ar ) {
|
||||
var oVerb, verb = '', args = ar.slice(), cleanArgs = args.slice(2), oJSON;
|
||||
if( cleanArgs.length ) {
|
||||
|
||||
// Support case-insensitive sub-commands (build, generate, validate, etc)
|
||||
var vidx = _.findIndex( cleanArgs, function(v){ return v[0] !== '-'; });
|
||||
if( vidx !== -1 ) {
|
||||
oVerb = cleanArgs[ vidx ];
|
||||
verb = args[ vidx + 2 ] = oVerb.trim().toLowerCase();
|
||||
}
|
||||
|
||||
// Remove --options --opts -o and process separately
|
||||
var optsIdx = _.findIndex( cleanArgs, function(v){
|
||||
return v === '-o' || v === '--options' || v === '--opts';
|
||||
});
|
||||
if(optsIdx !== -1) {
|
||||
var optStr = cleanArgs[ optsIdx + 1];
|
||||
args.splice( optsIdx + 2, 2 );
|
||||
if( optStr && (optStr = optStr.trim()) ) {
|
||||
//var myJSON = JSON.parse(optStr);
|
||||
if( optStr[0] === '{')
|
||||
oJSON = eval('(' + optStr + ')'); // jshint ignore:line
|
||||
else {
|
||||
var inf = safeLoadJSON( optStr );
|
||||
if( !inf.ex )
|
||||
oJSON = inf.json;
|
||||
// TODO: Error handling
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Grab the --debug flag
|
||||
var isDebug = _.some( args, function(v) {
|
||||
return v === '-d' || v === '--debug';
|
||||
});
|
||||
|
||||
// Grab the --silent flag
|
||||
var isSilent = _.some( args, function(v) {
|
||||
return v === '-s' || v === '--silent';
|
||||
});
|
||||
|
||||
return {
|
||||
debug: isDebug,
|
||||
silent: isSilent,
|
||||
orgVerb: oVerb,
|
||||
verb: verb,
|
||||
json: oJSON,
|
||||
args: args
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Invoke a HackMyResume verb. */
|
||||
function execute( src, dst, opts, log ) {
|
||||
|
||||
loadOptions.call( this, opts, this.parent.jsonArgs );
|
||||
var hand = require( './error' );
|
||||
hand.init( _opts.debug, _opts.assert, _opts.silent );
|
||||
var v = new HMR.verbs[ this.name() ]();
|
||||
_opts.errHandler = v;
|
||||
_out.init( _opts );
|
||||
v.on( 'hmr:status', function() { _out.do.apply( _out, arguments ); });
|
||||
v.on( 'hmr:error', function() {
|
||||
hand.err.apply( hand, arguments );
|
||||
});
|
||||
v.invoke.call( v, src, dst, _opts, log );
|
||||
if( v.errorCode )
|
||||
process.exit(v.errorCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Initialize HackMyResume options.
|
||||
TODO: Options loading is a little hacky, for two reasons:
|
||||
- Commander.js idiosyncracies
|
||||
- Need to accept JSON inputs from the command line.
|
||||
*/
|
||||
function loadOptions( o, cmdO ) {
|
||||
|
||||
// o and this.opts() seem to be the same (command-specific options)
|
||||
|
||||
// Load the specified options file (if any) and apply options
|
||||
if( cmdO )
|
||||
o = EXTEND(true, o, cmdO);
|
||||
|
||||
// Merge in command-line options
|
||||
o = EXTEND( true, o, this.opts() );
|
||||
|
||||
// Kludge parent-level options until piping issue is resolved
|
||||
if( this.parent.silent !== undefined && this.parent.silent !== null)
|
||||
o.silent = this.parent.silent;
|
||||
if( this.parent.debug !== undefined && this.parent.debug !== null)
|
||||
o.debug = this.parent.debug;
|
||||
if( this.parent.assert !== undefined && this.parent.assert !== null)
|
||||
o.assert = this.parent.assert;
|
||||
|
||||
if( o.debug ) {
|
||||
logMsg(chalk.cyan('OPTIONS:') + '\n');
|
||||
_.each(o, function(val, key) {
|
||||
logMsg(chalk.cyan(' %s') + chalk.cyan.bold(' %s'),
|
||||
PAD(key,22,null,PAD.RIGHT), val);
|
||||
});
|
||||
logMsg('');
|
||||
}
|
||||
|
||||
// Cache
|
||||
EXTEND(true, _opts, o);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Split multiple command-line filenames by the 'TO' keyword */
|
||||
function splitSrcDest() {
|
||||
|
||||
var params = this.parent.args.filter(function(j) { return String.is(j); });
|
||||
if( params.length === 0 )
|
||||
throw { fluenterror: HMSTATUS.resumeNotFound, quit: true };
|
||||
|
||||
// Find the TO keyword, if any
|
||||
var splitAt = _.findIndex( params, function(p) {
|
||||
return p.toLowerCase() === 'to';
|
||||
});
|
||||
|
||||
// TO can't be the last keyword
|
||||
if( splitAt === params.length - 1 && splitAt !== -1 ) {
|
||||
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('.') );
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
src: params.slice(0, splitAt === -1 ? undefined : splitAt ),
|
||||
dst: splitAt === -1 ? [] : params.slice( splitAt + 1 )
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Simple logging placeholder. */
|
||||
function logMsg() {
|
||||
_opts.silent || console.log.apply( console.log, arguments );
|
||||
}
|
||||
|
||||
|
||||
|
||||
}());
|
@ -17,6 +17,8 @@ try {
|
||||
}
|
||||
catch( ex ) {
|
||||
|
||||
console.log(ex);
|
||||
if(ex.stack) console.log(ex.stack);
|
||||
require('./cli/error').err( ex, true );
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ CLI test routines for HackMyResume.
|
||||
|
||||
var chai = require('chai')
|
||||
, should = chai.should()
|
||||
, HMRMAIN = require('../src/cli/main')
|
||||
, HMRMAIN = require('../dist/cli/main')
|
||||
, CHALK = require('chalk')
|
||||
, FS = require('fs')
|
||||
, PATH = require('path')
|
||||
@ -39,13 +39,12 @@ describe('Testing CLI interface', function () {
|
||||
process.exit = MyProcessExit;
|
||||
|
||||
try {
|
||||
var HMRMAIN = require('../src/cli/main');
|
||||
HMRMAIN( args );
|
||||
}
|
||||
catch( ex ) {
|
||||
require('../src/cli/error').err( ex, false );
|
||||
//if(ex.stack || (ex.inner && ex.inner.stacl))
|
||||
//console.log(ex.stack || ex.inner.stack);
|
||||
require('../dist/cli/error').err( ex, false );
|
||||
if(ex.stack || (ex.inner && ex.inner.stacl))
|
||||
console.log(ex.stack || ex.inner.stack);
|
||||
}
|
||||
process.exit = ProcessExitOrg;
|
||||
|
||||
|
@ -4,10 +4,6 @@
|
||||
0|--debug
|
||||
0|-d
|
||||
5|notacommand
|
||||
3|build
|
||||
14|build doesnt-exist.json
|
||||
14|build doesnt-exist.json -t not-a-theme
|
||||
14|build doesnt-exist.json -t node_modules/not-a-theme
|
||||
8|new
|
||||
0|new test/sandbox/cli-test/new-empty-resume.auto.json
|
||||
0|new test/sandbox/cli-test/new-empty-resume.jrs.json -f jrs
|
||||
@ -25,3 +21,13 @@
|
||||
0|peek test/resumes/jrs-0.0.0/richard-hendriks.json work[0]
|
||||
0|peek node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json employment.history[1]
|
||||
0|peek node_modules/fresh-test-resumes/src/fresh/johnny-trouble.json skills.sets
|
||||
3|build
|
||||
0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json test/sandbox/cli-test/jane/resume.html
|
||||
0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json test/sandbox/cli-test/jane/resume.pdf
|
||||
0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json test/sandbox/cli-test/jane/resume.md
|
||||
0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json test/sandbox/cli-test/jane/resume.txt
|
||||
0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json test/sandbox/cli-test/jane/resume.yml
|
||||
0|build node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json test/sandbox/cli-test/jane/resume.json
|
||||
14|build doesnt-exist.json
|
||||
14|build doesnt-exist.json -t not-a-theme
|
||||
14|build doesnt-exist.json -t node_modules/not-a-theme
|
||||
|
@ -7,7 +7,7 @@ Output test routines for HackMyResume.
|
||||
|
||||
var chai = require('chai')
|
||||
, expect = chai.expect
|
||||
, HMRMAIN = require('../src/cli/main')
|
||||
, HMRMAIN = require('../dist/cli/main')
|
||||
, CHALK = require('chalk')
|
||||
, FS = require('fs')
|
||||
, PATH = require('path')
|
||||
@ -46,11 +46,10 @@ describe('Testing Ouput interface', function () {
|
||||
try {
|
||||
args.unshift( process.argv[1] );
|
||||
args.unshift( process.argv[0] );
|
||||
var HMRMAIN = require('../src/cli/main');
|
||||
HMRMAIN( args );
|
||||
}
|
||||
catch( ex ) {
|
||||
require('../src/cli/error').err( ex, false );
|
||||
require('../dist/cli/error').err( ex, false );
|
||||
}
|
||||
CHALK.enabled = true;
|
||||
process.exit = ProcessExitOrg;
|
||||
|
Loading…
Reference in New Issue
Block a user