Skip to content

Instantly share code, notes, and snippets.

@Atsumi3
Created May 29, 2023 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Atsumi3/e280de62a748575e6ef5a8e17bce6094 to your computer and use it in GitHub Desktop.
Save Atsumi3/e280de62a748575e6ef5a8e17bce6094 to your computer and use it in GitHub Desktop.
[fvm] Flutterでプロジェクトがおかしくなった時に正常化するShellスクリプト
#!/usr/bin/env bash
PUBSPEC_FILE_NAME='pubspec.yaml'
echo '------------------------------------'
echo '-- flutter clean'
echo $(pwd)
# .dart_tool を除いたプロジェクトフォルダ内の $PUBSPEC_FILE_NAME が格納されているディレクトリ一覧を取得
PUB_SPEC_DIRS=$(find "$(pwd)" \
-type d -name ".dart_tool" -prune -o \
-type f -name $PUBSPEC_FILE_NAME \
-exec dirname {} \;
)
for PUB_SPEC_DIR in $PUB_SPEC_DIRS; do
cd "$PUB_SPEC_DIR" || continue
echo '------------------------------------'
echo "-- run flutter clean -> $(pwd)"
fvm flutter clean
done
echo ''
echo '------------------------------------'
echo '-- flutter pub get'
for PUB_SPEC_DIR in $PUB_SPEC_DIRS; do
cd "$PUB_SPEC_DIR" || continue
echo '------------------------------------'
echo "-- run pub get -> $(pwd)"
fvm flutter pub get
done
echo ''
echo '------------------------------------'
echo '-- flutter precache'
for PUB_SPEC_DIR in $PUB_SPEC_DIRS; do
cd "$PUB_SPEC_DIR" || continue
echo '------------------------------------'
echo "-- run flutter precache -> $(pwd)"
fvm flutter precache --ios
fvm flutter precache --android
done
echo ''
echo '------------------------------------'
echo '-- flutter pub run build_runner build --delete-conflicting-outputs'
for PUB_SPEC_DIR in $PUB_SPEC_DIRS; do
cd "$PUB_SPEC_DIR" || continue
if grep 'build_runner' "$PUBSPEC_FILE_NAME" >/dev/null; then
echo '------------------------------------'
echo "-- run build_runner -> $(pwd)"
echo '------------------------------------'
fvm flutter packages pub run build_runner build --delete-conflicting-outputs
echo '------------------------------------'
echo "-- finish build_runner -> $(pwd)"
echo '------------------------------------'
fi
done
echo ''
echo '------------------------------------'
echo '-- pod install'
pod repo update
PODFILE_DIRS=$(
find "$(pwd)" \
-type d -name ".dart_tool" -prune -o \
-type f -name "Podfile" \
-exec dirname {} \;
)
for PODFILE_DIR in $PODFILE_DIRS; do
echo '------------------------------------'
echo "-- run pod install -> $(pwd)"
cd "$PODFILE_DIR" || continue
pod install
done
echo ''
echo '------------------------------------'
echo '-- (prebuild) flutter build ipa'
for PUB_SPEC_DIR in $PUB_SPEC_DIRS; do
cd "$PUB_SPEC_DIR" || continue
echo '------------------------------------'
if [ -e "ios/Runner.xcworkspace" ]; then
if grep 'Staging' "ios/Runner.xcodeproj/project.pbxproj" >/dev/null; then
echo "-- run flutter build ipa -> $(pwd)"
fvm flutter build ipa --no-codesign --flavor Staging
else
echo "-- run flutter build ipa -> $(pwd)"
fvm flutter build ipa --no-codesign
fi
fi
done
echo ''
echo '------------------------------------'
echo '-- (prebuild) flutter build apk'
for PUB_SPEC_DIR in $PUB_SPEC_DIRS; do
cd "$PUB_SPEC_DIR" || continue
echo '------------------------------------'
if [ -e "android/app/build.gradle" ]; then
if grep 'staging' "android/app/build.gradle" >/dev/null; then
echo "-- run flutter build apk -> $(pwd)"
fvm flutter build apk --flavor Staging
else
echo "-- run flutter build apk -> $(pwd)"
fvm flutter build apk
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment