Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit e9e54b7

Browse files
cli: add update prompt (#811)
Co-authored-by: Matt Johnson-Pint <mattjohnsonpint@gmail.com>
1 parent 4eb171a commit e9e54b7

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
# Change Log
44

5+
## 2025-04-08 - CLI 0.17.3
6+
7+
- feat: Add update prompt on CLI usage [#811](https://github.com/hypermodeinc/modus/pull/811)
8+
59
## 2025-04-01 - Runtime 0.17.8
610

711
- fix: Update Hypermode api key reading for modus local dev [#805](https://github.com/hypermodeinc/modus/pull/805)

cli/src/baseCommand.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Command, Flags } from "@oclif/core";
2+
import { checkForUpdates } from "./util/updateNotifier.js";
23

34
export abstract class BaseCommand extends Command {
45
static baseFlags = {
@@ -13,4 +14,13 @@ export abstract class BaseCommand extends Command {
1314
hidden: true,
1415
}),
1516
};
17+
18+
async init(): Promise<void> {
19+
await super.init();
20+
21+
const cmd = this.id?.split(" ")[0];
22+
if (cmd !== "version" && !this.argv.includes("--version") && !this.argv.includes("-v")) {
23+
await checkForUpdates(this.config.version);
24+
}
25+
}
1626
}

cli/src/util/updateNotifier.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import chalk from "chalk";
2+
import semver from "semver";
3+
import * as vi from "./versioninfo.js";
4+
import { isOnline } from "./index.js";
5+
6+
/**
7+
* Checks if there's a newer version of the CLI available and prints an update message if needed.
8+
* @param currentVersion Current CLI version
9+
*/
10+
export async function checkForUpdates(currentVersion: string): Promise<void> {
11+
if (!(await isOnline())) {
12+
return;
13+
}
14+
15+
if (currentVersion.startsWith("v")) {
16+
currentVersion = currentVersion.slice(1);
17+
}
18+
19+
const latestVersion = await vi.getLatestCliVersion(false);
20+
if (!latestVersion) return;
21+
22+
const latestVersionNumber = latestVersion.startsWith("v") ? latestVersion.slice(1) : latestVersion;
23+
24+
if (semver.gt(latestVersionNumber, currentVersion)) {
25+
console.log();
26+
console.log(chalk.yellow("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
27+
console.log(chalk.yellow(`Update available! ${chalk.dim(currentVersion)}${chalk.greenBright(latestVersionNumber)}`));
28+
console.log(chalk.yellow("Run ") + chalk.cyanBright("npm update -g @hypermode/modus-cli") + chalk.yellow(" to update."));
29+
console.log(chalk.yellow("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
30+
console.log();
31+
}
32+
}

0 commit comments

Comments
 (0)