I asked myself, "how often did I build this project"?
Therefore, I'm using Vite (with SvelteKit), I searched for a build-in build-counter, but it seems, that there is nothing like that.
Okay, I didn't search that long, because this is a well working solution:
#!/bin/bash
# read the .env file
source .env
# Increase the version number in .env
NEW=$(($PUBLIC_BUILD_COUNT+1))
# write the new version number to .env
sed -i~ '/^PUBLIC_BUILD_COUNT=/s/=.*/='$NEW'/' .env
So in my package.json
I added this:
"build": "bash increase.sh && vite build",
and the .ENV
file will have a counter:
PUBLIC_BUILD_COUNT=39
PUBLIC_BUILD_DATE=22.03.2023-15:52
Oh wait, there is more:
# Get the current date and time
DATE=$(date +'%d.%m.%Y-%H:%M')
# write the new date to .env
sed -i~ '/^PUBLIC_BUILD_DATE=/s/=.*/='$DATE'/' .env
I think, you got it ;-)
Top comments (1)
just what i was looking for!