#!/bin/bash

source ./cappello_batch.sh

source ./.env.test.gruppomacro

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

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

cp .env.test.gruppomacro .env.production

sleep 1

  mv public/upload/products ../../
  mv public/upload/profile ../../

  npm run buildpwatest

  mv ../../products public/upload/
  mv ../../profile public/upload/

echo "Sincronizzazione $SERVERDIR_WEBSITE in remoto..."
rsync -e 'ssh -p 8822' -a --exclude 'upload' dist/pwa/ pcbuser@pcb:$SERVERDIR_WEBSITE
rsync -e 'ssh -p 8822' -av --delete dist/pwa/js/ pcbuser@pcb:$SERVERDIR_WEBSITE/js

sleep 1

echo "Finito $SERVERDIR_WEBSITE"
