require_relative '../../scripts/react_native_pods'

source 'https://cdn.cocoapods.org/'
platform :ios, '10.0'

if ENV['USE_FRAMEWORKS'] == '1'
  puts "Installing pods with use_frameworks!"
  use_frameworks!
end

if ENV['USE_HERMES'] == '1'
  puts "Using Hermes engine"
end

def pods()
  project 'RNTesterPods.xcodeproj'

  fabric_enabled = false

  # To use fabric: set the environment variable `USE_FABRIC` to 1, like below
  #   $ USE_FABRIC=1 bundle exec pod install
  # or
  #   $ export USE_FABRIC=1
  #   $ bundle exec pod install
  if ENV['USE_FABRIC'] == '1'
    puts "Building RNTester with Fabric enabled."
    fabric_enabled = true
  end

  prefix_path = "../.."
  use_react_native!(path: prefix_path, fabric_enabled: fabric_enabled, hermes_enabled: ENV['USE_HERMES'] == '1')
  pod 'ReactCommon/turbomodule/samples', :path => "#{prefix_path}/ReactCommon"

  # Additional Pods which aren't included in the default Podfile
  pod 'React-RCTPushNotification', :path => "#{prefix_path}/Libraries/PushNotificationIOS"
  pod 'Yoga', :path => "#{prefix_path}/ReactCommon/yoga", :modular_headers => true
  # Additional Pods which are classed as unstable
end

target 'RNTester' do
  pods()
  use_flipper!
end

target 'RNTesterUnitTests' do
  pods()
  pod 'React-RCTTest', :path => "./RCTTest"
end

target 'RNTesterIntegrationTests' do
  pods()
  pod 'React-RCTTest', :path => "./RCTTest"
end

def frameworks_pre_install(installer)
  static_frameworks = ['FlipperKit', 'Flipper', 'Flipper-Folly',
      'CocoaAsyncSocket', 'ComponentKit', 'Flipper-DoubleConversion',
      'Flipper-Glog', 'Flipper-PeerTalk', 'Flipper-RSocket',
      'CocoaLibEvent', 'OpenSSL-Universal', 'boost-for-react-native']

  Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
  installer.pod_targets.each do |pod|
    if static_frameworks.include?(pod.name)
      def pod.build_type
        Pod::BuildType.static_library
      end
    end
  end
end

post_install do |installer|
  flipper_post_install(installer)
end
