#!/usr/bin/env bash
set -e

CUR_DIR="$(pwd)"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

echo -e "\n## Building Portal"

echo -e "\nBuilding app"
echo ".NET Core version $(dotnet --version)"
echo "Restore"
dotnet restore "$DIR/Portal.csproj"
echo "Clean"
dotnet clean "$DIR/Portal.csproj" -c "Release" -o "$DIR/obj/Docker/publish"
echo "Node Build"
cd "$DIR"
npm install
cd "$CUR_DIR"
gulp --gulpfile "$DIR/gulpfile.js" build
echo "Publish"
dotnet publish "$DIR/Portal.csproj" -c "Release" -o "$DIR/obj/Docker/publish"

echo -e "\nBuilding docker image"
docker --version
docker build -t bitwarden/portal "$DIR/."
