Skip to content

Instantly share code, notes, and snippets.

@pavelglebov
Last active July 10, 2024 11:28
Show Gist options
  • Save pavelglebov/05898726f13159a6f1b663b00b05f16c to your computer and use it in GitHub Desktop.
Save pavelglebov/05898726f13159a6f1b663b00b05f16c to your computer and use it in GitHub Desktop.
React Native refresh packages util script
#!/bin/bash
CYAN='\033[0;36m'
RED='\033[0;31m'
NOCOLOR='\033[0m'
command=$1
shift
clean_locks=false
while getopts ":c" opt; do
case ${opt} in
c )
clean_locks=true
;;
\? )
echo "Invalid option: $OPTARG" 1>&2
exit 1
;;
: )
echo "Invalid option: $OPTARG requires an argument" 1>&2
exit 1
;;
esac
done
refresh_node_modules() {
if [ "$clean_locks" = true ]; then
echo -e "${RED}deleting yarn.lock${NOCOLOR}"
rm -f yarn.lock
fi
echo -e "${CYAN}Refreshing node_modules${NOCOLOR}"
rm -rf ./node_modules && yarn install
}
refresh_ios() {
if [ "$clean_locks" = true ]; then
echo -e "${RED}deleting Podfile.lock${NOCOLOR}"
rm -f ./ios/Podfile.lock
fi
echo -e "${CYAN}Refreshing iOS packages${NOCOLOR}"
rm -rf ./ios/Pods
cd ios && pod install
}
refresh_android() {
echo -e "${CYAN}Refreshing Android packages${NOCOLOR}"
cd android && ./gradlew clean
}
refresh_watchman() {
yarn wc
}
refresh_all() {
refresh_node_modules
refresh_ios
cd ..
refresh_android
refresh_watchman
}
if [ "$command" = "ios" ]; then
refresh_node_modules
refresh_ios
refresh_watchman
exit 0
elif [ "$command" = "android" ]; then
refresh_node_modules
refresh_android
refresh_watchman
exit 0
elif [ "$command" = "npm" ]; then
refresh_node_modules
refresh_watchman
exit 0
else
refresh_all
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment