import * as path from '../../path' ; import * as fs from '../../fs' ; import * as pods from '../../cocoapods' ; import { Config } from '../../../types' ; import { logError , logInfo } from '../../../helpers' ; export function preLink ( configuration ) { if ( ! ( configuration . firebase && configuration . firebase . ios && configuration . firebase . ios . googleServicesPlistFile ) ) { logError ( 'firebase.ios.googleServicesPlistFile must be specified in project config' ) ; return process . exit ( 1 ) ; } fs . copySync ( configuration . firebase . ios . googleServicesPlistFile , path . resolve ( path . ios . nativeProjectPath ( configuration ) , 'GoogleService-Info.plist' ) ) ; logInfo ( 'copied GoogleService-Info.plist to ./ios/' ) ; let appDelegate = fs . readFileSync ( path . ios . appDelegatePath ( configuration ) , { encoding : 'utf-8' } ) ; const firebaseImport = '#import <Firebase.h>' ; if ( appDelegate . indexOf ( firebaseImport ) === - 1 ) { appDelegate = firebaseImport + '\n' + appDelegate ; appDelegate = appDelegate . replace ( /(didFinishLaunchingWithOptions[\s\S]+?{)/ , '$1\n  [FIRApp configure];' ) ; fs . writeFileSync ( path . ios . appDelegatePath ( configuration ) , appDelegate ) ; logInfo ( 'Updated AppDelegate.m' ) ; } const podfile = fs . readFileSync ( path . ios . podfilePath ( ) , { encoding : 'utf-8' } ) ; const firebasePod = `pod 'Firebase/Core', '6.13.0'` ; if ( podfile . indexOf ( firebasePod ) === - 1 ) { pods . add ( [ firebasePod ] ) ; logInfo ( 'updated Podfile with Firebase pod' ) ; } const googleMeasurementPod = `pod 'GoogleAppMeasurement', '6.1.6'` ; if ( podfile . indexOf ( googleMeasurementPod ) === - 1 ) { pods . add ( [ googleMeasurementPod ] ) ; logInfo ( 'updated Podfile with GoogleAppMeasurement pod' ) ; } logInfo ( 'finished updating iOS for firebase' ) ; }