#!/bin/bash

echo "Checking for Mobile First and React Native version compatibility..."

#List the version of react-native package installed
propDep="version"
BASE_DIR=$PWD/..
RN_VERSION=$(node -pe "require('$BASE_DIR/react-native/package.json')['$prop']")


VERSION="${RN_VERSION//^}"
VER="${VERSION//.}"
MIN=0615

#Check if react-native version is available. Else throw an error stating to install react-native package first
if [[ $VER =~ [0-9]+ ]]; then
	echo "react-native version identified."
else
	echo "No react-native module found. Please install react-native equal to or above version 0.61.5 and then install the Mobile First react-native package. "
	exit 1
fi

#Check if minimum required react-native version is matched. If not, exit the installation process.
if [ $VER -ge $MIN  ]
then
echo "Successful installation"
else
echo "MF does not support apps using react-native version below version 0.61.5. Please upgrade to react-native greater than or equal to version 0.61.5 to use Mobile First"
exit 1
fi

