echo "Moving directory to aurelia-shop plugin"
cd ../
cd aurelia-shop
# READ LAST COMMIT HASH
read -r hash<.git/refs/heads/master
echo "Latest aurelia-shop git hash: $hash"
echo "Moving directory to aurelia-shop-admin plugin"
cd ../aurelia-shop-admin
echo "Updating package.json with latest git hash of aurelia-shop"
search='("aurelia-shop": ")(.*)#([a-z0-9]*)(")'
replace="\1\2#${hash}\4"
if [[ "$OSTYPE" == "darwin"* ]]; then
  sed -i "" -E "s/${search}/${replace}/g" "package.json"
else
  sed -i -E "s/${search}/${replace}/g" "package.json"
fi
sleep 1
echo "copy src and build from plugins into aurelia-shop-admin/node_modules"
rm -rf node_modules/aurelia-resources
rm -rf node_modules/aurelia-deco
rm -rf node_modules/aurelia-swissdata
rm -rf node_modules/aurelia-shop
rsync -a ../aurelia-resources node_modules --exclude .git --exclude node_modules
rsync -a ../aurelia-deco node_modules --exclude .git --exclude node_modules
rsync -a ../aurelia-swissdata node_modules --exclude .git --exclude node_modules
rsync -a ../aurelia-shop node_modules --exclude .git --exclude node_modules
git add package.json
git commit -m "Bump aurelia-shop dependency (without proper install and neither package-lock update)"
