import * as cp from "child_process" ; import * as vscode from "vscode" ; import { mavenOutputChannel } from "../mavenOutputChannel" ; export async function executeCommand ( command , args , options = { shell : true } ) { return new Promise ( ( resolve , reject ) : void => { mavenOutputChannel . appendLine ( `${ command }, [${ args . join ( "," ) }]` ) ; let result = "" ; const childProc = cp . spawn ( command , args , options ) ; if ( childProc . stdout !== null ) { childProc . stdout . on ( "data" , ( data ) => { data = data . toString ( ) ; result = result . concat ( data ) ; } ) ; } childProc . on ( "error" , reject ) ; childProc . on ( "close" , ( code ) => { if ( code !== 0 || result . indexOf ( "ERROR" ) > - 1 ) { reject ( new Error ( `Command "${ command } ${ args . toString ( ) }" failed with exit code "${ code }".` ) ) ; } else { resolve ( result ) ; } } ) ; } ) ; } export async function executeCommandWithProgress ( message , command , args , options = { shell : true } ) { let result = "" ; await vscode . window . withProgress ( { location : vscode . ProgressLocation . Window } , async ( p ) => { mavenOutputChannel . appendLine ( `${ command }, [${ args . join ( "," ) }]` ) ; return new Promise < void > ( async ( resolve , reject ) : Promise < void > => { p . report ( { message } ) ; try { result = await executeCommand ( command , args , options ) ; resolve ( ) ; } catch ( e ) { reject ( e ) ; } } ) ; } ) ; return result ; }