#!/bin/bash
mode="dev"
docker="false"

#
# Run Script for AURA Player
#
# Call with one of these parameters:
#
# - dev
# - build
#

if [[ $* =~ ^(dev|build)$ ]]; then
	mode=$1
fi

if [[ "$1" == *"docker:"* ]]; then
	docker="true"
	mode=${1#*:}
fi


echo "[ Run mode=$mode ]"
echo "[ Docker=$docker ]"



# +++ DEFAULT COMMANDS +++ #

if [[ $docker == "false" ]]; then

	### Runs the local development server ###

	if [[ $mode == "dev" ]]; then
		(npm run serve)
	fi

	### Builds the bundle ###

	if [[ $mode == "build" ]]; then
		(npm run build)
	fi

fi


# +++ DOCKER COMMANDS +++ #

if [[ $docker == "true" ]]; then
	BASE_DIR=$(readlink -f .)
	AUDIO_DIR=$(readlink -f ./audio)
	echo "Absolute base dir: " $BASE_DIR


	if [[ $mode == "build" ]]; then
		exec sudo docker build -t autoradio/dashboard .
	fi

	### Pushes the latest Docker Image to Docker Hub ###

	if [[ $mode == "push" ]]; then
		exec sudo docker push autoradio/dashboard
	fi
fi