import chalk from 'chalk' ; import readline from 'readline' ; import wcwidth from 'wcwidth' ; import stripAnsi from 'strip-ansi' ; import { Ora } from 'ora' ; import { logger } from '@react-native-community/cli-tools' ; const logMessage = ( message ? ) => { const indentation = '   ' ; if ( typeof message !== 'string' ) { logger . log ( ) ; return ; } const messageByLine = message . split ( '\n' ) ; return logger . log ( `${ indentation }${ messageByLine . join ( `\n${ indentation }` ) }` ) ; } ; const addBlankLine = ( ) => logMessage ( ) ; const logManualInstallation = ( { healthcheck , url , command , message , } ) => { if ( message ) { return logMessage ( message ) ; } if ( url ) { logMessage ( `Read more about how to download ${ healthcheck } at ${ chalk . dim . underline ( url ) }` ) ; return ; } if ( command ) { logMessage ( `Please install ${ healthcheck } by running ${ chalk . bold ( command ) }` ) ; } } ; const logError = ( { healthcheck , loader , error , message , command , } ) => { if ( loader ) { loader . fail ( ) ; } addBlankLine ( ) ; logMessage ( chalk . dim ( error . message ) ) ; if ( message ) { logMessage ( message ) ; addBlankLine ( ) ; return ; } logMessage ( `The error above occured while trying to install ${ healthcheck }. Please try again manually: ${ chalk . bold ( command ) }` ) ; addBlankLine ( ) ; } ; function calculateMessageSize ( message ) { return Math . max ( 1 , Math . ceil ( wcwidth ( stripAnsi ( message ) ) / ( process . stdout . columns || 80 ) ) ) ; } function removeMessage ( message ) { readline . moveCursor ( process . stdout , 0 , - calculateMessageSize ( message ) ) ; readline . clearScreenDown ( process . stdout ) ; } export { logMessage , logManualInstallation , logError , removeMessage } ;