#!/usr/bin/env bash

# This script serves as an easy starting point for common project actions like
# running or building the Finnow projects. Invoke it like so:
# > ./run.sh <command>
# where <command> is one of the below commands.

# "api" command to start the API.
if [ $1 = "api" ]; then
    echo "Running API..."
    dub --root=finnow-api --quiet run

# "app" command to start the app.
elif [ $1 = "app" ]; then
    echo "Running APP..."
    cd flutter_app
    flutter run
    cd ..

# "clean" command to clean all projects.
elif [ $1 = "clean" ]; then
    dub --root=finnow-api --quiet clean
    echo "Cleaned api."
    cd flutter_app
    flutter clean --suppress-analytics
    cd ..
    echo "Cleaned flutter app."

# "build" command to build all projects.
elif [ $1 = "build" ]; then
    dub --root=finnow-api --quiet clean
    dub --root=finnow-api --quiet build --build=release
    echo "Built api."
    cd flutter_app
    flutter build linux
    # flutter build apk
    cd ..
    echo "Built apps."

else
    echo "Unknown command: $1"
    exit 1
fi
