-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
openBrowser.js
29 lines (26 loc) · 1010 Bytes
/
openBrowser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
/* eslint-disable no-console */
const opn = require('./open');
const chalk = require('chalk');
const isDockerContainer = require('is-docker');
const { legacy, log, style } = require('@serverless/utils/log');
module.exports = function openBrowser(url) {
legacy.write(`\nIf your browser does not open automatically, please open the URL: ${url}\n\n`);
log.notice();
log.notice(
style.aside(`If your browser does not open automatically, please open this URL: ${url}`)
);
log.notice();
let browser = process.env.BROWSER;
if (browser === 'none' || isDockerContainer()) return;
if (process.platform === 'darwin' && browser === 'open') browser = undefined;
const options = { wait: false, app: browser };
opn(url, options).catch((err) => {
if (process.env.SLS_DEBUG) {
legacy.write(
`Serverless: ${chalk.red(`Opening of browser window errored with ${err.stack}`)}\n`
);
}
log.info(`Opening of browser window errored with ${err.stack}`);
});
};