From d40a27732f8561097ace7bdae562fc1ac2149f5b Mon Sep 17 00:00:00 2001 From: glendc Date: Thu, 19 Oct 2023 11:16:22 +0200 Subject: [PATCH] fix cache hashes --- justfile | 1 + polygrid-app/assets/sw.js | 4 ++-- polygrid-app/dist/sw.js | 4 ++-- scripts/prepare_dist_sw_js.py | 23 +++++++++++++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100755 scripts/prepare_dist_sw_js.py diff --git a/justfile b/justfile index 06e5a4d..c46b8c8 100644 --- a/justfile +++ b/justfile @@ -23,6 +23,7 @@ trunk-watch: cd polygrid-app && trunk watch qa: check check-wasm32 check-fmt clippy test test-docs trunk-build + scripts/prepare_dist_sw_js.py fmt: cargo fmt --all diff --git a/polygrid-app/assets/sw.js b/polygrid-app/assets/sw.js index 36be529..6eafa83 100644 --- a/polygrid-app/assets/sw.js +++ b/polygrid-app/assets/sw.js @@ -2,8 +2,8 @@ var cacheName = 'polygrid-pwa'; var filesToCache = [ './', './index.html', - './polygrid.js', - './polygrid_bg.wasm', + './polygrid-app-{{ POLYGRID_APP_HASH }}.js', + './polygrid-app-{{ POLYGRID_APP_HASH }}_bg.wasm', ]; /* Start the service worker and cache all of the app's content */ diff --git a/polygrid-app/dist/sw.js b/polygrid-app/dist/sw.js index 36be529..5186f93 100644 --- a/polygrid-app/dist/sw.js +++ b/polygrid-app/dist/sw.js @@ -2,8 +2,8 @@ var cacheName = 'polygrid-pwa'; var filesToCache = [ './', './index.html', - './polygrid.js', - './polygrid_bg.wasm', + './polygrid-app-6b58db615d930444.js', + './polygrid-app-6b58db615d930444_bg.wasm', ]; /* Start the service worker and cache all of the app's content */ diff --git a/scripts/prepare_dist_sw_js.py b/scripts/prepare_dist_sw_js.py new file mode 100755 index 0000000..4d456c6 --- /dev/null +++ b/scripts/prepare_dist_sw_js.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +import os +import re + + +APP_DIST_DIR = "polygrid-app/dist" + + +any_app_filename = next( + filename + for filename in os.listdir(APP_DIST_DIR) + if filename.startswith("polygrid-app-") +) + +nes_studio_hash = re.search(r'-app-([a-zA-Z0-9]+)', any_app_filename)[1] + +with open(f"{APP_DIST_DIR}/sw.js", "r") as f: + data = f.read() + data = data.replace('{{ POLYGRID_APP_HASH }}', nes_studio_hash) + +with open(f"{APP_DIST_DIR}/sw.js", "w") as f: + f.write(data)