Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# Change Log

## 2025-04-08 - CLI 0.17.3

- 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)
Expand Down
10 changes: 10 additions & 0 deletions cli/src/baseCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command, Flags } from "@oclif/core";
import { checkForUpdates } from "./util/updateNotifier.js";

export abstract class BaseCommand extends Command {
static baseFlags = {
Expand All @@ -13,4 +14,13 @@ export abstract class BaseCommand extends Command {
hidden: true,
}),
};

async init(): Promise<void> {
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);
}
}
}
32 changes: 32 additions & 0 deletions cli/src/util/updateNotifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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<void> {
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("Run ") + chalk.cyanBright("npm update -g @hypermode/modus-cli") + chalk.yellow(" to update."));
console.log(chalk.yellow("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
console.log();
}
}