import { ExpoConfig } from '@expo/config-types' ; import fs from 'fs-extra' ; import path from 'path' ; import { XcodeProject } from 'xcode' ; import { ConfigPlugin } from '../Plugin.types' ; import { createInfoPlistPlugin , withXcodeProject } from '../plugins/ios-plugins' ; import { InfoPlist } from './IosConfig.types' ; import { getSourceRoot } from './Paths' ; import { appendScheme } from './Scheme' ; import { addResourceFileToGroup , getProjectName } from './utils/Xcodeproj' ; export const withGoogle = createInfoPlistPlugin ( setGoogleConfig , 'withGoogle' ) ; export const withGoogleServicesFile = config => { return withXcodeProject ( config , config => { config . modResults = setGoogleServicesFile ( config , { projectRoot : config . modRequest . projectRoot , project : config . modResults } ) ; return config ; } ) ; } ; export function getGoogleSignInReservedClientId ( config ) { return config . ios ?. config ?. googleSignIn ?. reservedClientId ?? null ; } export function getGoogleServicesFile ( config ) { return config . ios ?. googleServicesFile ?? null ; } export function setGoogleSignInReservedClientId ( config , infoPlist ) { const reservedClientId = getGoogleSignInReservedClientId ( config ) ; if ( reservedClientId === null ) { return infoPlist ; } return appendScheme ( reservedClientId , infoPlist ) ; } export function setGoogleConfig ( config , infoPlist ) { infoPlist = setGoogleSignInReservedClientId ( config , infoPlist ) ; return infoPlist ; } export function setGoogleServicesFile ( config , { projectRoot , project } ) { const googleServicesFileRelativePath = getGoogleServicesFile ( config ) ; if ( googleServicesFileRelativePath === null ) { return project ; } const googleServiceFilePath = path . resolve ( projectRoot , googleServicesFileRelativePath ) ; fs . copyFileSync ( googleServiceFilePath , path . join ( getSourceRoot ( projectRoot ) , 'GoogleService-Info.plist' ) ) ; const projectName = getProjectName ( projectRoot ) ; const plistFilePath = `${ projectName }/GoogleService-Info.plist` ; if ( ! project . hasFile ( plistFilePath ) ) { project = addResourceFileToGroup ( { filepath : plistFilePath , groupName : projectName , project , isBuildFile : true , verbose : true } ) ; } return project ; }