#!/bin/bash

source ./cappello_batch.sh

source ./.env.test

msg="*** Sincronizzazione ???  $DIRECTORY_LOCAL e $SERVERDIR_WEBSITE (Y/N) ? "

if [ "$1" = "" ]; then
  read -p "$msg" risposta
else
  risposta=$1
fi

cd /home/paolo/myproject/$DIRECTORY_LOCAL/
cp .env.production .env.prod.bak
cp .env.test .env.production

sleep 1

npm run buildspa

echo "Sincronizzazione $SERVERDIR_WEBSITE in remoto..."
sshpass -p $SERVERPW_WEBSITE rsync -e 'ssh -p 8855' -a --exclude 'upload' dist/spa/ ftpadmin@servereng:$SERVERDIR_WEBSITE/
rsync -e 'ssh -p 8855' -av --delete dist/spa/js/ ftpadmin@servereng:$SERVERDIR_WEBSITE/js

cp .env.prod.bak .env.production

sleep 1

echo "Finito $SERVERDIR_WEBSITE"
