Last active
November 11, 2023 08:25
-
-
Save Ansh-Rathod/9b72aa55ca8616b92d8bd5cdc731e1aa to your computer and use it in GitHub Desktop.
flutter auto hot reload script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
chmod 777 ./hotreloader.sh | |
echo 'Script is running'; | |
while true | |
do | |
find lib/ -name '*.dart' | entr -dnp ./hotreloader.sh /_ | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
PIDFILES=($(compgen -G "/tmp/flutter*.pid")) | |
if [[ "${1-}" != "" && ${#PIDFILES[@]} > 0 ]]; then | |
echo $1 | |
PIDS="" | |
for pf in ${PIDFILES[@]}; do | |
PIDS+=$(cat $pf) | |
PIDS+=" " | |
done | |
if [[ "$1" =~ \/state\/ || "$1" =~ backend ]]; then | |
echo "Restarting ${PIDS}" | |
kill -USR2 $PIDS | |
else | |
echo "Reloading ${PIDS}" | |
kill -USR1 $PIDS | |
fi | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to run flutter run in the background | |
run_flutter() { | |
flutter run --pid-file /tmp/flutter.pid | |
# When flutter run exits, exit the script | |
exit | |
} | |
# Run the hotreload.sh script | |
sh ./hotreload.sh & | |
# Run flutter run in the background | |
run_flutter | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
brew install entr
install this package first.