Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ coverage/
*.test.ts

# Version control
.git/
# The .git dir is intentionally included in the build context because the build stage needs it to derive a version tag.
# The Dockerfile only copies the build stage output from /app/dist into the final image, so .git is excluded that way.
.gitignore

# CI/CD
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"name": "fdp-client-v3",
"version": "2.0.0-dev",
"private": true,
"type": "module",
"scripts": {
Expand Down
25 changes: 22 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// <reference types="vitest/config" />

import { strict as assert } from 'node:assert'
import { spawnSync } from 'node:child_process'
import * as fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath, URL } from 'node:url'
Expand All @@ -9,8 +11,6 @@ import { defineConfig, HtmlTagDescriptor, ViteDevServer } from 'vite'
import vueDevTools from 'vite-plugin-vue-devtools'
import svgLoader from 'vite-svg-loader'

import { version } from './package.json'

// https://vite.dev/config/
export default defineConfig({
// plugin order matters
Expand All @@ -21,7 +21,7 @@ export default defineConfig({
},
},
define: {
__APP_VERSION__: JSON.stringify(version),
__APP_VERSION__: JSON.stringify(gitDescribeVersion()),
__APP_BUILT_AT__: JSON.stringify(new Date().toISOString()),
},
// vitest options
Expand Down Expand Up @@ -65,6 +65,25 @@ function clientConfigOverridePlugin() {
}
}

/**
* Returns a version string obtained from `git describe`, in long format, for example, `'v1.2.3-0-gfc7760f'`.
* Fails intentionally if the `git describe` call fails or if its output is falsy.
*/
function gitDescribeVersion(): string {
const { stdout, stderr, status } = spawnSync(
'git',
[
'describe',
'--tags', // include the lightweight tags created by e.g. github
'--always', // use abbreviated commit hash if there are no tags at all
'--long', // use long format even if the current commit is tagged ('v1.2.3-0-gfc7760f' instead of 'v1.2.3')
],
{ encoding: 'utf8' },
)
assert(stdout, `git describe call failed (exit code: ${status}, stderr: ${stderr?.trim()})`)
return stdout.trim()
}

/**
* Appends a `<link>` tag for a custom CSS `stylesheet` to the `<head>` section of `index.html`.
* This should be loaded after the default CSS files to allow proper overriding.
Expand Down