#! /bin/bash

function main() {
   cd "$(dirname "$BASH_SOURCE")"
   set -e
   go test ./...
   GOOS=linux GOARCH=arm GOARM=5 CGO_ENABLED=0 go build -o $(basename "$PWD") -a -installsuffix cgo
   scp ./public/swagger/* zach@tickle.lan:./dndex/files/swagger/
   scp ./dndex zach@tickle.lan:./dndex/dndex.new
   ssh zach@tickle.lan bash -c 'true; while [ -e ./dndex/dndex.new ]; do printf "."; sleep 3; done; echo'
   if [ -n "$BIG" ]; then
      big
   fi
}

function big() {
   pushd ./public/vue/dndex-ui
   npm install
   npm run build
   scp ./dist/* zach@tickle.lan:./dndex-ui/public/
   popd
}

if [ "$0" == "$BASH_SOURCE" ]; then
   main "$@"
fi
