#!/bin/bash -exu

# This script will reload all the plugins that have been installed,
# which gets you upto the most recent versions.

cd `dirname "$0"`/..

unset NODE_ENV
npm install
CORDOVA="$(npm bin)/cordova"
PLUGINS=`"$CORDOVA" plugins ls | cut -d ' ' -f 1 | tr  '\n' ' '`
echo "$PLUGINS"
if [ "$PLUGINS" == "No " ]
then
  echo "Looks like we have no plugins; that can't be right. Bailing."
  exit -1
fi
mkdir -p ./platforms/android/assets/www/
touch ./platforms/android/assets/www/cordova_plugins.js
for plugin in $PLUGINS
do
  "$CORDOVA" plugins remove --verbose --force $plugin || true
  "$CORDOVA" plugins add --verbose --force $plugin || true
done
