diff --git a/scripts/build.sh b/scripts/build.sh index 75a2c87..55a3dbe 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,8 +1,23 @@ #!/bin/sh SHA=$(git rev-parse --short HEAD) + +# Build to a temporary file bun build ./src/js/main.js \ - --outfile ./public/bundle.js \ + --outfile ./public/bundle.tmp.js \ --target browser -printf "////\n// version: %s\n\n" "$SHA" | cat - ./public/bundle.js > ./public/bundle.tmp.js -mv ./public/bundle.tmp.js ./public/bundle.js + +# If bundle.js doesn't exist yet, fake it it +if [ ! -f ./public/bundle.js ]; then + touch ./public/bundle.js +fi + +# Strip version comments from both files and compare +tail -n +4 ./public/bundle.js > ./public/bundle.old.content.tmp +tail -n +1 ./public/bundle.tmp.js > ./public/bundle.new.content.tmp + +if ! cmp -s ./public/bundle.old.content.tmp ./public/bundle.new.content.tmp; then + printf "////\n// version: %s\n\n" "$SHA" | cat - ./public/bundle.tmp.js > ./public/bundle.js +fi + +rm ./public/bundle.tmp.js ./public/bundle.old.content.tmp ./public/bundle.new.content.tmp \ No newline at end of file