import execa from 'execa' ; import chalk from 'chalk' ; import { ToolingLog , LogLevel } from '@kbn/dev-utils' ; import { watchStdioForLine } from './watch_stdio_for_line' ; interface Options { level ? : Exclude < LogLevel , 'silent' | 'error' > ; cwd ? : string ; env ? : Record < string , string > ; exitAfter ? : RegExp ; } export async function exec ( log , cmd , args , { level = 'debug' , cwd , env , exitAfter } = { } ) { log [ level ] ( chalk . dim ( '$' ) , cmd , ... args ) ; const proc = execa ( cmd , args , { stdio : [ 'ignore' , 'pipe' , 'pipe' ] , cwd , env , preferLocal : true , } ) ; await watchStdioForLine ( proc , ( line ) => log [ level ] ( line ) , exitAfter ) ; }