-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add upgrade notification when newer CLI version is available #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ea28425
49a22bb
16eb79f
95bc93d
e1b4f96
e58f957
9b9da8d
fe39b9d
4ff5804
d7fd7fa
f24f127
f903c19
4984b96
76f0980
f7a4a7d
0029e0e
c3228b3
0fca9ec
dc0da09
62049c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { log } from "@clack/prompts"; | ||
| import type { UpgradeInfo } from "@/cli/utils/version-check.js"; | ||
| import { checkForUpgrade } from "@/cli/utils/version-check.js"; | ||
| import { theme } from "@/cli/utils/theme.js"; | ||
|
|
||
| function formatUpgradeMessage(info: UpgradeInfo): string { | ||
| const { shinyOrange } = theme.colors; | ||
| const { bold } = theme.styles; | ||
|
|
||
| return `${shinyOrange("Update available!")} ${shinyOrange(`${info.currentVersion} β ${info.latestVersion}`)} ${shinyOrange("Run:")} ${bold(shinyOrange("npm update -g base44"))}`; | ||
| } | ||
|
|
||
| /** | ||
| * Checks for available upgrades and prints a notification if one exists. | ||
| */ | ||
| export async function printUpgradeNotificationIfAvailable(): Promise<void> { | ||
| try { | ||
| const upgradeInfo = await checkForUpgrade(); | ||
| if (upgradeInfo) { | ||
| log.message(formatUpgradeMessage(upgradeInfo)); | ||
| } | ||
| } catch { | ||
| // Silently ignore errors | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @claude this whole file should be inside the src/cli folder because it's not related to the core/ of the product There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude finished @kfirstri's task in 1m 34s ββ View job Completed
Moved --- | Branch |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { execa } from "execa"; | ||
| import packageJson from "../../../package.json"; | ||
| import { getTestOverrides } from "@/core/config.js"; | ||
|
|
||
| export interface UpgradeInfo { | ||
| currentVersion: string; | ||
| latestVersion: string; | ||
| } | ||
|
|
||
| export async function checkForUpgrade(): Promise<UpgradeInfo | null> { | ||
| const testLatestVersion = getTestOverrides()?.latestVersion; | ||
| if (testLatestVersion !== undefined) { | ||
| if (testLatestVersion === null) { | ||
| return null; | ||
| } | ||
| const currentVersion = packageJson.version; | ||
| if (testLatestVersion !== currentVersion) { | ||
| return { currentVersion, latestVersion: testLatestVersion }; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| try { | ||
| const { stdout } = await execa("npm", ["view", "base44", "version"], { | ||
| timeout: 500, | ||
| shell: true, | ||
| env: { CI: "1" }, | ||
| }); | ||
| const latestVersion = stdout.trim(); | ||
| const currentVersion = packageJson.version; | ||
|
|
||
| if (latestVersion !== currentVersion) { | ||
| return { currentVersion, latestVersion }; | ||
| } | ||
| return null; | ||
| } catch { | ||
| return null; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { describe, it } from "vitest"; | ||
| import { setupCLITests } from "./testkit/index.js"; | ||
|
|
||
| describe("upgrade notification", () => { | ||
| const t = setupCLITests(); | ||
|
|
||
| it("displays upgrade notification when newer version is available", async () => { | ||
| t.givenLatestVersion("1.0.0"); | ||
| await t.givenLoggedIn({ email: "[email protected]", name: "Test User" }); | ||
|
|
||
| const result = await t.run("whoami"); | ||
|
|
||
| t.expectResult(result).toSucceed(); | ||
| t.expectResult(result).toContain("Update available!"); | ||
| t.expectResult(result).toContain("1.0.0"); | ||
| t.expectResult(result).toContain("npm update -g base44"); | ||
| }); | ||
|
|
||
| it("does not display notification when version is current", async () => { | ||
| t.givenLatestVersion(null); | ||
| await t.givenLoggedIn({ email: "[email protected]", name: "Test User" }); | ||
|
|
||
| const result = await t.run("whoami"); | ||
|
|
||
| t.expectResult(result).toSucceed(); | ||
| t.expectResult(result).toNotContain("Update available!"); | ||
| }); | ||
|
|
||
| it("does not display notification when check is not overridden", async () => { | ||
| await t.givenLoggedIn({ email: "[email protected]", name: "Test User" }); | ||
|
|
||
| const result = await t.run("whoami"); | ||
|
|
||
| t.expectResult(result).toSucceed(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@claude i see were using log.message, and the
printUpgradeNotificationIfAvailableis called inrunCommandbut after we already dooutromeaning it will be a weird hevaior, maybe we can do it at the begining?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude finished @kfirstri's task in 47s ββ View job
Completed
Moved the upgrade notification to display right after the intro/banner, before the main command logic runs. This prevents the notification from appearing after the
outro, which would have created strange behavior where messages appear after the command completion message.The notification now appears at the beginning of the command flow, making it more visible and avoiding any confusion with the outro message.
| Branch