Skip to content

Commit

Permalink
fix cache hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
glendc committed Oct 19, 2023
1 parent aa27e3d commit d40a277
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions polygrid-app/assets/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions polygrid-app/dist/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
23 changes: 23 additions & 0 deletions scripts/prepare_dist_sw_js.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit d40a277

Please sign in to comment.