33# This script loops through subdirectories to find Flutter projects,
44# cleans them by removing platform-specific folders,
55# recreates the Flutter project files, and then removes an unnecessary test file.
6+ #
7+ # Usage:
8+ # ./scripts/update_flutter.sh # Process all Flutter projects
9+ # ./scripts/update_flutter.sh signals # Process only the 'signals' directory
610
7- # Find all directories one level deep from the current location.
8- for dir in * /; do
11+ # Check if a specific directory was provided as an argument
12+ if [ $# -eq 1 ]; then
13+ # Process only the specified directory
14+ target_dir=" $1 "
15+ if [ ! -d " $target_dir " ]; then
16+ echo " ❌ Error: Directory '$target_dir ' does not exist."
17+ exit 1
18+ fi
19+ # Add trailing slash if not present
20+ if [[ ! " $target_dir " == * / ]]; then
21+ target_dir=" ${target_dir} /"
22+ fi
23+ directories=(" $target_dir " )
24+ else
25+ # Find all directories one level deep from the current location
26+ directories=(* /)
27+ fi
28+
29+ # Process the directories
30+ for dir in " ${directories[@]} " ; do
931 # Ensure we are only processing actual directories.
1032 if [ -d " $dir " ]; then
1133 echo " 🔎 Processing directory: $dir "
@@ -14,40 +36,48 @@ for dir in */; do
1436
1537 # 1. Check if pubspec.yaml exists and contains a 'flutter:' dependency.
1638 if [ -f " $pubspec_file " ] && grep -q " flutter:" " $pubspec_file " ; then
17- echo " ✅ Found pubspec.yaml with a Flutter dependency."
39+ echo " ✅ Found pubspec.yaml with a Flutter dependency."
1840
1941 # 2. Check if it's a valid project by looking for platform folders.
2042 if [ -d " ${dir} ios" ] || [ -d " ${dir} android" ] || [ -d " ${dir} web" ] || \
2143 [ -d " ${dir} macos" ] || [ -d " ${dir} windows" ] || [ -d " ${dir} linux" ]; then
2244
23- echo " ✅ Found platform folders. Proceeding with cleanup..."
45+ echo " ✅ Found platform folders. Proceeding with cleanup..."
2446
2547 # Using a subshell to change directory, so we don't have to 'cd ..'
2648 (
2749 cd " $dir " || exit
2850
2951 # 3. Remove the old platform folders.
30- echo " Removing platform folders: ios, android, web, macos, windows, linux"
52+ echo " Removing platform folders: ios, android, web, macos, windows, linux"
3153 rm -rf ios android web macos windows linux
3254
3355 # 4. Recreate the Flutter project in the current directory.
34- echo " 🚀 Running 'fvm flutter create .'"
56+ echo " 🚀 Running 'fvm flutter create .'"
3557 fvm flutter create .
3658
3759 # 5. Remove the default widget test file.
3860 widget_test_file=" test/widget_test.dart"
3961 if [ -f " $widget_test_file " ]; then
40- echo " 🗑️ Removing generated file: $widget_test_file "
62+ echo " 🗑️ Removing generated file: $widget_test_file "
4163 rm " $widget_test_file "
4264 fi
4365
44- echo " ✨ Successfully processed project in $dir "
66+ # Clean the project
67+ echo " 🧹 Cleaning the project"
68+ fvm flutter clean
69+
70+ # Install dependencies
71+ echo " 🔎 Installing dependencies"
72+ fvm flutter pub get
73+
74+ echo " ✨ Successfully processed project in $dir "
4575 )
4676 else
47- echo " ⏭️ Skipping: No platform folders found."
77+ echo " ⏭️ Skipping: No platform folders found."
4878 fi
4979 else
50- echo " ⏭️ Skipping: Not a Flutter project."
80+ echo " ⏭️ Skipping: Not a Flutter project."
5181 fi
5282 echo " --------------------------------------------------"
5383 fi
0 commit comments