#!/bin/bash

set -e;

utils_repo="fusion-utils"
datastore_repo="fusiondatastore"
grid_repo="fusiongrid"

read -p "Enter branch for ${utils_repo}? [develop] : " fusion_utils_branch
read -p "Enter branch for ${datastore_repo}? [develop] : " fusiondatastore_branch
read -p "Enter branch for ${grid_repo}? [develop] : " fusiongrid_branch

if [[ -z "$fusion_utils_branch" ]]; then
  fusion_utils_branch="develop"
fi

if [[ -z "$fusiondatastore_branch" ]]; then
  fusiondatastore_branch="develop"
fi

if [[ -z "$fusiongrid_branch" ]]; then
  fusiongrid_branch="develop"
fi

cd ../../../

# TO DO make this a loop after removing lerna
echo -e "\n\033[33mGenerating builds for ${utils_repo} on branch ${fusion_utils_branch} \033[0m"
cd ${utils_repo}/
git fetch --all;
git checkout ${fusion_utils_branch};
git pull;
npm run build;
cd ../

echo -e "\n\033[33mGenerating builds for ${datastore_repo} on branch ${fusiondatastore_branch} \033[0m"
cd ${datastore_repo}/
git fetch --all;
git checkout ${fusiondatastore_branch};
git pull;
npm run build;
cd ../

echo -e "\n\033[33mGenerating builds for ${grid_repo} on branch ${fusiongrid_branch} \033[0m"
cd ${grid_repo}/
git fetch --all;
git checkout ${fusiongrid_branch};
git pull;
#TO DO remove following line after removing lerna
cd packages/grid-core/
npm run build;

# rm -rf ./bundle
# mkdir bundle
# cp dist/ bundle/
# cp ../../../${datastore_repo}/dist/fusiondatastore.js bundle/

