diff --git a/dist/cli/main.js b/dist/cli/main.js index 40a3da1..b511831 100644 --- a/dist/cli/main.js +++ b/dist/cli/main.js @@ -6,7 +6,7 @@ Definition of the `main` function. */ (function() { - var Command, EXTEND, FS, HME, HMR, HMSTATUS, OUTPUT, PAD, PATH, PKG, StringUtils, _, _err, _exitCallback, _opts, _out, _title, chalk, execute, initOptions, initialize, loadOptions, logMsg, main, safeLoadJSON, splitSrcDest; + var Command, EXTEND, FS, HME, HMR, HMSTATUS, M2C, OUTPUT, PAD, PATH, PKG, StringUtils, _, _err, _exitCallback, _opts, _out, _title, chalk, execute, executeFail, executeSuccess, initOptions, initialize, loadOptions, logMsg, main, printf, safeLoadJSON, splitSrcDest; HMR = require('../index'); @@ -36,6 +36,10 @@ Definition of the `main` function. Command = require('commander').Command; + M2C = require('../utils/md2chalk'); + + printf = require('printf'); + _opts = {}; _title = chalk.white.bold('\n*** HackMyResume v' + PKG.version + ' ***'); @@ -202,7 +206,7 @@ Definition of the `main` function. /* Invoke a HackMyResume verb. */ execute = function(src, dst, opts, log) { - var onFail, prom, v; + var prom, v; v = new HMR.verbs[this.name()](); loadOptions.call(this, opts, this.parent.jsonArgs); _opts.errHandler = v; @@ -214,10 +218,31 @@ Definition of the `main` function. return _err.err.apply(_err, arguments); }); prom = v.invoke.call(v, src, dst, _opts, log); - onFail = function(err) { - _exitCallback(err.fluenterror ? err.fluenterror : err); - }; - prom.then((function() {}), onFail); + prom.then(executeSuccess, executeFail); + }; + + + /* Success handler for verb invocations. Calls process.exit by default */ + + executeSuccess = function(obj) { + _exitCallback(0); + }; + + + /* Failure handler for verb invocations. Calls process.exit by default */ + + executeFail = function(err) { + var finalErrorCode, msgs; + finalErrorCode = -1; + if (err) { + finalErrorCode = err.fluenterror ? err.fluenterror : err; + console.log(err.stack); + } + if (_opts.debug) { + msgs = require('./msg').errors; + logMsg(printf(M2C(msgs.exiting.msg, 'cyan'), finalErrorCode)); + } + _exitCallback(finalErrorCode); }; diff --git a/dist/cli/msg.yml b/dist/cli/msg.yml index ebcf8a4..ae19ff1 100644 --- a/dist/cli/msg.yml +++ b/dist/cli/msg.yml @@ -100,3 +100,5 @@ errors: msg: The '**%s**' parameter was needed but not supplied. createError: msg: Failed to create **'%s'**. + exiting: + msg: Exiting with status code **%s**. diff --git a/dist/generators/word-generator.js b/dist/generators/word-generator.js index ca38707..c4c9b7d 100644 --- a/dist/generators/word-generator.js +++ b/dist/generators/word-generator.js @@ -16,13 +16,9 @@ Definition of the WordGenerator class. extend(WordGenerator, superClass); function WordGenerator() { - return WordGenerator.__super__.constructor.apply(this, arguments); + WordGenerator.__super__.constructor.call(this, 'doc', 'xml'); } - WordGenerator.prototype.init = function() { - return WordGenerator.__super__.init.call(this, 'doc', 'xml'); - }; - return WordGenerator; })(TemplateGenerator); diff --git a/dist/verbs/build.js b/dist/verbs/build.js index a5e1c88..208b58d 100644 --- a/dist/verbs/build.js +++ b/dist/verbs/build.js @@ -201,11 +201,12 @@ Implementation of the 'build' verb for HackMyResume. _rezObj = new RTYPES[toFormat]().parseJSON(rez); targets = _expand(dst, theme); _.each(targets, function(t) { + var ref; if (this.hasError() && opts.assert) { return {}; } t.final = _single.call(this, t, theme, targets); - if (t.final.fluenterror) { + if ((ref = t.final) != null ? ref.fluenterror : void 0) { t.final.quit = opts.assert; this.err(t.final.fluenterror, t.final); } @@ -258,7 +259,7 @@ Implementation of the 'build' verb for HackMyResume. f = targInfo.file; try { if (!targInfo.fmt) { - return; + return {}; } fType = targInfo.fmt.outFormat; fName = PATH.basename(f, '.' + fType); diff --git a/dist/verbs/verb.js b/dist/verbs/verb.js index f5340fc..c59c0b5 100644 --- a/dist/verbs/verb.js +++ b/dist/verbs/verb.js @@ -16,7 +16,9 @@ Definition of the Verb class. /** - An instantiation of a HackMyResume command. + An abstract invokable verb. + Provides base class functionality for verbs. Provide common services such as + error handling, event management, and promise support. @class Verb */ @@ -92,6 +94,9 @@ Definition of the Verb class. return true; }; + + /** Has an error occurred during this verb invocation? */ + Verb.prototype.hasError = function() { return this.errorCode || this.errorObj; }; diff --git a/src/cli/main.coffee b/src/cli/main.coffee index ff81492..59e7d43 100644 --- a/src/cli/main.coffee +++ b/src/cli/main.coffee @@ -20,6 +20,8 @@ _ = require 'underscore' OUTPUT = require './out' PAD = require 'string-padding' Command = require('commander').Command +M2C = require '../utils/md2chalk' +printf = require 'printf' _opts = { } _title = chalk.white.bold('\n*** HackMyResume v' +PKG.version+ ' ***') _out = new OUTPUT( _opts ) @@ -251,14 +253,29 @@ execute = ( src, dst, opts, log ) -> v.on 'hmr:status', -> _out.do.apply _out, arguments v.on 'hmr:error', -> _err.err.apply _err, arguments - # Invoke the verb! Returns a promise + # Invoke the verb using promise syntax prom = v.invoke.call v, src, dst, _opts, log + prom.then executeSuccess, executeFail - # Resolved or rejected? - onFail = (err) -> - _exitCallback( if err.fluenterror then err.fluenterror else err ) - return - prom.then (->), onFail + return + + + +### Success handler for verb invocations. Calls process.exit by default ### +executeSuccess = (obj) -> _exitCallback 0; return + + + +### Failure handler for verb invocations. Calls process.exit by default ### +executeFail = (err) -> + finalErrorCode = -1 + if err + finalErrorCode = if err.fluenterror then err.fluenterror else err + console.log err.stack + if _opts.debug + msgs = require('./msg').errors; + logMsg printf M2C( msgs.exiting.msg, 'cyan' ), finalErrorCode + _exitCallback finalErrorCode return diff --git a/src/cli/msg.yml b/src/cli/msg.yml index ebcf8a4..ae19ff1 100644 --- a/src/cli/msg.yml +++ b/src/cli/msg.yml @@ -100,3 +100,5 @@ errors: msg: The '**%s**' parameter was needed but not supplied. createError: msg: Failed to create **'%s'**. + exiting: + msg: Exiting with status code **%s**. diff --git a/src/generators/word-generator.coffee b/src/generators/word-generator.coffee index e8b765d..17e2a25 100644 --- a/src/generators/word-generator.coffee +++ b/src/generators/word-generator.coffee @@ -9,4 +9,4 @@ TemplateGenerator = require './template-generator' module.exports = class WordGenerator extends TemplateGenerator - init: () -> super 'doc', 'xml' + constructor: () -> super 'doc', 'xml' diff --git a/src/verbs/build.coffee b/src/verbs/build.coffee index e4cdb78..f47ccfe 100644 --- a/src/verbs/build.coffee +++ b/src/verbs/build.coffee @@ -139,7 +139,7 @@ _build = ( src, dst, opts ) -> _.each targets, (t) -> return { } if @hasError() and opts.assert t.final = _single.call @, t, theme, targets - if t.final.fluenterror + if t.final?.fluenterror t.final.quit = opts.assert @err t.final.fluenterror, t.final return @@ -198,7 +198,7 @@ _single = ( targInfo, theme, finished ) -> try if !targInfo.fmt - return + return { } fType = targInfo.fmt.outFormat fName = PATH.basename f, '.' + fType theFormat = null