From 56fb554f132a53d74b2e9a1a02cc973c5420e73c Mon Sep 17 00:00:00 2001 From: "Max P." Date: Wed, 21 May 2025 03:47:02 +0200 Subject: [PATCH] feat(utils): add version retrieval utility - Introduces a function to retrieve the application version - Returns 'dev' if the version file is missing and 'unknown' for other errors - Exports the new utility for use in other modules --- src/utils/mod.ts | 1 + src/utils/version.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/utils/version.ts diff --git a/src/utils/mod.ts b/src/utils/mod.ts index bb933cd..c68b31f 100644 --- a/src/utils/mod.ts +++ b/src/utils/mod.ts @@ -1,2 +1,3 @@ export { resolveUnitTargetPath, writeUnitFiles } from './fs.ts'; export { deriveNameFromExec } from './misc.ts'; +export { getVersion } from './version.ts'; diff --git a/src/utils/version.ts b/src/utils/version.ts new file mode 100644 index 0000000..3d78737 --- /dev/null +++ b/src/utils/version.ts @@ -0,0 +1,12 @@ +export async function getVersion(): Promise { + try { + const versionUrl = new URL('../../VERSION', import.meta.url); + const version = await Deno.readTextFile(versionUrl); + return version.trim(); + } catch (err) { + if (err instanceof Deno.errors.NotFound) { + return 'dev'; + } + return 'unknown'; + } +}