From 6f9983eb42e783c32272e8fa47adf6d8502da441 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 13 Dec 2021 05:46:42 -0800 Subject: [PATCH] Add `--open` / `--no-open` to `yarn flipper-server` Summary: As a convenience, open the browser by default when starting up Reviewed By: timur-valiev Differential Revision: D32984536 fbshipit-source-id: 540abf594f2f2553880f587bcd7d4811ea36fe74 --- desktop/package.json | 1 + desktop/scripts/start-flipper-server.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/desktop/package.json b/desktop/package.json index 316ee0b8e..689cd8db9 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -170,6 +170,7 @@ "metro-minify-terser": "^0.66.2", "metro-resolver": "^0.66.2", "node-fetch": "^2.6.6", + "open": "^8.3.0", "p-filter": "^2.1.0", "p-map": "^4.0.0", "patch-package": "^6.4.7", diff --git a/desktop/scripts/start-flipper-server.ts b/desktop/scripts/start-flipper-server.ts index e245b452b..3a73ceac5 100644 --- a/desktop/scripts/start-flipper-server.ts +++ b/desktop/scripts/start-flipper-server.ts @@ -15,6 +15,7 @@ import Watchman from './watchman'; import {serverDir} from './paths'; import isFB from './isFB'; import yargs from 'yargs'; +import open from 'open'; const argv = yargs .usage('yarn start [args]') @@ -59,6 +60,11 @@ const argv = yargs 'Build the server without watching for changing or starting the service', type: 'boolean', }, + open: { + describe: 'Open Flipper in the default browser after starting', + type: 'boolean', + default: true, + }, }) .version('DEV') .help() @@ -186,6 +192,14 @@ async function startWatchChanges() { await compileServerMain(); } else { await startWatchChanges(); - restartServer(); // builds and starts + // builds and starts + await restartServer(); + + if (argv.open) { + setTimeout(() => { + // TODO: make port configurable together with flipper-server + open('http://localhost:52342/index.web.dev.html'); + }, 2000); + } } })();