#!/usr/bin/env bash

npm i -g react-native-cli

# Clean-up activities
#rm -rf android/.gradle
#rm -rf android/app/build

# Creates an .env from ENV variables for use with react-native-config
ENV_WHITELIST=${ENV_WHITELIST:-"^RN_"}
printf "Creating an .env file with the following whitelist:\n"
printf "%s\n" $ENV_WHITELIST
set | egrep -e $ENV_WHITELIST | sed 's/^RN_//g' > .env
printf "\n.env created with contents:\n\n"
cat /Users/runner/work/1/s/.env
source /Users/runner/work/1/s/.env

printf "\n.env content checking - 1 :\n\n"
pwd
ls -altr
chmod +rwx /Users/runner/work/1/s/.env

printf "\n.env content check after one round test - 2 :\n\n"
ls -ltrha
cat /Users/runner/work/1/s/.env

# Builing app using react-native cli
printf "\n. Initial build setup:\n\n"
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

# Clean-up drawable items
printf "\n. Clean-up drawable items:\n\n"
rm -rf /Users/runner/work/1/s/android/app/src/main/res/drawable-*

printf "\n. Exporting the env files:\n\n"
export ENVFILE=.env
echo $ENVFILE

printf "\n. ################### FINISHED THE PREBUILD SETUP #################:\n\n"