import fs from 'fs-extra' ; import path from 'path' ; import gradleScript from './EasBuildGradleScript' ; import * as Paths from './Paths' ; const APPLY_EAS_GRADLE = 'apply from: "./eas-build.gradle"' ; function hasApplyLine ( content , applyLine ) { return ( content . replace ( /\r\n/g , '\n' ) . split ( '\n' ) . some ( line => line === applyLine || line === applyLine . replace ( /"/g , "'" ) ) ) ; } export function getEasBuildGradlePath ( projectRoot ) { return path . join ( projectRoot , 'android' , 'app' , 'eas-build.gradle' ) ; } export async function configureEasBuildAsync ( projectRoot ) { const buildGradlePath = Paths . getAppBuildGradleFilePath ( projectRoot ) ; const easGradlePath = getEasBuildGradlePath ( projectRoot ) ; await fs . writeFile ( easGradlePath , gradleScript ) ; const buildGradleContent = await fs . readFile ( path . join ( buildGradlePath ) , 'utf8' ) ; const hasEasGradleApply = hasApplyLine ( buildGradleContent , APPLY_EAS_GRADLE ) ; if ( ! hasEasGradleApply ) { await fs . writeFile ( buildGradlePath , `${ buildGradleContent . trim ( ) }\n${ APPLY_EAS_GRADLE }\n` ) ; } } export async function isEasBuildGradleConfiguredAsync ( projectRoot ) { const buildGradlePath = Paths . getAppBuildGradleFilePath ( projectRoot ) ; const easGradlePath = getEasBuildGradlePath ( projectRoot ) ; const hasEasGradleFile = await fs . pathExists ( easGradlePath ) ; const buildGradleContent = await fs . readFile ( path . join ( buildGradlePath ) , 'utf8' ) ; const hasEasGradleApply = hasApplyLine ( buildGradleContent , APPLY_EAS_GRADLE ) ; return hasEasGradleApply && hasEasGradleFile ; }