Last active
July 29, 2022 19:49
-
-
Save Hesamedin/c960d9bcd80b7e1c2e582232e5e7320d to your computer and use it in GitHub Desktop.
Clean ios project of a Flutter project and Run it.
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
#!/bin/bash | |
set -e | |
echo "The script you are running is: $(dirname "$0")/$(basename "$0")" | |
function runDebug() { | |
flutter run iOS --debug --target=lib/main_dev.dart | |
} | |
function runRelease() { | |
flutter run iOS --target=lib/main_prod.dart | |
} | |
CURRENT_DIR="$PWD" | |
FOLDER_SYMLINKS="$CURRENT_DIR/ios/.symlinks" | |
FOLDER_PODS="$CURRENT_DIR/ios/Pods" | |
FILE_PODFILE_LOCK="$CURRENT_DIR/ios/Podfile.lock" | |
FILE_FLUTTER_PODSPEC="$CURRENT_DIR/ios/Flutter/Flutter.podspec" | |
FILE_EXPORT_ENV="$CURRENT_DIR/ios/Flutter/flutter_export_environment.sh" | |
FILE_GENERATED="$CURRENT_DIR/ios/Flutter/Generated.xcconfig" | |
ARRAY_FOLDERS=( "$FOLDER_SYMLINKS" "$FOLDER_PODS" ) | |
ARRAY_FILES=( "$FILE_PODFILE_LOCK" "$FILE_FLUTTER_PODSPEC" "$FILE_EXPORT_ENV" "$FILE_GENERATED" ) | |
# Iterate over folders and remove its contents | |
for folder in "${ARRAY_FOLDERS[@]}" | |
do | |
if [ -d "$folder" ]; then | |
rm -Rf "$folder" | |
echo "$folder deleted." | |
else | |
echo "$folder does not exist." | |
fi | |
done | |
# Iterate over files and remove them | |
for file in "${ARRAY_FILES[@]}" | |
do | |
if [ -f "$file" ]; then | |
rm "$file" | |
echo "$file deleted." | |
else | |
echo "$file does not exist." | |
fi | |
done | |
# Clean Flutter project | |
flutter clean | |
# Download dependencies | |
flutter pub get | |
# Run the app on the emulator. | |
# Make sure the emulator is running. | |
if [ "$1" = "-r" ]; then | |
echo "Release build is running..." | |
runRelease | |
else | |
echo "Debug build is running..." | |
runDebug | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script cleans the ios folder by deleting all files and folders that are being used to cache data. Then runs the Flutter app.
The script assumes that there are two entries (main file) for the project one is being used if the build is a dev build and the other will be used if it is a production build. You need to pass -r to the command if it is a production build.
I usually put this file under the
scripts
folder at the root of the project. Use the following commands when you want to run it:dev build:
prod build: