import { spawn } from 'child_process' ; import { ROOT_PATH } from './paths' ; import { relative } from 'path' ; import { underline , greenBright , bold } from 'chalk' ; function logShell ( e , args , cwd ) { console . log ( bold ( relative ( ROOT_PATH , cwd ) ) , greenBright `$` , underline ( `${ e } ${ args . join ( ' ' ) }` ) ) ; } function cwdShell ( e , args , cwd ) { logShell ( e , args , cwd ) ; return spawn ( e , args , { cwd : cwd , stdio : 'inherit' , shell : true , } ) ; } export function shell ( command , ... rest ) { const [ e , ... args ] = join ( command , ... rest ) . split ( ' ' ) ; return cwdShell ( e , args , ROOT_PATH ) ; } shell . cwd = ( path ) => { return ( command , ... rest ) => { const [ e , ... args ] = join ( command , ... rest ) . split ( ' ' ) ; return cwdShell ( e , args , path ) ; } ; } ; export function printShell ( command , ... rest ) { const [ e , ... args ] = join ( command , ... rest ) . split ( ' ' ) ; return logShell ( e , args , ROOT_PATH ) ; } printShell . cwd = ( path ) => { return ( command , ... rest ) => { const [ e , ... args ] = join ( command , ... rest ) . split ( ' ' ) ; return logShell ( e , args , path ) ; } ; } ; function join ( command , ... rest ) { let text = '' ; for ( const [ i , t ] of command . entries ( ) ) { text += t ; i in rest && ( text += rest [ i ] ) ; } return text ; }