-
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
Changes from all commits
5fe35cb
64201fa
b2d9b60
b72e1eb
d01cea7
298b4bb
2c18844
4f61569
8fb2d7b
689de72
f7826b8
ab20341
a16d37f
d003ce3
5baf1da
fe9d6a0
c562319
2826286
63b3c57
48411c8
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,22 @@ | ||
| import { log } from "@clack/prompts"; | ||
| import { theme } from "@/cli/utils/theme.js"; | ||
| import type { UpgradeInfo } from "@/cli/utils/version-check.js"; | ||
| import { checkForUpgrade } from "@/cli/utils/version-check.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"))}`; | ||
| } | ||
|
|
||
| export async function printUpgradeNotificationIfAvailable(): Promise<void> { | ||
| try { | ||
| const upgradeInfo = await checkForUpgrade(); | ||
| if (upgradeInfo) { | ||
| log.message(formatUpgradeMessage(upgradeInfo)); | ||
| } | ||
| } catch { | ||
| // Silently ignore errors | ||
| } | ||
| } | ||
|
Collaborator
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 { getTestOverrides } from "@/core/config.js"; | ||
| import packageJson from "../../../package.json"; | ||
|
|
||
| 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: "test@example.com", 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: "test@example.com", 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: "test@example.com", 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