Last active
September 28, 2023 14:15
-
-
Save loopmode/3b02f6258620244957d83543ab14cf25 to your computer and use it in GitHub Desktop.
nuke-ios - reset the ios workspace of a react-native project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# put this where you keep custom aliases and functions (e.g. ~/.bashrc or ~/.zshenv) | |
function nuke-ios() { | |
for arg in "$@"; do | |
if [[ "$arg" == "--help" ]] || [[ "$arg" == "-h" ]]; then | |
echo "nuke-ios: Resets the iOS workspace of a react-native project by deleting temporary artifacts." | |
echo | |
echo "Usage:" | |
echo " nuke-ios [options]" | |
echo | |
echo "Options:" | |
echo " --install, -i Install pods after cleanup" | |
echo " --global, -g Delete global DerivedData in ~/Library/Developer/Xcode/DerivedData" | |
echo " --help, -h Show this help message" | |
echo | |
echo "The function can be run either in the root of the react-native project, in which case it will cd into the ./ios folder and then cd back up," | |
echo "or it can be run directly inside the ./ios folder of the project." | |
echo "It will delete various temporary files/folders to ensure a clean slate. By default, it will not reinstall pods unless '--install' is passed." | |
echo "The '--global' option allows for deleting the global DerivedData directory in addition to the local one inside ./ios folder." | |
return 0 | |
fi | |
done | |
is_pwd_ios=$([[ $(basename "$PWD") == "ios" ]] && echo true || echo false) | |
local args_install=false | |
local args_global=false | |
# Parse arguments | |
while [ "$#" -gt 0 ]; do | |
case "$1" in | |
--install|-i) args_install=true; shift ;; | |
--global|-g) args_global=true; shift ;; | |
*) echo "Unknown argument: $1"; return 1 ;; | |
esac | |
done | |
if [[ "$is_pwd_ios" != "true" ]]; then | |
echo ">> cd ./ios" | |
cd ./ios || { echo "!! Unable to locate './ios' folder. Exiting."; return 1; } | |
fi | |
echo ">> Delete DerivedData" | |
rm -rf DerivedData | |
if [[ "$args_global" == "true" ]]; then | |
echo ">> Delete DerivedData global" | |
rm -rf ~/Library/Developer/Xcode/DerivedData | |
fi | |
echo ">> Delete Pods" | |
find . -name Pods -type d -exec rm -rf "{}" + | |
echo ">> Delete tmp.xcconfig" | |
rm -f tmp.xcconfig | |
echo ">> Delete xcuserdata" | |
AppName=$(find . -maxdepth 1 -name "*.xcworkspace" -exec basename {} .xcworkspace \; | head -n 1) | |
rm -rf $AppName.xcworkspace/xcuserdata | |
if [[ "$args_install" == "true" ]]; then | |
echo ">> Install pods" | |
pod install | |
else | |
echo ">> Skip pod install (pass -i or --install)" | |
fi | |
if [[ "$is_pwd_ios" != "true" ]]; then | |
echo ">> cd .." | |
cd .. | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment