11import { Architecture , ProcessCallback } from "@/types" ;
2- import { ExecOptions , ShellString , exec , which } from "shelljs" ;
32import { ImageResult , RemoveImageCommandFlags } from "@/types/images" ;
43import {
54 LogsCommandFlags ,
65 RemoveCommandFlags ,
76 RunCommandFlags ,
87 StopCommandFlags ,
98} from "@/types/container" ;
9+ import { exec , execSync } from "child_process" ;
1010
11- import { ChildProcess } from "child_process" ;
1211import { GlobalFlags } from "@/types/global" ;
1312import { LoginCommandFlags } from "@/types/registry" ;
1413import { paramCase } from "change-case" ;
@@ -44,7 +43,7 @@ export default abstract class BaseBackend {
4443 command : string ,
4544 callback ?: ProcessCallback
4645 ) : Promise < boolean > {
47- const child = ( await this . exec ( command ) ) as ChildProcess ;
46+ const child = exec ( command ) ;
4847
4948 return await new Promise ( ( resolve ) => {
5049 child ?. stdout ?. on ( "data" , ( data ) => {
@@ -62,22 +61,12 @@ export default abstract class BaseBackend {
6261 } ) ;
6362 }
6463
65- protected async execSync (
66- command : string ,
67- options ?: Omit < ExecOptions , "async" >
68- ) : Promise < ShellString > {
69- return exec ( command , {
70- silent : true ,
71- async : false ,
72- ...options ,
73- } ) as ShellString ;
64+ protected execSync ( command : string ) : string {
65+ return execSync ( command ) . toString ( ) ;
7466 }
7567
76- protected async exec (
77- command : string ,
78- options ?: Omit < ExecOptions , "async" >
79- ) : Promise < ChildProcess > {
80- return exec ( command , { silent : true , async : true , ...options } ) ;
68+ protected which ( command : string ) {
69+ return this . execSync ( `which ${ command } ` ) ;
8170 }
8271
8372 protected mergeFlags ( flags ?: GlobalFlags ) : string {
@@ -111,7 +100,7 @@ export default abstract class BaseBackend {
111100
112101 //#region VMs
113102 async checkVM ( ) : Promise < boolean > {
114- return ! ! which ( this . vm ) ;
103+ return ! ! this . which ( this . vm ) ;
115104 }
116105 async checkInstance ( ) : Promise < boolean > {
117106 return true ;
@@ -125,21 +114,18 @@ export default abstract class BaseBackend {
125114 //#endregion
126115
127116 //#region registry
128- async login (
129- flags ?: LoginCommandFlags ,
130- server ?: string
131- ) : Promise < ShellString > {
117+ login ( flags ?: LoginCommandFlags , server ?: string ) : string {
132118 const command = `${ this . container } login ${ this . mergeFlags (
133119 flags
134120 ) } ${ server } `;
135121
136- return await this . execSync ( command ) ;
122+ return this . execSync ( command ) ;
137123 }
138124
139- async logout ( server ?: string ) : Promise < ShellString > {
125+ logout ( server ?: string ) : string {
140126 const command = `${ this . container } logout ${ server } ` ;
141127
142- return await this . execSync ( command ) ;
128+ return this . execSync ( command ) ;
143129 }
144130 //#endregion
145131
@@ -154,32 +140,26 @@ export default abstract class BaseBackend {
154140 return await this . fork ( command , callback ) ;
155141 }
156142
157- async stop (
158- container : string | string [ ] ,
159- flags ?: StopCommandFlags
160- ) : Promise < ShellString > {
143+ stop ( container : string | string [ ] , flags ?: StopCommandFlags ) : string {
161144 const containers = Array . isArray ( container )
162145 ? container . join ( " " )
163146 : container ;
164147 const command = `${ this . container } stop ${ this . mergeFlags (
165148 flags
166149 ) } ${ containers } `;
167150
168- return await this . execSync ( command ) ;
151+ return this . execSync ( command ) ;
169152 }
170153
171- async remove (
172- container : string | string [ ] ,
173- flags ?: RemoveCommandFlags
174- ) : Promise < ShellString > {
154+ remove ( container : string | string [ ] , flags ?: RemoveCommandFlags ) : string {
175155 const containers = Array . isArray ( container )
176156 ? container . join ( " " )
177157 : container ;
178158 const command = `${ this . container } rm ${ this . mergeFlags (
179159 flags
180160 ) } ${ containers } `;
181161
182- return await this . execSync ( command ) ;
162+ return this . execSync ( command ) ;
183163 }
184164
185165 async logs ( container : string , flags ?: LogsCommandFlags ) : Promise < boolean > {
@@ -199,9 +179,7 @@ export default abstract class BaseBackend {
199179 }
200180
201181 async getImages ( ) : Promise < ImageResult [ ] > {
202- const child = ( await this . exec (
203- `${ this . container } images --format "{{json .}}"`
204- ) ) as ChildProcess ;
182+ const child = exec ( `${ this . container } images --format "{{json .}}"` ) ;
205183
206184 return new Promise ( ( resolve , reject ) => {
207185 if ( ! ! child . exitCode ) reject ( null ) ;
@@ -219,14 +197,14 @@ export default abstract class BaseBackend {
219197 } ) ;
220198 }
221199
222- async removeImage (
200+ removeImage (
223201 image : string | string [ ] ,
224202 flags ?: RemoveImageCommandFlags
225- ) : Promise < ShellString > {
203+ ) : string {
226204 const images = Array . isArray ( image ) ? image . join ( " " ) : image ;
227205 const command = `${ this . container } rmi ${ this . mergeFlags ( flags ) } ${ images } ` ;
228206
229- return await this . execSync ( command ) ;
207+ return this . execSync ( command ) ;
230208 }
231209 //#endregion
232210}
0 commit comments