diff options
Diffstat (limited to 'bin/utils.js')
-rw-r--r-- | bin/utils.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/bin/utils.js b/bin/utils.js index 821112e..84d2e2f 100644 --- a/bin/utils.js +++ b/bin/utils.js @@ -30,6 +30,34 @@ function watch(dir) { return d.promise; } +// exit wraps a promise +// and forcefully quits the program when the promise is resolved +function exit(promise) { + promise + .then(function() { + // Prevent badly behaving plugins + // from making the process hang + process.exit(0); + }, function(err) { + // Log error + logError(err); + + // Exit process with failure code + process.exit(-1); + }); +} + +// CLI action wrapper, calling exit when finished +function action(f) { + return function() { + // Call func and get optional promise + var p = f.apply(null, arguments); + + // Exit process + return exit(Q(p)); + } +} + function logError(err) { var message = err.message || err; if (process.env.DEBUG != null) message = err.stack || message; @@ -60,6 +88,8 @@ function runGitCommand(command, args) { // Exports module.exports = { + exit: exit, + action: action, watch: watch, logError: logError, gitCmd: runGitCommand |