diff options
author | jakob.stendahl <jakob.stendahl@infomedia.dk> | 2023-01-15 22:35:42 +0100 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2023-01-15 22:35:42 +0100 |
commit | 3df1a8049dc693fb1a8835d2aafdd57b74aac407 (patch) | |
tree | 82b34456f34224a92f36591be908c69a4fddb3eb /postbuild.sh | |
parent | 216e1259c32c4775768da915b6fea9b8adc5c35f (diff) | |
download | microbit-gamepad-3df1a8049dc693fb1a8835d2aafdd57b74aac407.tar.gz microbit-gamepad-3df1a8049dc693fb1a8835d2aafdd57b74aac407.zip |
Initial commit
Diffstat (limited to 'postbuild.sh')
-rwxr-xr-x | postbuild.sh | 37 |
1 files changed, 37 insertions, 0 deletions
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 .. |