From 7dcf104da1d755061c9a45fcc5418c2cb891d43c Mon Sep 17 00:00:00 2001 From: Tapio Vierros Date: Tue, 31 Mar 2015 19:47:01 +0300 Subject: [PATCH] Merge pull request #31 from richardgoater/master Add "--open" Option --- packages/live-server/index.js | 4 ++-- packages/live-server/live-server.js | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/live-server/index.js b/packages/live-server/index.js index fa22ce03e..5a9d18da2 100644 --- a/packages/live-server/index.js +++ b/packages/live-server/index.js @@ -123,8 +123,8 @@ LiveServer.start = function(options) { console.log(('Serving "' + root + '" at ' + browserURL).green); // Launch browser - if(!noBrowser) - open(browserURL); + if (!noBrowser) + open(browserURL + (options.open || '')); }; module.exports = LiveServer; diff --git a/packages/live-server/live-server.js b/packages/live-server/live-server.js index 157ee7f63..bec04de5f 100755 --- a/packages/live-server/live-server.js +++ b/packages/live-server/live-server.js @@ -16,19 +16,29 @@ for (var i = process.argv.length-1; i >= 2; --i) { opts.port = portNumber; process.argv.splice(i, 1); } - } else if (arg == "--no-browser") { + } + else if (arg.indexOf("--open=") > -1) { + var path = arg.substring(7); + if (path.indexOf('/') != 0) { + path = '/' + path; + } + opts.open = path; + process.argv.splice(i, 1); + } + else if (arg == "--no-browser") { opts.noBrowser = true; process.argv.splice(i, 1); } else if (arg == "--quiet" || arg == "-q") { opts.logLevel = 0; process.argv.splice(i, 1); } else if (arg == "--help" || arg == "-h") { - console.log('Usage: live-server [-h|--help] [--port=PORT] [--no-browser] [PATH]'); + console.log('Usage: live-server [-h|--help] [-q|--quiet] [--port=PORT] [--open=PATH] [--no-browser] [PATH]'); process.exit(); } } -if (process.argv[2]) +if (process.argv[2]) { process.chdir(process.argv[2]); +} liveServer.start(opts);