Skip to content

Instantly share code, notes, and snippets.

@ludoo0d0a
Last active March 30, 2020 19:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ludoo0d0a/12c013739c19c6e0998a19192674ee3d to your computer and use it in GitHub Desktop.
Save ludoo0d0a/12c013739c19c6e0998a19192674ee3d to your computer and use it in GitHub Desktop.
Flutter upgrade from a fresh install
#!/bin/bash
#
# Flutter upgrade from a fresh install
# version : 1.0
# Can be used in case of androidX migration.
# ios, Android specific configruation are not copied ; use a git merge after execution
#
# Copy this file in /usr/local/bin/ and call it from root source of an existing flutter project.
# It requires : jq, xq and yq installation
# > brew install jq
# > pip install yq xq
#
# > curl -o /usr/local/bin/flutter-upgrade.sh https://gist.githubusercontent.com/ludoo0d0a/12c013739c19c6e0998a19192674ee3d/raw/flutter-upgrade.sh
# > chmod +x /usr/local/bin/flutter-upgrade.sh
#
# set -x
TMP=tmp_upgrade
DIR=${PWD##*/}
APP=`yq .name pubspec.yaml | tr -d '"'`
DESC=`yq .description pubspec.yaml | tr -d '"'`
PACKAGE=`xq .manifest[\"@package\"] android/app/src/main/AndroidManifest.xml | head -n1 | tr -d '"'`
git checkout -b upgrade
rm -rf $TMP
mkdir $TMP
cd $TMP
flutter create --org "$PACKAGE" -i swift -a kotlin --description "$DESC" $APP
cd $APP
#Prepare content
rm -rf lib
cp -rf ../../lib lib
rm -rf test
cp -rf ../../test test
rm -rf assets
cp -rf ../../assets assets
cp -rf ../../pubspec.yaml pubspec.yaml
cp -rf ../../.gitignore .gitignore
rm -f README.md
#Copy content back
cd ../..
rm -rf android
rm -rf ios
cp -rf $TMP/$APP/* .
# Clean
rm -rf $TMP
rm -f .packages
pwd
# build
flutter clean
flutter packages get
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment