diff --git a/cli.js b/cli.js index ac32322..9f707ad 100755 --- a/cli.js +++ b/cli.js @@ -15,9 +15,12 @@ var join = require('path').join; var open = require('opn'); var got = require('got'); var fs = require('fs'); +var giffyBreak = require('giffy-break'); var imgcat = join(__dirname, 'node_modules', '.bin', 'imgcat'); +var API_KEY = 'dc6zaTOxFJmzC'; + /** * npm install + gifs @@ -28,17 +31,32 @@ var ps = npm(args); var gif; if (isInstall(args)) { - findImages() - .then(displayImages) - .catch(errorHandler); + if (isIterm) { + findImages() + .then(displayImages) + .catch(errorHandler); - ps.on('exit', function (code) { - if (gif) { - gif.kill(); - } + ps.on('exit', function (code) { + if (gif) { + gif.kill(); + } - process.exit(code); - }); + process.exit(code); + }); + } else { + var promise = new Promise(function (resolve, reject) { + ps.on('exit', function (code) { + (code === 0 ? resolve : reject)(code); + }); + }); + + giffyBreak(promise, API_KEY, { + interval: 3000, + startMessage: 'Running $ npm ' + args.join(' ') + '' + }) + .then(open) + .catch(errorHandler); + } } function isInstall (args) { @@ -56,18 +74,12 @@ function findImages () { return got('http://api.giphy.com/v1/gifs/trending', { json: true, query: { - api_key: 'dc6zaTOxFJmzC' + api_key: API_KEY } }); } function showImage (url, done) { - if (!isIterm) { - open(url); - done(); - return; - } - var path = tempfile(); var image = fs.createWriteStream(path); diff --git a/package.json b/package.json index 35bb72d..903e29c 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "array-shuffle": "^1.0.0", "cross-spawn-async": "^2.1.9", "each-series": "^1.0.0", + "giffy-break": "^0.4.1", "got": "^5.5.0", "imgcat": "^0.1.1", "is-iterm": "^1.0.0",