opt_out_usage

# Get project root
def root_path
  Dir.pwd.sub(/.*\Kfastlane/, '').sub(/.*\Kandroid/, '').sub(/.*\Kios/, '').sub(/.*\K\/\//, '')
end

# Run on root
lane :sh_on_root do |options|
  command = options[:command]

  sh("cd #{root_path} && #{command}")
end

# Reusable tasks
lane :fetch_dependencies do
  sh_on_root(command: "flutter clean")
  sh_on_root(command: "flutter pub get")
end

lane :build_autogenerated_code do
  sh_on_root(command: "flutter gen-l10n")
  sh_on_root(command: "flutter pub global activate script_runner")
  sh_on_root(command: "scr setup")
end

def get_build_type (type)
  case type
  when 'production'
    return {
      'ios_flavor' => 'production',
      'android_flavor' => 'production',
      'ios_type' => 'appstore',
      'ios_export_method' => 'app-store',
      'android_type' => 'production'
    }
  when 'staging'
    return {
      'ios_flavor' => 'production',
      'android_flavor' => 'production',
      'ios_type' => 'adhoc',
      'ios_export_method' => 'ad-hoc',
      'android_type' => 'beta'
    }
  when 'branch'
    return {
      'ios_flavor' => 'development',
      'android_flavor' => 'development',
      'ios_type' => 'adhoc',
      'ios_export_method' => 'ad-hoc',
      'android_type' => ''
    }
  else
    return {}
  end
end
