#!/bin/bash

DESTDIR='/home/runassudo/Documents/Work/School Cloud Data/unenc/public/www/opentally'

# Prevent deploy with unstaged changes

git update-index --refresh > /dev/null
if git diff-index --quiet HEAD -- ; then true; else
	echo Cannot deploy with unstaged changes
	exit 1
fi

# Rebuild WASM

./scripts/build_wasm.sh

# Build homepage

./scripts/build_homepage.sh

# Copy files

#mkdir "$DESTDIR/stv/"
cp -r html/* "$DESTDIR/stv/"

# Replace GITVERSION, etc.

GITVERSION=$(git rev-parse --short HEAD)
sed -i "s#GITVERSION#$GITVERSION#g" "$DESTDIR/stv/index.html"
sed -i "s#GITVERSION#$GITVERSION#g" "$DESTDIR/stv/index.js"
sed -i "s#GITVERSION#$GITVERSION#g" "$DESTDIR/stv/worker.js"
