From 8ec5b7819ba4c30266197c3dbb6ea560856f1367 Mon Sep 17 00:00:00 2001 From: Henrik Comes <33446962+henrikcomes@users.noreply.github.com> Date: Mon, 13 Mar 2023 10:34:17 +0100 Subject: [PATCH] Adds argument to disable opening all apps on startup When --open=false is passed the Angular CLI won't open a new browser tab for each app that was started. If the argument is not passed the Angular CLI will open a new browser tab for each app that was started, to not break the current flow for users The implementation of yargs could be considered to allow a simpler/cleaner way of implementing more arguments in the future --- libs/mf/src/server/mf-dev-server.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libs/mf/src/server/mf-dev-server.ts b/libs/mf/src/server/mf-dev-server.ts index 5eace7e9..8df961ed 100644 --- a/libs/mf/src/server/mf-dev-server.ts +++ b/libs/mf/src/server/mf-dev-server.ts @@ -16,9 +16,9 @@ function startCmd(name: string, cmd: string): void { } // tslint:disable-next-line: no-shadowed-variable -function startApps(apps: ProjectInfo[]): void { +function startApps(apps: ProjectInfo[], open: boolean): void { for (const app of apps) { - const cmd = `ng serve ${app.name} -o`; + const cmd = `ng serve ${app.name} --open ${open}`; print('DEVSVR', padding, app.name + ' ' + (app.port || '4200')); startCmd(app.name, cmd); } @@ -30,6 +30,15 @@ if (!isWorkspace()) { } const [, , ...filter] = argv; + +let open = true; +const dontOpenIndex = filter.indexOf("--open=false") + +if(dontOpenIndex >= 0) { + open = false; + filter.splice(dontOpenIndex, 1); +} + const startAll = filter.length === 0; const projects = readProjectInfos(); @@ -41,4 +50,4 @@ const apps = projects.filter( ); padding = apps.reduce((acc, p) => Math.max(acc, p.name.length), 0); padding = Math.max(6, padding); -startApps(apps); +startApps(apps, open);