Skip to content

Instantly share code, notes, and snippets.

@crcdng
Last active October 6, 2024 22:46
Show Gist options
  • Save crcdng/5d21f0ba770a8a68aecc86e319ef6aa3 to your computer and use it in GitHub Desktop.
Save crcdng/5d21f0ba770a8a68aecc86e319ef6aa3 to your computer and use it in GitHub Desktop.
shell script to build and prepare a Flutter/Flame web project for itch.io
#!/bin/sh
# builds and prepares a Flutter/Flame web build for itch.io
# tested on Mac
# added: create output dir if it does not exist
# added: mitigate bug where keyboard keys are working fine locally but aren’t recognized on itch.io.
# after uploading set the dimensions in the "Embed options" section on itch.io
# set these parameters before running
PROJECT_NAME='NAME'
PROJECT_DIR='FULL PATH TO THE FLUTTER DIRECTORY OF YOUR PROJECT'
TEMP_BUILD_DIR='FULL PATH TO A TEMPORARY DIRECTORY (WILL BE CREATED AND DELETED AT THE END)'
OUTPUT_DIR='FULL PATH TO THE DIRECTORY WHERE THE ZIP FILE READY FOR UPLOAD TO ITCH.IO WILL BE PUT'
if [ ! -d "$OUTPUT_DIR" ]; then
echo "$OUTPUT_DIR does not exist. creating it"
mkdir "$OUTPUT_DIR"
fi
cd $PROJECT_DIR &&
flutter build web &&
cp -R "${PROJECT_DIR}/build/web" $TEMP_BUILD_DIR &&
sleep 1 &&
cd $TEMP_BUILD_DIR &&
sed -i '' 's/<base href="\/">//g' index.html &&
sed -i '' 's/<body>/<body>\n<script>window.onclick = function () { window.focus(); }<\/script>/g' index.html &&
zip -vr "${OUTPUT_DIR}/${PROJECT_NAME}_$(date +%Y%m%d-%H%M%S).zip" ./ -x "*.DS_Store"
rm -r $TEMP_BUILD_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment