1+ import detectPort from "detect-port" ;
12import process from "process" ;
23import open from "open" ;
34
@@ -12,13 +13,18 @@ export type Inject = {
1213 getIndexHtml : ( ) => string ;
1314} ;
1415
15- function actualRun ( appInfo : AppInfo , options : Options , inject : Inject ) : void {
16+ async function actualRun (
17+ appInfo : AppInfo ,
18+ options : Options ,
19+ inject : Inject ,
20+ ) : Promise < void > {
1621 const { injectFrontend, injectSim, getIndexHtml } = inject ;
22+ options . basePort = await detectPort ( options . basePort ) ;
1723 const instances = new Instances ( appInfo , injectSim , options ) ;
1824
1925 const numberOfInstances = 2 ;
2026 for ( let i = 0 ; i < numberOfInstances ; i ++ ) {
21- instances . add ( ) ;
27+ await instances . add ( ) ;
2228 }
2329
2430 const frontend = createFrontend (
@@ -37,7 +43,11 @@ function actualRun(appInfo: AppInfo, options: Options, inject: Inject): void {
3743 open ( "http://localhost:" + options . basePort ) ;
3844}
3945
40- export function run ( locationStr : string , options : Options , inject : Inject ) {
46+ export async function run (
47+ locationStr : string ,
48+ options : Options ,
49+ inject : Inject ,
50+ ) : Promise < void > {
4151 let location : Location ;
4252 try {
4353 location = getLocation ( locationStr ) ;
@@ -57,15 +67,14 @@ export function run(locationStr: string, options: Options, inject: Inject) {
5767
5868 console . log ( "Starting webxdc project in:" , locationStr ) ;
5969
60- getAppInfo ( location )
61- . then ( ( appInfo ) => {
62- actualRun ( appInfo , options , inject ) ;
63- } )
64- . catch ( ( e ) => {
65- if ( e instanceof AppInfoError ) {
66- console . error ( e . message ) ;
67- return ;
68- }
69- throw e ;
70- } ) ;
70+ try {
71+ const appInfo = await getAppInfo ( location ) ;
72+ await actualRun ( appInfo , options , inject ) ;
73+ } catch ( e ) {
74+ if ( e instanceof AppInfoError ) {
75+ console . error ( e . message ) ;
76+ return ;
77+ }
78+ throw e ;
79+ }
7180}
0 commit comments