Last change
on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | const open = require('opn');
|
---|
| 4 | const isAbsoluteUrl = require('is-absolute-url');
|
---|
| 5 |
|
---|
| 6 | function runOpen(uri, options, log) {
|
---|
| 7 | // https://github.com/webpack/webpack-dev-server/issues/1990
|
---|
| 8 | let openOptions = { wait: false };
|
---|
| 9 | let openOptionValue = '';
|
---|
| 10 |
|
---|
| 11 | if (typeof options.open === 'string') {
|
---|
| 12 | openOptions = Object.assign({}, openOptions, { app: options.open });
|
---|
| 13 | openOptionValue = `: "${options.open}"`;
|
---|
| 14 | } else if (typeof options.open === 'object') {
|
---|
| 15 | openOptions = options.open;
|
---|
| 16 | openOptionValue = `: "${JSON.stringify(options.open)}"`;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | const pages =
|
---|
| 20 | typeof options.openPage === 'string'
|
---|
| 21 | ? [options.openPage]
|
---|
| 22 | : options.openPage || [''];
|
---|
| 23 |
|
---|
| 24 | return Promise.all(
|
---|
| 25 | pages.map((page) => {
|
---|
| 26 | const pageUrl = page && isAbsoluteUrl(page) ? page : `${uri}${page}`;
|
---|
| 27 |
|
---|
| 28 | return open(pageUrl, openOptions).catch(() => {
|
---|
| 29 | log.warn(
|
---|
| 30 | `Unable to open "${pageUrl}" in browser${openOptionValue}. If you are running in a headless environment, please do not use the --open flag`
|
---|
| 31 | );
|
---|
| 32 | });
|
---|
| 33 | })
|
---|
| 34 | );
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | module.exports = runOpen;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.