From cfffbd46a963affe8ae7a0ab38f773d498104ad1 Mon Sep 17 00:00:00 2001 From: hmerritt Date: Sat, 27 Jan 2024 17:33:47 +0000 Subject: [PATCH] feat: print app name and version when running scripts --- bootstrap.cjs | 4 ++++ scripts/bootstrap/core.cjs | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/bootstrap.cjs b/bootstrap.cjs index cff57e6..6d178ed 100644 --- a/bootstrap.cjs +++ b/bootstrap.cjs @@ -37,5 +37,9 @@ async function bootstrap() { const isTest = args.length >= 1 && args[0] === "vitest"; if (isTest) env[0][1] = "test"; + // Log app name and version info + console.log(`${core.versionString(appName, appVersion, gitBranch, gitCommitHashShort)}\n`); + + // Run bootstrap script core.bootstrap(env, allowEnvOverride, args, path); } diff --git a/scripts/bootstrap/core.cjs b/scripts/bootstrap/core.cjs index db832a2..2f53239 100644 --- a/scripts/bootstrap/core.cjs +++ b/scripts/bootstrap/core.cjs @@ -181,6 +181,36 @@ function runStream(command, path = __dirname) { }); } +/** + * Returns version string including app name, version, git branch, and commit hash. + * + * This has been refactored from `/src/lib/global/version.ts`. @TODO make shared function and remove this one. + * + * E.g `App [Version 1.0.0 (development 4122b6...dc7c)]` + */ +const versionString = (appName = undefined, appVersion = undefined, gitBranch = undefined, gitCommitHash = undefined) => { + if (!appVersion) { + return `${appName} [Version unknown]`; + } + + let versionString = `${appName} [Version ${appVersion}`; + + if (gitCommitHash) { + versionString += ` (`; + + // Branch name + versionString += `${gitBranch || "unknown"}/`; + + // Commit hash + versionString += `${gitCommitHash})`; + } + + versionString += `]`; + + return versionString; +}; + + module.exports = { bootstrap, buildENV, @@ -189,5 +219,6 @@ module.exports = { overrideHardcodedENV, run, runStream, - shorten + shorten, + versionString };