# Run with tooling from https://github.com/flutter/codelabs/tree/main/tooling/codelab_rebuild
name: Flutter Maps Firestore rebuild script
steps:
  - name: Remove the runner
    rmdirs: 
      - ios
  - name: Recreate runner
    flutter: create --platforms ios .
  - name: Create GoogleService-Info.plist
    path: ios/GoogleService-Info.plist
    replace-contents: |
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
      <plist version="1.0">
      <dict>
      	<!--
      	TODO: Replace this file with credentials from Cloud Firestore.
      	See https://pub.dev/packages/cloud_firestore#setup for more detail.
      	-->
      </dict>
      </plist>
  - name: Patch Podfile
    path: ios/Podfile
    patch-u: |
      --- b/flutter_maps_firestore/ios/Podfile
      +++ a/flutter_maps_firestore/ios/Podfile
      @@ -1,5 +1,5 @@
       # Uncomment this line to define a global platform for your project
      -# platform :ios, '11.0'
      +platform :ios, '14.0'
       
       # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
       ENV['COCOAPODS_DISABLE_STATS'] = 'true'
      @@ -37,5 +37,8 @@ end
       post_install do |installer|
         installer.pods_project.targets.each do |target|
           flutter_additional_ios_build_settings(target)
      +    target.build_configurations.each do |config|
      +      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
      +     end
         end
       end
  - name: Patch ios/Flutter/AppFrameworkInfo.plist
    path: ios/Flutter/AppFrameworkInfo.plist
    patch-u: |
      --- b/flutter_maps_firestore/ios/Flutter/AppFrameworkInfo.plist
      +++ a/flutter_maps_firestore/ios/Flutter/AppFrameworkInfo.plist
      @@ -21,6 +21,6 @@
         <key>CFBundleVersion</key>
         <string>1.0</string>
         <key>MinimumOSVersion</key>
      -  <string>11.0</string>
      +  <string>14.0</string>
       </dict>
       </plist>
  - name: Patch ios/Runner/AppDelegate.swift
    path: ios/Runner/AppDelegate.swift
    patch-u: |
      --- b/flutter_maps_firestore/ios/Runner/AppDelegate.swift
      +++ a/flutter_maps_firestore/ios/Runner/AppDelegate.swift
      @@ -1,5 +1,6 @@
       import UIKit
       import Flutter
      +import GoogleMaps
       
       @UIApplicationMain
       @objc class AppDelegate: FlutterAppDelegate {
      @@ -7,7 +8,11 @@ import Flutter
           _ application: UIApplication,
           didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
         ) -> Bool {
      +    // TODO: Replace this with an API key that has Google Maps for iOS enabled
      +    // See https://developers.google.com/maps/documentation/ios-sdk/get-api-key
      +    GMSServices.provideAPIKey("ADD_A_KEY_HERE")
           GeneratedPluginRegistrant.register(with: self)
      +      
           return super.application(application, didFinishLaunchingWithOptions: launchOptions)
         }
       }
  - name: Patch ios/Runner/Info.plist
    path: ios/Runner/Info.plist
    patch-u: |
      --- b/flutter_maps_firestore/ios/Runner/Info.plist
      +++ a/flutter_maps_firestore/ios/Runner/Info.plist
      @@ -2,10 +2,12 @@
       <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
       <plist version="1.0">
       <dict>
      +	<key>NSLocationWhenInUseUsageDescription</key>
      +	<string>Finding Ice Cream stores near you</string>
       	<key>CFBundleDevelopmentRegion</key>
       	<string>$(DEVELOPMENT_LANGUAGE)</string>
       	<key>CFBundleDisplayName</key>
      -	<string>Flutter Maps Firestore</string>
      +	<string>Find Ice Cream</string>
       	<key>CFBundleExecutable</key>
       	<string>$(EXECUTABLE_NAME)</string>
       	<key>CFBundleIdentifier</key>
  - name: flutter pub upgrade
    flutter: pub upgrade --major-versions
  - name: flutter build ios
    flutter: build ios --simulator
