mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-05 09:56:22 +00:00
Add support for external options file.
This commit is contained in:
parent
c8d4a3deb3
commit
f65cf8880e
45
src/index.js
45
src/index.js
@ -14,9 +14,11 @@ var SPAWNW = require('./core/spawn-watch')
|
||||
, FCMD = require( './hackmycmd')
|
||||
, PKG = require('../package.json')
|
||||
, FS = require('fs')
|
||||
, EXTEND = require('./utils/extend')
|
||||
, chalk = require('chalk')
|
||||
, PATH = require('path')
|
||||
, HACKMYSTATUS = require('./core/status-codes')
|
||||
, safeLoadJSON = require('./utils/safe-json-loader')
|
||||
, _opts = { }
|
||||
, title = chalk.white.bold('\n*** HackMyResume v' + PKG.version + ' ***')
|
||||
, StringUtils = require('./utils/string.js')
|
||||
@ -40,13 +42,6 @@ function main() {
|
||||
|
||||
var args = initialize();
|
||||
|
||||
function execVerb( src, dst, opts, log ) {
|
||||
_opts = opts;
|
||||
_opts.silent = this.parent.silent;
|
||||
_opts.opts = this.parent.opts;
|
||||
FCMD.verbs[ this.name() ].call( null, src, dst, opts, log );
|
||||
}
|
||||
|
||||
// Create the top-level (application) command...
|
||||
var program = new Command('hackmyresume')
|
||||
.version(PKG.version)
|
||||
@ -100,7 +95,7 @@ function main() {
|
||||
.alias('generate')
|
||||
//.arguments('<sources> TO [targets]')
|
||||
//.usage('...')
|
||||
.option('-t --theme <theme>', 'Theme name or path', 'modern')
|
||||
.option('-t --theme <theme>', 'Theme name or path')
|
||||
.option('-n --no-prettify', 'Disable HTML prettification', true)
|
||||
.option('-c --css <option>', 'CSS linking / embedding', 'embed')
|
||||
.option('-p --pdf <engine>', 'PDF generation engine')
|
||||
@ -165,6 +160,40 @@ function initialize() {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Invoke a HackMyResume verb.
|
||||
*/
|
||||
function execVerb( src, dst, opts, log ) {
|
||||
loadOptions.call( this, opts );
|
||||
FCMD.verbs[ this.name() ].call( null, src, dst, _opts, log );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Initialize HackMyResume options.
|
||||
*/
|
||||
function loadOptions( opts ) {
|
||||
|
||||
opts.opts = this.parent.opts;
|
||||
|
||||
// Load the specified options file (if any) and apply options
|
||||
if( opts.opts && String.is( opts.opts )) {
|
||||
var json = safeLoadJSON( PATH.relative( process.cwd(), opts.opts ) );
|
||||
json && ( opts = EXTEND( true, opts, json ) );
|
||||
if( !json ) {
|
||||
throw safeLoadJSON.error;
|
||||
}
|
||||
}
|
||||
|
||||
// Merge in command-line options
|
||||
opts = EXTEND( true, opts, this.opts() )
|
||||
opts.silent = this.parent.silent;
|
||||
_opts = opts;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Split multiple command-line filenames by the 'TO' keyword
|
||||
*/
|
||||
|
24
src/utils/safe-json-loader.js
Normal file
24
src/utils/safe-json-loader.js
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
Definition of the SafeJsonLoader class.
|
||||
@module syntax-error-ex.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
var FS = require('fs');
|
||||
|
||||
module.exports = function loadSafeJson( file ) {
|
||||
try {
|
||||
return JSON.parse( FS.readFileSync( file ) );
|
||||
}
|
||||
catch(ex) {
|
||||
loadSafeJson.error = ex;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
}());
|
@ -1,6 +1,7 @@
|
||||
/**
|
||||
Definition of the SyntaxErrorEx class.
|
||||
@module syntax-error-ex.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
@ -26,7 +27,7 @@ Definition of the SyntaxErrorEx class.
|
||||
colNum = ex.columnNumber;
|
||||
}
|
||||
if( lineNum === null || colNum === null ) {
|
||||
var JSONLint = require('json-lint');
|
||||
var JSONLint = require('json-lint'); // TODO: json-lint or is-my-json-valid?
|
||||
var lint = JSONLint( rawData, { comments: false } );
|
||||
if( lineNum === null ) lineNum = (lint.error ? lint.line : '???');
|
||||
if( colNum === null ) colNum = (lint.error ? lint.character : '???');
|
||||
|
Loading…
Reference in New Issue
Block a user