diff --git a/src/content-cli.ts b/src/content-cli.ts index 3bf4cd41..89527c16 100644 --- a/src/content-cli.ts +++ b/src/content-cli.ts @@ -22,24 +22,27 @@ if (!semverSatisfies(process.version, requiredVersion)) { process.exit(1); } -// Global configuration options -const program: Command = new Command(); -program.version(VersionUtils.getCurrentCliVersion()); -program.option("-q, --quietmode", "Reduce output to a minimum", false); -program.option("-p, --profile [profile]"); -program.option("--debug", "Print debug messages", false); -program.option("--dev", "Development Mode", false); -program.parseOptions(process.argv); +async function configureGlobalConfigurationOptions(): Promise { + const program: Command = new Command(); + const currentCliVersion = await VersionUtils.getCurrentCliVersion(); + program.version(currentCliVersion); + program.option("-q, --quietmode", "Reduce output to a minimum", false); + program.option("-p, --profile [profile]"); + program.option("--debug", "Print debug messages", false); + program.option("--dev", "Development Mode", false); + program.parseOptions(process.argv); -if (!program.opts().quietmode) { - console.log(`Content CLI - (C) Copyright 2025 - Celonis SE - Version ${VersionUtils.getCurrentCliVersion()}`); - console.log(); -} + if (!program.opts().quietmode) { + console.log(`Content CLI - (C) Copyright 2025 - Celonis SE - Version ${currentCliVersion}`); + console.log(); + } -if (program.opts().debug) { - logger.transports.forEach(t => { - t.level = "debug"; - }); + if (program.opts().debug) { + logger.transports.forEach(t => { + t.level = "debug"; + }); + } + return program; } /** @@ -53,6 +56,7 @@ function configureRootCommands(configurator: Configurator): void { } async function run(): Promise { + const program = await configureGlobalConfigurationOptions(); const context = new Context(program.opts()); await context.init(); diff --git a/src/core/utils/version.ts b/src/core/utils/version.ts index 78343fc5..7f3c3583 100644 --- a/src/core/utils/version.ts +++ b/src/core/utils/version.ts @@ -1,8 +1,14 @@ -// tslint:disable-next-line:no-var-requires -const { version } = require("../../../package.json"); +import * as fs from "fs"; +import * as findUp from "find-up"; export class VersionUtils { - public static getCurrentCliVersion(): string { - return version; + public static async getCurrentCliVersion(): Promise { + const packageJsonPath = await findUp("package.json"); + if (!packageJsonPath) { + throw new Error("Could not find package.json"); + } + + const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")); + return pkg.version; } }