File tree 1 file changed +30
-3
lines changed
1 file changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -21,9 +21,36 @@ function logError(error) {
21
21
22
22
async function runProcess ( command , args = [ ] , directory = projectRoot ( ) ) {
23
23
try {
24
- throw new Exception ( "Not implemented yet" ) ; // TODO
25
- // const result = await $`cd ${directory} && ${command} ${args}`;
26
- return result . stdout . trim ( ) ;
24
+ return new Promise ( ( resolve , reject ) => {
25
+ const process = spawn ( command , args , {
26
+ cwd : directory ,
27
+ shell : true ,
28
+ stdio : [ 'inherit' , 'pipe' , 'pipe' ]
29
+ } ) ;
30
+
31
+ let stdout = '' ;
32
+ let stderr = '' ;
33
+
34
+ process . stdout . on ( 'data' , ( data ) => {
35
+ stdout += data . toString ( ) ;
36
+ } ) ;
37
+
38
+ process . stderr . on ( 'data' , ( data ) => {
39
+ stderr += data . toString ( ) ;
40
+ } ) ;
41
+
42
+ process . on ( 'close' , ( code ) => {
43
+ if ( code === 0 ) {
44
+ resolve ( stdout . trim ( ) ) ;
45
+ } else {
46
+ reject ( new Error ( `Command failed with code ${ code } : ${ stderr } ` ) ) ;
47
+ }
48
+ } ) ;
49
+
50
+ process . on ( 'error' , ( error ) => {
51
+ reject ( new Error ( `Failed to start command: ${ error . message } ` ) ) ;
52
+ } ) ;
53
+ } ) ;
27
54
} catch ( error ) {
28
55
throw new Error ( `Command failed: ${ error . message } ` ) ;
29
56
}
You can’t perform that action at this time.
0 commit comments