@@ -16,6 +16,7 @@ export class Control {
1616    db ; 
1717    npm ; 
1818    rust ; 
19+     shared ; 
1920    signals  =  { } ; 
2021    status  =  { 
2122        client : false , 
@@ -30,6 +31,7 @@ export class Control {
3031        npm : false , 
3132        postgres : false , 
3233        redis : false , 
34+         shared : false , 
3335    } ; 
3436    constructor ( cli )  { 
3537        this . cli  =  cli ; 
@@ -48,6 +50,7 @@ export class Control {
4850            this . kill ( "files" ) , 
4951            this . kill ( "connection" ) , 
5052            this . kill ( "python" ) , 
53+             this . kill ( "shared" ) , 
5154        ] ) ; 
5255        process . exit ( 0 ) ; 
5356    } 
@@ -153,7 +156,7 @@ export class Control {
153156        this . status . types  =  false ; 
154157        await  this . kill ( "types" ) ; 
155158        if  ( ! this . cli . options . skipTypes  ||  restart )  { 
156-             this . types  =  spawn ( "npm run compile --workspace=quadratic-shared && npm run  build:wasm:types" ,  {  shell : true  } ) ; 
159+             this . types  =  spawn ( "npm run build:wasm:types" ,  {  shell : true  } ) ; 
157160            this . ui . printOutput ( "types" ,  ( data )  =>  { 
158161                this . handleResponse ( "types" ,  data ,  { 
159162                    success : "Running " , 
@@ -287,11 +290,7 @@ export class Control {
287290        this . signals . multiplayer  =  new  AbortController ( ) ; 
288291        this . ui . print ( "multiplayer" ) ; 
289292        this . multiplayer  =  spawn ( "cargo" ,  this . cli . options . multiplayer 
290-             ? [ 
291-                 "watch" , 
292-                 "-x" , 
293-                 "run -p quadratic-multiplayer --target-dir=target" , 
294-             ] 
293+             ? [ "watch" ,  "-x" ,  "run -p quadratic-multiplayer --target-dir=target" ] 
295294            : [ "run" ,  "-p" ,  "quadratic-multiplayer" ,  "--target-dir=target" ] ,  { 
296295            signal : this . signals . multiplayer . signal , 
297296            cwd : "quadratic-multiplayer" , 
@@ -325,11 +324,7 @@ export class Control {
325324        catch  ( e )  {  } 
326325        this . signals . files  =  new  AbortController ( ) ; 
327326        this . files  =  spawn ( "cargo" ,  this . cli . options . files 
328-             ? [ 
329-                 "watch" , 
330-                 "-x" , 
331-                 "run -p quadratic-files --target-dir=target" , 
332-             ] 
327+             ? [ "watch" ,  "-x" ,  "run -p quadratic-files --target-dir=target" ] 
333328            : [ "run" ,  "-p" ,  "quadratic-files" ,  "--target-dir=target" ] ,  { 
334329            signal : this . signals . files . signal , 
335330            cwd : "quadratic-files" , 
@@ -363,6 +358,55 @@ export class Control {
363358            this . status . files  =  "killed" ; 
364359        } 
365360    } 
361+     async  runShared ( restart )  { 
362+         if  ( this . quitting ) 
363+             return ; 
364+         if  ( this . status . shared  ===  "killed" ) 
365+             return ; 
366+         this . status . shared  =  false ; 
367+         this . ui . print ( "shared" ) ; 
368+         await  this . kill ( "shared" ) ; 
369+         let  firstRun  =  true ; 
370+         this . signals . shared  =  new  AbortController ( ) ; 
371+         this . shared  =  spawn ( `npm run ${ this . cli . options . shared  ? "watch"  : "compile" }  ,  { 
372+             signal : this . signals . shared . signal , 
373+             shell : true , 
374+         } ) ; 
375+         this . ui . printOutput ( "shared" ,  ( data )  =>  { 
376+             this . handleResponse ( "shared" ,  data ,  { 
377+                 success : [ " 0 errors." ,  "successfully" ] , 
378+                 error : [ "error" ] , 
379+                 start : "Starting" , 
380+             } ,  ( )  =>  { 
381+                 if  ( firstRun  &&  ! restart )  { 
382+                     firstRun  =  false ; 
383+                     if  ( this . status . db  !==  "killed"  &&  ! this . db )  { 
384+                         this . runDb ( ) ; 
385+                     } 
386+                 } 
387+             } ) ; 
388+         } ) ; 
389+     } 
390+     async  restartShared ( )  { 
391+         this . cli . options . shared  =  ! this . cli . options . shared ; 
392+         if  ( this . shared )  { 
393+             this . runShared ( true ) ; 
394+         } 
395+     } 
396+     async  killShared ( )  { 
397+         if  ( this . status . shared  ===  "killed" )  { 
398+             this . status . shared  =  false ; 
399+             this . ui . print ( "shared" ,  "restarting..." ) ; 
400+             this . runShared ( ) ; 
401+         } 
402+         else  { 
403+             if  ( this . shared )  { 
404+                 await  this . kill ( "shared" ) ; 
405+                 this . ui . print ( "shared" ,  "killed" ,  "red" ) ; 
406+             } 
407+             this . status . shared  =  "killed" ; 
408+         } 
409+     } 
366410    async  runConnection ( )  { 
367411        if  ( this . quitting ) 
368412            return ; 
@@ -379,11 +423,7 @@ export class Control {
379423        catch  ( e )  {  } 
380424        this . signals . connection  =  new  AbortController ( ) ; 
381425        this . connection  =  spawn ( "cargo" ,  this . cli . options . connection 
382-             ? [ 
383-                 "watch" , 
384-                 "-x" , 
385-                 "run -p quadratic-connection --target-dir=target" , 
386-             ] 
426+             ? [ "watch" ,  "-x" ,  "run -p quadratic-connection --target-dir=target" ] 
387427            : [ "run" ,  "-p" ,  "quadratic-connection" ,  "--target-dir=target" ] ,  { 
388428            signal : this . signals . connection . signal , 
389429            cwd : "quadratic-connection" , 
@@ -543,7 +583,7 @@ export class Control {
543583        this . ui  =  ui ; 
544584        this . checkServices ( ) ; 
545585        this . runRust ( ) ; 
546-         this . runDb ( ) ; 
547586        this . runPython ( ) ; 
587+         this . runShared ( ) ; 
548588    } 
549589} 
0 commit comments