@@ -4,27 +4,20 @@ import {execute, spawn} from '@junobuild/cli-tools';
44import { statSync } from 'node:fs' ;
55import { readdir , readFile , writeFile } from 'node:fs/promises' ;
66import { join } from 'node:path' ;
7-
8- const DEV = ( process . env . NODE_ENV ?? 'production' ) === 'development' ;
7+ import { type CliContextPageParams , CliContextPage } from './_cli-context.page' ;
98
109const JUNO_CONFIG = join ( process . cwd ( ) , 'juno.config.ts' ) ;
1110
12- const JUNO_TEST_ARGS = [ '--mode' , 'development' , '--headless' ] ;
13-
14- const { command : JUNO_CMD , args : JUNO_CDM_ARGS } = DEV
15- ? { command : 'node' , args : [ 'dist/index.js' ] }
16- : { command : 'juno' , args : [ ] } ;
17-
18- const buildArgs = ( args : string [ ] ) : string [ ] => [ ...JUNO_CDM_ARGS , ...args , ...JUNO_TEST_ARGS ] ;
19-
20- export interface CliPageParams {
11+ export interface CliPageParams extends CliContextPageParams {
2112 satelliteId : PrincipalText ;
2213}
2314
24- export class CliPage {
15+ export class CliPage extends CliContextPage {
2516 #satelliteId: PrincipalText ;
2617
27- private constructor ( { satelliteId} : CliPageParams ) {
18+ private constructor ( { satelliteId, command} : CliPageParams ) {
19+ super ( { command} ) ;
20+
2821 this . #satelliteId = satelliteId ;
2922 }
3023
@@ -64,36 +57,36 @@ export class CliPage {
6457
6558 protected async loginWithEmulator ( ) : Promise < void > {
6659 await execute ( {
67- command : JUNO_CMD ,
68- args : buildArgs ( [ 'login' , '--emulator' ] )
60+ command : this . command ,
61+ args : this . buildArgs ( [ 'login' , '--emulator' ] )
6962 } ) ;
7063 }
7164
7265 async applyConfig ( ) : Promise < void > {
7366 await execute ( {
74- command : JUNO_CMD ,
75- args : buildArgs ( [ 'config' , 'apply' , '--force' ] )
67+ command : this . command ,
68+ args : this . buildArgs ( [ 'config' , 'apply' , '--force' ] )
7669 } ) ;
7770 }
7871
7972 private async logout ( ) : Promise < void > {
8073 await execute ( {
81- command : JUNO_CMD ,
82- args : buildArgs ( [ 'logout' ] )
74+ command : this . command ,
75+ args : this . buildArgs ( [ 'logout' ] )
8376 } ) ;
8477 }
8578
8679 async clearHosting ( ) : Promise < void > {
8780 await execute ( {
88- command : JUNO_CMD ,
89- args : buildArgs ( [ 'hosting' , 'clear' ] )
81+ command : this . command ,
82+ args : this . buildArgs ( [ 'hosting' , 'clear' ] )
9083 } ) ;
9184 }
9285
9386 async deployHosting ( { clear} : { clear : boolean } ) : Promise < void > {
9487 await execute ( {
95- command : JUNO_CMD ,
96- args : buildArgs ( [ 'hosting' , 'deploy' , ...( clear ? [ '--clear' ] : [ ] ) ] )
88+ command : this . command ,
89+ args : this . buildArgs ( [ 'hosting' , 'deploy' , ...( clear ? [ '--clear' ] : [ ] ) ] )
9790 } ) ;
9891 }
9992
@@ -103,8 +96,8 @@ export class CliPage {
10396 target : 'satellite' | 'orbiter' | 'mission-control' ;
10497 } ) : Promise < void > {
10598 await execute ( {
106- command : JUNO_CMD ,
107- args : buildArgs ( [ 'snapshot' , 'create' , '--target' , target ] )
99+ command : this . command ,
100+ args : this . buildArgs ( [ 'snapshot' , 'create' , '--target' , target ] )
108101 } ) ;
109102 }
110103
@@ -114,8 +107,8 @@ export class CliPage {
114107 target : 'satellite' | 'orbiter' | 'mission-control' ;
115108 } ) : Promise < void > {
116109 await execute ( {
117- command : JUNO_CMD ,
118- args : buildArgs ( [ 'snapshot' , 'restore' , '--target' , target ] )
110+ command : this . command ,
111+ args : this . buildArgs ( [ 'snapshot' , 'restore' , '--target' , target ] )
119112 } ) ;
120113 }
121114
@@ -125,8 +118,8 @@ export class CliPage {
125118 target : 'satellite' | 'orbiter' | 'mission-control' ;
126119 } ) : Promise < void > {
127120 await execute ( {
128- command : JUNO_CMD ,
129- args : buildArgs ( [ 'snapshot' , 'delete' , '--target' , target ] )
121+ command : this . command ,
122+ args : this . buildArgs ( [ 'snapshot' , 'delete' , '--target' , target ] )
130123 } ) ;
131124 }
132125
@@ -136,8 +129,8 @@ export class CliPage {
136129 target : 'satellite' | 'orbiter' | 'mission-control' ;
137130 } ) : Promise < { snapshotFolder : string } > {
138131 await execute ( {
139- command : JUNO_CMD ,
140- args : buildArgs ( [ 'snapshot' , 'download' , '--target' , target ] )
132+ command : this . command ,
133+ args : this . buildArgs ( [ 'snapshot' , 'download' , '--target' , target ] )
141134 } ) ;
142135
143136 return await this . getSnapshotFsFolder ( ) ;
@@ -171,8 +164,8 @@ export class CliPage {
171164 folder : string ;
172165 } ) : Promise < void > {
173166 await execute ( {
174- command : JUNO_CMD ,
175- args : buildArgs ( [ 'snapshot' , 'upload' , '--target' , target , '--dir' , folder ] )
167+ command : this . command ,
168+ args : this . buildArgs ( [ 'snapshot' , 'upload' , '--target' , target , '--dir' , folder ] )
176169 } ) ;
177170 }
178171
@@ -184,8 +177,8 @@ export class CliPage {
184177 let output = '' ;
185178
186179 await spawn ( {
187- command : JUNO_CMD ,
188- args : buildArgs ( [ 'snapshot' , 'list' , '--target' , target ] ) ,
180+ command : this . command ,
181+ args : this . buildArgs ( [ 'snapshot' , 'list' , '--target' , target ] ) ,
189182 stdout : ( o ) => ( output += o ) ,
190183 silentErrors : true
191184 } ) ;
@@ -198,8 +191,8 @@ export class CliPage {
198191 let output = '' ;
199192
200193 await spawn ( {
201- command : JUNO_CMD ,
202- args : buildArgs ( [ 'whoami' ] ) ,
194+ command : this . command ,
195+ args : this . buildArgs ( [ 'whoami' ] ) ,
203196 stdout : ( o ) => ( output += o ) ,
204197 silentErrors : true
205198 } ) ;
0 commit comments