1 | ;
|
2 | /**
|
3 | * @license
|
4 | * Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
5 | * This code may only be used under the BSD style license found at
|
6 | * http://polymer.github.io/LICENSE.txt
|
7 | * The complete set of authors may be found at
|
8 | * http://polymer.github.io/AUTHORS.txt
|
9 | * The complete set of contributors may be found at
|
10 | * http://polymer.github.io/CONTRIBUTORS.txt
|
11 | * Code distributed by Google as part of the polymer project is also
|
12 | * subject to an additional IP rights grant found at
|
13 | * http://polymer.github.io/PATENTS.txt
|
14 | */
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | const url = require("url");
|
17 | const opn = require("opn");
|
18 | /**
|
19 | * Open the given web page URL. If no browser keyword is provided, `opn` will
|
20 | * use the user's default browser.
|
21 | */
|
22 | function openWebPage(url, withBrowser) {
|
23 | const openOptions = { app: withBrowser };
|
24 | opn(url, openOptions, (err) => {
|
25 | if (err) {
|
26 | // log error and continue
|
27 | console.error(`ERROR: Problem launching ` +
|
28 | `"${openOptions.app || 'default web browser'}".`);
|
29 | }
|
30 | });
|
31 | }
|
32 | /**
|
33 | * Opens one or more browsers based on the given options and url params.
|
34 | *
|
35 | * @param options
|
36 | * @param serverUrl
|
37 | * @param componentUrl
|
38 | */
|
39 | function openBrowser(options, serverUrl, componentUrl) {
|
40 | if (options.open) {
|
41 | let openUrl;
|
42 | if (options.openPath) {
|
43 | openUrl = Object.assign({}, serverUrl);
|
44 | openUrl.pathname = options.openPath;
|
45 | }
|
46 | else {
|
47 | openUrl = Object.assign({}, componentUrl);
|
48 | }
|
49 | if (!Array.isArray(options.browser)) {
|
50 | openWebPage(url.format(openUrl));
|
51 | }
|
52 | else {
|
53 | options.browser.forEach((browser) => {
|
54 | openWebPage(url.format(openUrl), browser);
|
55 | });
|
56 | }
|
57 | }
|
58 | }
|
59 | exports.openBrowser = openBrowser;
|
60 | //# sourceMappingURL=open_browser.js.map |
\ | No newline at end of file |