diff options
author | Matthias Pfeil <matthias.pfeil@wwu.de> | 2016-06-17 16:00:53 +0200 |
---|---|---|
committer | Matthias Pfeil <matthias.pfeil@wwu.de> | 2016-06-17 16:00:53 +0200 |
commit | d86f9b266707ccbe94e01e83e6d8b2f5e3686a2c (patch) | |
tree | 70221a0f34d166fec0a900710e886895df041144 /lib/cli | |
parent | aca4313fc3119c00cfdc9a3fa78e2164660f0918 (diff) | |
download | gitbook-d86f9b266707ccbe94e01e83e6d8b2f5e3686a2c.zip gitbook-d86f9b266707ccbe94e01e83e6d8b2f5e3686a2c.tar.gz gitbook-d86f9b266707ccbe94e01e83e6d8b2f5e3686a2c.tar.bz2 |
add open and browser args to serve command
Diffstat (limited to 'lib/cli')
-rw-r--r-- | lib/cli/serve.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/cli/serve.js b/lib/cli/serve.js index 4ba5148..0802d8d 100644 --- a/lib/cli/serve.js +++ b/lib/cli/serve.js @@ -1,6 +1,7 @@ /* eslint-disable no-console */ var tinylr = require('tiny-lr'); +var open = require('open'); var Parse = require('../parse'); var Output = require('../output'); @@ -32,9 +33,11 @@ function generateBook(args, kwargs) { var outputFolder = getOutputFolder(args); var book = getBook(args, kwargs); var Generator = Output.getGenerator(kwargs.format); + var browser = kwargs['browser']; var hasWatch = kwargs['watch']; var hasLiveReloading = kwargs['live']; + var hasOpen = kwargs['open']; // Stop server if running if (server.isRunning()) console.log('Stopping server'); @@ -71,6 +74,10 @@ function generateBook(args, kwargs) { } }); } + + if (hasOpen) { + open('http://localhost:'+port, browser); + } }) .then(function() { if (!hasWatch) { @@ -112,6 +119,16 @@ module.exports = { description: 'Enable live reloading', defaults: true }, + { + name: 'open', + description: 'Enable opening book in browser', + defaults: true + }, + { + name: 'browser', + description: 'Specify browser for opening book', + defaults: '' + }, options.log, options.format ], |