Skip to content

Commit e80955e

Browse files
committed
Add flutter upgrade script
1 parent 73e7848 commit e80955e

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

scripts/update_flutter.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
# This script loops through subdirectories to find Flutter projects,
4+
# cleans them by removing platform-specific folders,
5+
# recreates the Flutter project files, and then removes an unnecessary test file.
6+
7+
# Find all directories one level deep from the current location.
8+
for dir in */; do
9+
# Ensure we are only processing actual directories.
10+
if [ -d "$dir" ]; then
11+
echo "🔎 Processing directory: $dir"
12+
13+
pubspec_file="${dir}pubspec.yaml"
14+
15+
# 1. Check if pubspec.yaml exists and contains a 'flutter:' dependency.
16+
if [ -f "$pubspec_file" ] && grep -q "flutter:" "$pubspec_file"; then
17+
echo " ✅ Found pubspec.yaml with a Flutter dependency."
18+
19+
# 2. Check if it's a valid project by looking for platform folders.
20+
if [ -d "${dir}ios" ] || [ -d "${dir}android" ] || [ -d "${dir}web" ] || \
21+
[ -d "${dir}macos" ] || [ -d "${dir}windows" ] || [ -d "${dir}linux" ]; then
22+
23+
echo " ✅ Found platform folders. Proceeding with cleanup..."
24+
25+
# Using a subshell to change directory, so we don't have to 'cd ..'
26+
(
27+
cd "$dir" || exit
28+
29+
# 3. Remove the old platform folders.
30+
echo " Removing platform folders: ios, android, web, macos, windows, linux"
31+
rm -rf ios android web macos windows linux
32+
33+
# 4. Recreate the Flutter project in the current directory.
34+
echo " 🚀 Running 'fvm flutter create .'"
35+
fvm flutter create .
36+
37+
# 5. Remove the default widget test file.
38+
widget_test_file="test/widget_test.dart"
39+
if [ -f "$widget_test_file" ]; then
40+
echo " 🗑️ Removing generated file: $widget_test_file"
41+
rm "$widget_test_file"
42+
fi
43+
44+
echo " ✨ Successfully processed project in $dir"
45+
)
46+
else
47+
echo " ⏭️ Skipping: No platform folders found."
48+
fi
49+
else
50+
echo " ⏭️ Skipping: Not a Flutter project."
51+
fi
52+
echo "--------------------------------------------------"
53+
fi
54+
done
55+
56+
echo "All directories have been processed."

0 commit comments

Comments
 (0)