git precommit hooks

This commit is contained in:
cpu
2025-05-09 16:57:06 +02:00
parent c656af0009
commit ba26edf8be
6 changed files with 122 additions and 15 deletions

View File

@@ -177,7 +177,30 @@ curl https://nexus-timer.virtonline.eu
Or open it in your browser:
[https://nexus-timer.virtonline.eu](https://nexus-timer.virtonline.eu)
### Update the app
## Developer Setup
### Clone the repository
```bash
git clone https://gitea.virtonline.eu/2HoursProject/nexus-timer.git
cd nexus-timer
```
### Git Pre-Commit Hook
This project uses a Git pre-commit hook to automatically updates the build timestamp placeholder in `src/views/InfoView.vue` and increments the `CACHE_VERSION` in `public/service-worker.js` (it is the indicator for the installed PWA that the new version is available). This ensures that each commit intended for a build/deployment reflects the correct information.
**Setup Steps:**
1. **Ensure Node.js is installed.** The hook script is written in Node.js.
2. **Configure Git to use the local hooks directory:**
After cloning the repository, run the following command in your terminal from the project root to tell Git to use the hooks located in the `.githooks` directory:
```bash
git config core.hooksPath .githooks
```
This step needs to be done once per local clone of the repository.
3. **Ensure the hook script is executable:**
The script `scripts/git-hooks/pre-commit.js` is the source, and it's copied/symlinked to `.githooks/pre-commit`. If you manually copy or if permissions are lost, ensure the hook in `.githooks` is executable:
```bash
chmod +x .githooks/pre-commit
```
(The main script in `scripts/git-hooks/` should also be executable if you plan to run it manually for testing: `chmod +x scripts/git-hooks/pre-commit.js`)
### Modify the app
Make code changes...
Run the live update server locally
@@ -188,11 +211,6 @@ npm run dev
Open it in your browser:
[http://localhost:8080/](http://localhost:8080/)
When done, do not forget to update the `CACHE_VERSION` in the `service-worker.js`. It is the indicator for the PWA that the new version is available.
```bash
ver=$(grep -oP "CACHE_VERSION = 'nexus-timer-cache-v\K[0-9]+" public/service-worker.js)
sed -i "s/nexus-timer-cache-v$ver/nexus-timer-cache-v$((ver+1))/" public/service-worker.js
```
Stage changes, commit and push
```bash
git add .