From 7aef8d8ed3a6f4e1ec0f4f86bce914e9c2f58bdc Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 19 Mar 2026 18:11:49 +0100 Subject: [PATCH] Fix naming consistency in JS, script files - JavaScript exports have been simplified and renamed - Certain scripts now reference DIST and SRC folders - Software URLs are now loaded via the JSON file --- .gitignore | 1 - README.md | 7 +- kobopatch-wasm/build.sh | 8 +- serve-locally.sh | 8 +- tests/e2e/playwright.config.js | 2 +- tests/e2e/run-e2e.sh | 15 +- web/src/index.html | 2 + web/src/js/app.js | 22 +- web/src/js/kobo-device.js | 51 +- web/src/js/kobo-software-urls.js | 47 ++ web/src/js/{kobopatch.js => patch-runner.js} | 4 +- web/src/js/patch-ui.js | 2 +- web/src/js/wasm_exec.js | 575 ------------------- web/src/patches/downloads.json | 8 + web/src/wasm/.gitkeep | 0 15 files changed, 102 insertions(+), 650 deletions(-) create mode 100644 web/src/js/kobo-software-urls.js rename web/src/js/{kobopatch.js => patch-runner.js} (97%) delete mode 100644 web/src/js/wasm_exec.js create mode 100644 web/src/patches/downloads.json delete mode 100644 web/src/wasm/.gitkeep diff --git a/.gitignore b/.gitignore index bab7578..822b353 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,6 @@ kobopatch-wasm/kobopatch.wasm kobopatch-wasm/wasm_exec.js # Generated files in src (written by build scripts, regenerated on demand) -web/src/wasm/kobopatch.wasm web/src/js/wasm_exec.js web/src/nickelmenu/NickelMenu.zip web/src/nickelmenu/kobo-config.zip diff --git a/README.md b/README.md index ce694f4..8f5565c 100644 --- a/README.md +++ b/README.md @@ -41,10 +41,11 @@ web/ style.css js/ app.js # ES module entry point: step navigation, flow orchestration - kobo-device.js # KOBO_MODELS, FIRMWARE_DOWNLOADS, KoboDevice class + kobo-device.js # KoboModels, KoboDevice class + kobo-software-urls.js # KoboSoftwareUrls, getSoftwareUrl, getDevicesForVersion nickelmenu.js # NickelMenuInstaller: downloads/bundles NickelMenu + config patch-ui.js # PatchUI: loads patches, parses YAML, renders toggle UI - kobopatch.js # KobopatchRunner: spawns Web Worker per build + patch-runner.js # KoboPatchRunner: spawns Web Worker per build patch-worker.js # Web Worker: loads WASM, runs patchFirmware() wasm_exec.js # Go WASM runtime (generated by build.sh, gitignored) wasm/ @@ -84,7 +85,7 @@ tests/ ## Adding a new software version 1. Add the patch zip to `web/src/patches/` and update `index.json` -2. Add download URLs to `FIRMWARE_DOWNLOADS` in `web/src/js/kobo-device.js` (keyed by version then serial prefix) +2. Add download URLs to `KoboSoftwareUrls` in `web/src/js/kobo-software-urls.js` (keyed by version then serial prefix) 3. The Kobo CDN prefix per device family (e.g. `kobo12`, `kobo13`) is stable; the date path segment changes per release ## Building the WASM binary diff --git a/kobopatch-wasm/build.sh b/kobopatch-wasm/build.sh index 52fcb19..6e021de 100755 --- a/kobopatch-wasm/build.sh +++ b/kobopatch-wasm/build.sh @@ -2,6 +2,9 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +WEB_DIR="$SCRIPT_DIR/../web" +SRC_DIR="$WEB_DIR/src" +DIST_DIR="$WEB_DIR/dist" if [ ! -d "$SCRIPT_DIR/kobopatch-src" ]; then echo "Error: kobopatch source not found. Run ./setup.sh first." @@ -15,7 +18,8 @@ GOOS=js GOARCH=wasm go build -o kobopatch.wasm . echo "WASM binary size: $(du -h kobopatch.wasm | cut -f1)" echo "Copying artifacts..." -cp kobopatch.wasm "$SCRIPT_DIR/../web/src/wasm/kobopatch.wasm" -cp wasm_exec.js "$SCRIPT_DIR/../web/src/js/wasm_exec.js" +mkdir -p "$DIST_DIR/wasm" +cp kobopatch.wasm "$DIST_DIR/wasm/kobopatch.wasm" +cp wasm_exec.js "$SRC_DIR/js/wasm_exec.js" echo "Done." diff --git a/serve-locally.sh b/serve-locally.sh index 5bd8737..4344740 100755 --- a/serve-locally.sh +++ b/serve-locally.sh @@ -2,16 +2,18 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +WEB_DIR="$SCRIPT_DIR/web" +SRC_DIR="$WEB_DIR/src" +DIST_DIR="$WEB_DIR/dist" WASM_DIR="$SCRIPT_DIR/kobopatch-wasm" -DIST_DIR="$SCRIPT_DIR/web/dist" -if [ ! -f "$DIST_DIR/nickelmenu/NickelMenu.zip" ]; then +if [ ! -f "$SRC_DIR/nickelmenu/NickelMenu.zip" ]; then echo "NickelMenu assets not found, downloading..." "$SCRIPT_DIR/nickelmenu/setup.sh" fi echo "Building JS bundle..." -cd "$SCRIPT_DIR/web" +cd "$WEB_DIR" npm install --silent npm run build diff --git a/tests/e2e/playwright.config.js b/tests/e2e/playwright.config.js index 36329e6..a5d2621 100644 --- a/tests/e2e/playwright.config.js +++ b/tests/e2e/playwright.config.js @@ -17,7 +17,7 @@ module.exports = defineConfig({ }, }, webServer: { - command: 'cd ../../kobopatch-wasm && bash build.sh && cd ../web && node build.mjs && python3 -m http.server -d dist 8889', + command: 'cd ../../web && node build.mjs && cd ../kobopatch-wasm && bash build.sh && cd ../web && python3 -m http.server -d dist 8889', port: 8889, reuseExistingServer: true, }, diff --git a/tests/e2e/run-e2e.sh b/tests/e2e/run-e2e.sh index b4dd261..3373a12 100755 --- a/tests/e2e/run-e2e.sh +++ b/tests/e2e/run-e2e.sh @@ -16,6 +16,11 @@ set -euo pipefail cd "$(dirname "$0")" +PROJECT_ROOT="$(cd ../.. && pwd)" +WEB_DIR="$PROJECT_ROOT/web" +SRC_DIR="$WEB_DIR/src" +DIST_DIR="$WEB_DIR/dist" + PLAYWRIGHT_ARGS=("--reporter=list") while [[ $# -gt 0 ]]; do @@ -42,20 +47,20 @@ done FIRMWARE_VERSION="4.45.23646" FIRMWARE_URL="https://ereaderfiles.kobo.com/firmwares/kobo13/Mar2026/kobo-update-${FIRMWARE_VERSION}.zip" -FIRMWARE_DIR="../../kobopatch-wasm/testdata" +FIRMWARE_DIR="$PROJECT_ROOT/kobopatch-wasm/testdata" FIRMWARE_FILE="${FIRMWARE_DIR}/kobo-update-${FIRMWARE_VERSION}.zip" # Check WASM is built. -if [ ! -f "../../web/dist/wasm/kobopatch.wasm" ]; then +if [ ! -f "$DIST_DIR/wasm/kobopatch.wasm" ]; then echo "ERROR: kobopatch.wasm not found. Run kobopatch-wasm/build.sh first." exit 1 fi # Set up NickelMenu assets if not present. -NM_DIR="../../web/src/nickelmenu" +NM_DIR="$SRC_DIR/nickelmenu" if [ ! -f "$NM_DIR/NickelMenu.zip" ] || [ ! -f "$NM_DIR/kobo-config.zip" ]; then echo "Setting up NickelMenu assets..." - ../../nickelmenu/setup.sh + "$PROJECT_ROOT/nickelmenu/setup.sh" fi # Download firmware if not cached. @@ -80,5 +85,5 @@ npx playwright install chromium # Run the tests. echo "Running E2E integration tests..." -FIRMWARE_ZIP="$(cd ../.. && pwd)/kobopatch-wasm/testdata/kobo-update-${FIRMWARE_VERSION}.zip" \ +FIRMWARE_ZIP="$FIRMWARE_FILE" \ npx playwright test "${PLAYWRIGHT_ARGS[@]}" diff --git a/web/src/index.html b/web/src/index.html index f50e85b..41e8cb8 100644 --- a/web/src/index.html +++ b/web/src/index.html @@ -12,6 +12,8 @@ + +