diff --git a/package.json b/package.json index 226fa5dd..86474dc2 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@fontsource/open-sans": "^4.4.5", "@hcaptcha/react-hcaptcha": "^0.3.6", "@preact/preset-vite": "^2.0.0", + "@rollup/plugin-replace": "^2.4.2", "@styled-icons/bootstrap": "^10.34.0", "@styled-icons/feather": "^10.34.0", "@styled-icons/simple-icons": "^10.33.0", diff --git a/src/pages/settings/Settings.module.scss b/src/pages/settings/Settings.module.scss index 2540c1c0..4f095c0e 100644 --- a/src/pages/settings/Settings.module.scss +++ b/src/pages/settings/Settings.module.scss @@ -104,6 +104,10 @@ display: flex; flex-direction: column; } + + .revision a:hover { + text-decoration: underline; + } } scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track); diff --git a/src/pages/settings/Settings.tsx b/src/pages/settings/Settings.tsx index a4115c90..a8713521 100644 --- a/src/pages/settings/Settings.tsx +++ b/src/pages/settings/Settings.tsx @@ -20,6 +20,7 @@ import { User } from "@styled-icons/feather"; import { Megaphone } from "@styled-icons/bootstrap"; +import { GIT_REVISION, REPO_URL } from "../../revision"; import LineDivider from "../../components/ui/LineDivider"; import RequiresOnline from "../../context/revoltjs/RequiresOnline"; import ButtonItem from "../../components/navigation/items/ButtonItem"; @@ -142,6 +143,11 @@ export default function Settings() { ,
+ + + { GIT_REVISION.substr(0, 7) } + + Stable {APP_VERSION} API: {client.configuration?.revolt ?? "N/A"} revolt.js: {LIBRARY_VERSION} diff --git a/src/revision.ts b/src/revision.ts new file mode 100644 index 00000000..ab519af0 --- /dev/null +++ b/src/revision.ts @@ -0,0 +1,2 @@ +export const GIT_REVISION = '__GIT_REVISION__'; +export const REPO_URL = 'https://gitlab.insrt.uk/revolt/revite/-/commit'; diff --git a/vite.config.ts b/vite.config.ts index 372f38d4..dca74704 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,9 +1,24 @@ import { resolve } from 'path' +import { readFileSync } from 'fs' import { defineConfig } from 'vite' import preact from '@preact/preset-vite' import { VitePWA } from 'vite-plugin-pwa' +import replace from '@rollup/plugin-replace' + +function getGitRevision() { + try { + const rev = readFileSync('.git/HEAD').toString().trim(); + if (rev.indexOf(':') === -1) { + return rev; + } else { + return readFileSync('.git/' + rev.substring(5)).toString().trim(); + } + } catch (err) { + console.error('Failed to get Git revision.'); + return '?'; + } +} -// https://vitejs.dev/config/ export default defineConfig({ plugins: [ preact(), @@ -31,6 +46,10 @@ export default defineConfig({ ] }, workbox: { } + }), + replace({ + __GIT_REVISION__: getGitRevision(), + preventAssignment: true }) ], build: { diff --git a/yarn.lock b/yarn.lock index a08e2b04..fbae6d6b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1057,7 +1057,7 @@ is-module "^1.0.0" resolve "^1.19.0" -"@rollup/plugin-replace@^2.4.1": +"@rollup/plugin-replace@^2.4.1", "@rollup/plugin-replace@^2.4.2": version "2.4.2" resolved "https://registry.yarnpkg.com/@rollup/plugin-replace/-/plugin-replace-2.4.2.tgz#a2d539314fbc77c244858faa523012825068510a" integrity sha512-IGcu+cydlUMZ5En85jxHH4qj2hta/11BHq95iHEyb2sbgiN0eCdzvUcHw5gt9pBL5lTi4JDYJ1acCoMGpTvEZg==