DEV Community

Cover image for Build counter
Kolja
Kolja

Posted on

1

Build counter

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
Enter fullscreen mode Exit fullscreen mode

So in my package.json I added this:

"build": "bash increase.sh && vite build",
Enter fullscreen mode Exit fullscreen mode

and the .ENV file will have a counter:

PUBLIC_BUILD_COUNT=39
PUBLIC_BUILD_DATE=22.03.2023-15:52
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

I think, you got it ;-)

Top comments (1)

Collapse
 
nomouse profile image
slade-london

just what i was looking for!

typescript

11 Tips That Make You a Better Typescript Programmer

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay