woocommerce/plugins/woocommerce-blocks/tests/e2e/utils/cli.ts

36 lines
626 B
TypeScript

/**
* External dependencies
*/
import { exec, ExecException } from 'child_process';
interface ExecResult {
stdout: string;
stderr: string;
}
interface ExecError extends ExecResult {
error: ExecException | null;
}
export function cli( command: string ): Promise< ExecResult > {
return new Promise( ( resolve, reject ) => {
exec(
command,
( error: ExecException | null, stdout: string, stderr: string ) => {
if ( error ) {
reject( {
error,
stdout,
stderr,
} as ExecError );
} else {
resolve( {
stdout,
stderr,
} as ExecResult );
}
}
);
} );
}