format import { getHealthchecks , getEnvInfo } from 'flipper-doctor' ; import { FlipperDoctor } from 'flipper-common' ; import produce from 'immer' ; export async function getHealthChecks ( options ) { return produce ( getHealthchecks ( ) , ( healthchecks ) => { if ( ! options . settings . enableAndroid ) { healthchecks . android = { label : healthchecks . android . label , isSkipped : true , skipReason : 'Healthcheck is skipped, because "Android Development" option is disabled in the Flipper settings' , } ; } if ( ! options . settings . enableIOS ) { healthchecks . ios = { label : healthchecks . ios . label , isSkipped : true , skipReason : 'Healthcheck is skipped, because "iOS Development" option is disabled in the Flipper settings' , } ; } Object . keys ( healthchecks ) . forEach ( ( cat ) => { const category = healthchecks [ cat as keyof typeof healthchecks ] ; if ( 'healthchecks' in category ) { category . healthchecks . forEach ( ( h ) => { delete h . run ; } ) ; } } ) ; } ) ; } let envInfoPromise ; export async function runHealthcheck ( options , categoryName , ruleName ) { const healthchecks = getHealthchecks ( ) ; const category = healthchecks [ categoryName ] ; if ( ! category ) { throw new Error ( 'Unknown category: ' + categoryName ) ; } if ( ! ( 'healthchecks' in category ) ) { throw new Error ( 'Skipped category: ' + categoryName ) ; } const check = category . healthchecks . find ( ( h ) => h . key === ruleName ) ; if ( ! check ) { throw new Error ( 'Unknown healthcheck: ' + ruleName ) ; } if ( ! envInfoPromise ) { envInfoPromise = getEnvInfo ( ) ; } const environmentInfo = await envInfoPromise ; const checkResult = await check . run ! ( environmentInfo , options . settings ) ; return checkResult . hasProblem && check . isRequired ? { status : 'FAILED' , message : checkResult . message , } : checkResult . hasProblem && ! check . isRequired ? { status : 'WARNING' , message : checkResult . message , } : { status : 'SUCCESS' , message : checkResult . message } ; }