This script recursively scans a given directory for Flutter and React Native projects and cleans them by removing unnecessary build artifacts and dependencies.
- Detects Flutter projects by checking for
pubspec.yamlandmain*.dartinside thelibfolder. - Detects React Native projects by checking for
package.jsonalong withandroidoriosdirectories. - Cleans Flutter projects using
flutter clean. - Cleans React Native projects by removing
node_modules,ios/Pods, and build directories. - Skips cleaning if the project is already clean.
- Recursively scans subdirectories if a project type is not detected at the current level.
Make sure you have the necessary tools installed:
- Flutter installed and available in PATH.
- Node.js and npm for React Native projects.
Before running the script, you need to give it execute permissions:
chmod +x cleanup.shThe script starts at the provided root directory.
It checks each folder:
- If it's a Flutter project, it runs
flutter clean. - If it's a React Native project, it removes
node_modules,ios/Pods, and build folders. - If neither, it recursively checks subdirectories.
The process continues until all subdirectories are checked.
A message confirms the cleanup completion.
Before cleaning, the script checks if the project is already clean:
- A Flutter project is clean if it has no
build/or.dart_tool/directories. - A React Native project is clean if it has no
node_modules/,ios/Pods/, or build directories.
If the project is already clean, the script skips it to save time.
./cleanup.sh ~/ProjectsThis command will clean all Flutter and React Native projects inside the ~/Projects directory and its subdirectories.
- The script does not reinstall dependencies (
flutter pub getornpm install). You may need to do this manually after cleaning. - Ensure you have backup copies of important files before running the script.
This script is open-source and can be modified as needed.