#!/usr/bin/env bash

flavor='production'
scheme='production'
configuration='Release-production'
entryPoint='main.dart'
bundleName="Vereign"

if [[ $1 == 'development' ]]
then
    flavor='development'
    scheme='development'
    configuration='Release-development'
    entryPoint='main-dev.dart'
    bundleName="Vereign-dev"
fi

# Build ios
flutter build ios --flavor ${flavor} -t lib/${entryPoint}

# Export xarchive
xcodebuild \
    -workspace ios/Runner.xcworkspace \
    -scheme ${scheme} \
    -sdk iphoneos \
    -configuration ${configuration} \
    archive -archivePath \
    build/ios/${bundleName}.xcarchive

# Package ipa
xcodebuild \
    -exportArchive \
    -archivePath build/ios/${bundleName}.xcarchive \
    -exportOptionsPlist ios/Runner/Info.plist \
    -exportPath build/ios/${bundleName}

# Move packages wherever we need
# cp build/ios/Vereign/production.ipa /path && cp build/ios/Vereign-dev/development.ipa /path

# Cleanup
# flutter clean
