Skip to content

Cache breaking #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions example_app/.gitignore → .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,28 @@
# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/
example_app/.dart_tool/
example_app/.flutter-plugins
example_app/.flutter-plugins-dependencies
example_app/.packages
example_app/.pub-cache/
example_app/.pub/
example_app/build/
example_app/flutter/

# Web related
lib/generated_plugin_registrant.dart
example_app/lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols
example_app/app.*.symbols

# Obfuscation related
app.*.map.json
example_app/app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
example_app/android/app/debug
example_app/android/app/profile
example_app/android/app/release

# Local Netlify folder
.netlify
39 changes: 37 additions & 2 deletions build-web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# Reminder to check for updates to the build script.
# Flutter for web is still in beta so expect updates!

CURRENT_VERSION=1.0.1
CURRENT_VERSION=1.1.0
REMOTE_URL="https://github.com/FrankFlitton/Flutter-for-web-deploy-script"
REMOTE_TAGS="$(git ls-remote --tags $REMOTE_URL)"
REMOTE_TAGS="$(echo $(git ls-remote --tags $REMOTE_URL))"

REMOTE_HASHES=()
REMOTE_VERSIONS=()
Expand Down Expand Up @@ -98,4 +98,39 @@ $FLUTTER_BIN build web --release
echo "🚚🖼 Copying graphic assets to their expected folders"
cp -R $APP_DIR/build/web/assets/. $APP_DIR/build/web/

# Start cache breaking

BUILD_HASH=$((1 + $RANDOM % 100000))
HASHED_FILE=""

fileExtHash() {
SEPERATOR=$(echo $1 | tail -c 2)
F_EXT=$(echo $1 | cut -d"$SEPERATOR" -f 1)
HASHED_EXT=$F_EXT"?"$BUILD_HASH$SEPERATOR
HASHED_FILE=$HASHED_EXT
}

replacePath() {
INPUT_FILE=$1
TARGET_EXT=$2
TARGET_HASHED_EXT=$3
cat $INPUT_FILE | awk -v srch="$TARGET_EXT" -v repl="$TARGET_HASHED_EXT" '{ sub(srch,repl,$0); print $0 }' >tmp && mv tmp $INPUT_FILE
}

# Force new js to be loaded by the browser.
# Breaking cache on js and json files in index.html

HTML_EXTS=("js" "json")

echo "✅📦 Hashing assets for this release"

for EXT_ROOT in ${HTML_EXTS[@]}; do
# echo $EXT
EXT_LIST=("."$EXT_ROOT\" "."$EXT_ROOT\')
for EXT in ${EXT_LIST[@]}; do
fileExtHash $EXT
replacePath $APP_DIR/build/web/index.html $EXT $HASHED_FILE
done
done

echo "✅🦋 Flutter for web build pipeline complete!"
39 changes: 37 additions & 2 deletions example_app/build-web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# Reminder to check for updates to the build script.
# Flutter for web is still in beta so expect updates!

CURRENT_VERSION=1.0.1
CURRENT_VERSION=1.1.0
REMOTE_URL="https://github.com/FrankFlitton/Flutter-for-web-deploy-script"
REMOTE_TAGS="$(git ls-remote --tags $REMOTE_URL)"
REMOTE_TAGS="$(echo $(git ls-remote --tags $REMOTE_URL))"

REMOTE_HASHES=()
REMOTE_VERSIONS=()
Expand Down Expand Up @@ -98,4 +98,39 @@ $FLUTTER_BIN build web --release
echo "🚚🖼 Copying graphic assets to their expected folders"
cp -R $APP_DIR/build/web/assets/. $APP_DIR/build/web/

# Start cache breaking

BUILD_HASH=$((1 + $RANDOM % 100000))
HASHED_FILE=""

fileExtHash() {
SEPERATOR=$(echo $1 | tail -c 2)
F_EXT=$(echo $1 | cut -d"$SEPERATOR" -f 1)
HASHED_EXT=$F_EXT"?"$BUILD_HASH$SEPERATOR
HASHED_FILE=$HASHED_EXT
}

replacePath() {
INPUT_FILE=$1
TARGET_EXT=$2
TARGET_HASHED_EXT=$3
cat $INPUT_FILE | awk -v srch="$TARGET_EXT" -v repl="$TARGET_HASHED_EXT" '{ sub(srch,repl,$0); print $0 }' >tmp && mv tmp $INPUT_FILE
}

# Force new js to be loaded by the browser.
# Breaking cache on js and json files in index.html

HTML_EXTS=("js" "json")

echo "✅📦 Hashing assets for this release"

for EXT_ROOT in ${HTML_EXTS[@]}; do
# echo $EXT
EXT_LIST=("."$EXT_ROOT\" "."$EXT_ROOT\')
for EXT in ${EXT_LIST[@]}; do
fileExtHash $EXT
replacePath $APP_DIR/build/web/index.html $EXT $HASHED_FILE
done
done

echo "✅🦋 Flutter for web build pipeline complete!"