From bbaefb322764ff96b8c40e0588e5e860fdef4151 Mon Sep 17 00:00:00 2001 From: Gregory Koberger Date: Mon, 3 Oct 2016 19:42:51 -0700 Subject: [PATCH] Open docs in new window --- api.js | 4 ++-- lib/docs.js | 8 +++++++- lib/host.js | 4 ++++ utils.js | 5 +++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/api.js b/api.js index 9f9db4428..dffc19609 100644 --- a/api.js +++ b/api.js @@ -31,9 +31,9 @@ exports.api = function(args, opts) { } catch(e) { console.log('You need to log in to do this!'.red); console.log('Run ' + 'api login'.yellow); - process.exit(); + return process.exit(); } - }; + } if(actionObj.swagger) { utils.findSwagger(function(err, swagger, file) { diff --git a/lib/docs.js b/lib/docs.js index 3ef7ec40b..4193442da 100644 --- a/lib/docs.js +++ b/lib/docs.js @@ -1,3 +1,5 @@ +var utils = require('../utils'); + exports.swagger = true; exports.swaggerUrl = true; exports.login = true; @@ -6,10 +8,14 @@ exports.desc = "Upload your docs to ReadMe ($)"; exports.aliases = ['documentation', 'readme', 'readme.io', 'readmeio']; exports.run = function(config, info) { + var url = "https://swagger.readme.io/preview/" + new Buffer(info.swaggerUrl).toString('base64'); + console.log("You can view your new docs here:"); console.log(""); - console.log(" https://swagger.readme.io/preview/" + new Buffer(info.swaggerUrl).toString('base64')); + console.log(" " + url); console.log(""); + utils.open(url, info); + process.exit(); }; diff --git a/lib/host.js b/lib/host.js index bc7561c79..7b8ef4455 100644 --- a/lib/host.js +++ b/lib/host.js @@ -1,3 +1,5 @@ +var utils = require('../utils'); + exports.swagger = true; exports.swaggerUrl = true; exports.login = true; @@ -12,5 +14,7 @@ exports.run = function(config, info) { console.log(""); console.log("You can also use .yaml to get the YAML representation.".grey); + utils.open(info.swaggerUrl, info); + process.exit(); }; diff --git a/utils.js b/utils.js index 3dea1a2b6..8d3ce6909 100644 --- a/utils.js +++ b/utils.js @@ -3,6 +3,7 @@ var os = require('os'); var path = require('path'); var glob = require('glob') var figures = require('figures'); +var open = require('open'); var _ = require('lodash'); var git = require('git-utils'); @@ -210,6 +211,10 @@ exports.guessLanguage = function(cb) { return language; }; +exports.open = function(url, info) { + open(url); +}; + exports.swaggerInlineExample = function(_lang) { var prefix = ' ';