From 27f4b2b2fdad45bc363c42510f51f5a4af65f32a Mon Sep 17 00:00:00 2001 From: danstarns Date: Mon, 7 Apr 2025 08:42:38 +0700 Subject: [PATCH 1/4] cli: add update prompt --- cli/src/baseCommand.ts | 10 ++++++++++ cli/src/util/updateNotifier.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 cli/src/util/updateNotifier.ts diff --git a/cli/src/baseCommand.ts b/cli/src/baseCommand.ts index 984243502..bc3d8d54d 100644 --- a/cli/src/baseCommand.ts +++ b/cli/src/baseCommand.ts @@ -1,4 +1,5 @@ import { Command, Flags } from "@oclif/core"; +import { checkForUpdates } from "./util/updateNotifier.js"; export abstract class BaseCommand extends Command { static baseFlags = { @@ -13,4 +14,13 @@ export abstract class BaseCommand extends Command { hidden: true, }), }; + + async init(): Promise { + await super.init(); + + const cmd = this.id?.split(" ")[0]; + if (cmd !== "version" && !this.argv.includes("--version") && !this.argv.includes("-v")) { + await checkForUpdates(this.config.version); + } + } } diff --git a/cli/src/util/updateNotifier.ts b/cli/src/util/updateNotifier.ts new file mode 100644 index 000000000..dc29cc4ef --- /dev/null +++ b/cli/src/util/updateNotifier.ts @@ -0,0 +1,31 @@ +import chalk from "chalk"; +import semver from "semver"; +import * as vi from "./versioninfo.js"; +import { isOnline } from "./index.js"; + +/** + * Checks if there's a newer version of the CLI available and prints an update message if needed. + * @param currentVersion Current CLI version + */ +export async function checkForUpdates(currentVersion: string): Promise { + if (!(await isOnline())) { + return; + } + + if (currentVersion.startsWith("v")) { + currentVersion = currentVersion.slice(1); + } + + const latestVersion = await vi.getLatestCliVersion(false); + if (!latestVersion) return; + + const latestVersionNumber = latestVersion.startsWith("v") ? latestVersion.slice(1) : latestVersion; + + if (semver.gt(latestVersionNumber, currentVersion)) { + console.log(); + console.log(chalk.yellow("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")); + console.log(chalk.yellow(`Update available! ${chalk.dim(currentVersion)} → ${chalk.greenBright(latestVersionNumber)}`)); + console.log(chalk.yellow("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")); + console.log(); + } +} From 282d7845dce0971f98d0179015a1841cf3f43aba Mon Sep 17 00:00:00 2001 From: danstarns Date: Tue, 8 Apr 2025 19:32:29 +0700 Subject: [PATCH 2/4] add update command in notify --- cli/src/util/updateNotifier.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/src/util/updateNotifier.ts b/cli/src/util/updateNotifier.ts index dc29cc4ef..475cdf173 100644 --- a/cli/src/util/updateNotifier.ts +++ b/cli/src/util/updateNotifier.ts @@ -25,6 +25,7 @@ export async function checkForUpdates(currentVersion: string): Promise { console.log(); console.log(chalk.yellow("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")); console.log(chalk.yellow(`Update available! ${chalk.dim(currentVersion)} → ${chalk.greenBright(latestVersionNumber)}`)); + console.log(chalk.yellow("Run ") + chalk.cyanBright("npm update -g @hypermode/modus-cli") + chalk.yellow(" to update.")); console.log(chalk.yellow("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")); console.log(); } From ffdf4bc1c172dded5ced91c35c52e8b2b0b1395b Mon Sep 17 00:00:00 2001 From: danstarns Date: Tue, 8 Apr 2025 19:34:34 +0700 Subject: [PATCH 3/4] docs: add changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 181a558a7..35f176505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ # Change Log +## 2025-04-08 - Runtime 0.17.8 + +- feat: Add update prompt on CLI usage [#811](https://github.com/hypermodeinc/modus/pull/811) + ## 2025-04-01 - Runtime 0.17.8 - fix: Update Hypermode api key reading for modus local dev [#805](https://github.com/hypermodeinc/modus/pull/805) From c69af74d0be583e53c091fe66d21eca952b62a95 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Tue, 8 Apr 2025 11:31:58 -0700 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35f176505..4234f7b22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ # Change Log -## 2025-04-08 - Runtime 0.17.8 +## 2025-04-08 - CLI 0.17.3 - feat: Add update prompt on CLI usage [#811](https://github.com/hypermodeinc/modus/pull/811)