From 3df1a8049dc693fb1a8835d2aafdd57b74aac407 Mon Sep 17 00:00:00 2001 From: "jakob.stendahl" Date: Sun, 15 Jan 2023 22:35:42 +0100 Subject: Initial commit --- postbuild.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 postbuild.sh (limited to 'postbuild.sh') diff --git a/postbuild.sh b/postbuild.sh new file mode 100755 index 0000000..8702d63 --- /dev/null +++ b/postbuild.sh @@ -0,0 +1,37 @@ +#!/bin/bash +PUBLISH_URL="/microbit-gamepad/" + +cd "dist" || exit 1 + +VERSION=$(cat ../package.json \ + | grep version \ + | head -1 \ + | awk -F: '{ print $2 }' \ + | sed 's/[",]//g' \ + | tr -d '[[:space:]]') + +tput setaf 4; echo "> Add service-worker.js..."; tput sgr0 +cp ../src/service-worker.js ./service-worker.js + +tput setaf 4; echo "> Add version number to files ($VERSION)..."; tput sgr0 +sed -i".bak" "s/{{ VERSION }}/$VERSION/g" index.html +sed -i".bak" "s/{{ VERSION }}/$VERSION/g" service-worker.js + +tput setaf 4; echo "> Add cache-files to webmanifest..."; tput sgr0 +cache_files="'$PUBLISH_URL'"; +for file in *; do + if [[ "$file" =~ (manifest.webmanifest|.git|.bak) ]]; then + continue + fi + if [[ "$cache_files" == "" ]]; then + cache_files="'$PUBLISH_URL$file'" + else + cache_files="$cache_files,""'$PUBLISH_URL$file'" + fi +done +sed -i".bak" "s|\"{{ CACHE_FILES }}\"|$cache_files|g" service-worker.js + +tput setaf 4; echo "> Remove .bak-files..."; tput sgr0 +rm *.bak + +cd .. -- cgit v1.2.3