From aeda6271cddbdce894dd8f6440afbd969c126954 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 14 Nov 2024 18:14:43 +0100 Subject: [PATCH] :sparkles: Improve release build process for render wasm --- frontend/scripts/build | 1 + frontend/src/app/config.cljs | 5 +++++ frontend/src/app/render_wasm.cljs | 22 ++++++++++++---------- render-wasm/build | 2 ++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/frontend/scripts/build b/frontend/scripts/build index f77c10938..b967e430b 100755 --- a/frontend/scripts/build +++ b/frontend/scripts/build @@ -30,6 +30,7 @@ rsync -avr resources/public/ target/dist/ sed -i -re "s/\%version\%/$CURRENT_VERSION/g" ./target/dist/index.html; sed -i -re "s/\%buildDate\%/$BUILD_DATE/g" ./target/dist/index.html; +sed -i "s/version=develop/version=$CURRENT_VERSION/g" ./target/dist/js/render_wasm.js; if [ "$INCLUDE_STORYBOOK" = "yes" ]; then # build storybook diff --git a/frontend/src/app/config.cljs b/frontend/src/app/config.cljs index e6b4361b0..61b410c09 100644 --- a/frontend/src/app/config.cljs +++ b/frontend/src/app/config.cljs @@ -182,3 +182,8 @@ (cond-> (u/join public-uri "assets/by-file-media-id/") (true? thumbnail?) (u/join (dm/str id "/thumbnail")) (false? thumbnail?) (u/join (dm/str id))))))) + +(defn resolve-static-asset + [path] + (let [uri (u/join public-uri path)] + (assoc uri :query (dm/str "version=" (:full version))))) diff --git a/frontend/src/app/render_wasm.cljs b/frontend/src/app/render_wasm.cljs index a625ac3ff..ee99da70c 100644 --- a/frontend/src/app/render_wasm.cljs +++ b/frontend/src/app/render_wasm.cljs @@ -11,6 +11,7 @@ [app.common.data.macros :as dm] [app.common.types.shape.impl :as ctsi] [app.common.uuid :as uuid] + [app.config :as cf] [app.util.object :as obj] [promesa.core :as p])) @@ -137,16 +138,17 @@ (defonce module (if (exists? js/dynamicImport) - (->> (js/dynamicImport "/js/render_wasm.js") - (p/mcat (fn [module] - (let [default (unchecked-get module "default")] - (default)))) - (p/fmap (fn [module] - (set! internal-module module) - true)) - (p/merr (fn [cause] - (js/console.error cause) - (p/resolved false)))) + (let [uri (cf/resolve-static-asset "js/render_wasm.js")] + (->> (js/dynamicImport (str uri)) + (p/mcat (fn [module] + (let [default (unchecked-get module "default")] + (default)))) + (p/fmap (fn [module] + (set! internal-module module) + true)) + (p/merr (fn [cause] + (js/console.error cause) + (p/resolved false))))) (p/resolved false))) (set! app.common.types.shape.impl/wasm-create-shape create-shape) diff --git a/render-wasm/build b/render-wasm/build index 4d6cd3cb1..b6ed61b58 100755 --- a/render-wasm/build +++ b/render-wasm/build @@ -29,4 +29,6 @@ cargo build $_CARGO_PARAMS cp target/wasm32-unknown-emscripten/$_BUILD_MODE/render_wasm.js ../frontend/resources/public/js/ cp target/wasm32-unknown-emscripten/$_BUILD_MODE/render_wasm.wasm ../frontend/resources/public/js/ +sed -i "s/render_wasm.wasm/render_wasm.wasm?version=develop/g" ../frontend/resources/public/js/render_wasm.js; + popd