Skip to content

Commit c4c7de2

Browse files
committed
chore(cli): addressed feedback
1 parent efee7c0 commit c4c7de2

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

genkit-tools/cli/src/utils/updates.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { detectCLIRuntime } from '../utils/runtime-detector';
2525
import { version as currentVersion, name } from '../utils/version';
2626

2727
const GCS_BUCKET_URL = 'https://storage.googleapis.com/genkit-assets-cli';
28+
const CLI_DOCS_URL = 'https://genkit.dev/docs/devtools/';
2829
const AXIOS_INSTANCE: AxiosInstance = axios.create({
2930
timeout: 3000,
3031
});
@@ -79,7 +80,7 @@ interface NpmRegistryResponse {
7980
latest: string;
8081
[key: string]: string;
8182
};
82-
versions: Record<string, any>;
83+
versions: Record<string, unknown>;
8384
}
8485

8586
/**
@@ -138,21 +139,21 @@ export async function getLatestVersionFromNpm(
138139
// Sort by semver descending (newest first)
139140
versions.sort(semver.rcompare);
140141
return versions[0];
141-
} catch (error: any) {
142+
} catch (error: unknown) {
142143
if (error instanceof GenkitToolsError) {
143144
throw error;
144145
}
145146

146147
throw new GenkitToolsError(
147-
`Failed to fetch npm versions: ${error?.message ?? error}`
148+
`Failed to fetch npm versions: ${(error as Error)?.message ?? String(error)}`
148149
);
149150
}
150151
}
151152

152153
/**
153154
* Checks if update notifications are disabled via environment variable or user config.
154155
*/
155-
function areUpdateNotificationsDisabled(): boolean {
156+
function isUpdateNotificationsDisabled(): boolean {
156157
if (process.env.GENKIT_CLI_DISABLE_UPDATE_NOTIFICATIONS === 'true') {
157158
return true;
158159
}
@@ -163,10 +164,7 @@ function areUpdateNotificationsDisabled(): boolean {
163164
/**
164165
* Gets the latest version and update message for compiled binary installations.
165166
*/
166-
async function getBinaryUpdateInfo(): Promise<{
167-
latestVersion: string;
168-
updateMessage: string;
169-
} | null> {
167+
async function getBinaryUpdateInfo(): Promise<string | null> {
170168
const gcsLatestData = await getGCSLatestData();
171169
const machine = `${platform}-${arch}`;
172170
const platformData = gcsLatestData.platforms[machine];
@@ -177,26 +175,19 @@ async function getBinaryUpdateInfo(): Promise<{
177175
}
178176

179177
const latestVersion = normalizeVersion(gcsLatestData.latestVersion);
180-
const fileName = platformData.versionedUrl.split('/').pop() || '';
181-
const downloadUrl = `${GCS_BUCKET_URL}/prod/${machine}/v${latestVersion}/${fileName}`;
182-
const updateMessage = `${clc.dim('Run')} ${clc.bold(`curl -Lo ./genkit_bin ${downloadUrl}`)} ${clc.dim('to upgrade')}`;
183-
return { latestVersion, updateMessage };
178+
return latestVersion;
184179
}
185180

186181
/**
187182
* Gets the latest version and update message for npm installations.
188183
*/
189-
async function getNpmUpdateInfo(): Promise<{
190-
latestVersion: string;
191-
updateMessage: string;
192-
} | null> {
184+
async function getNpmUpdateInfo(): Promise<string | null> {
193185
const latestVersion = await getLatestVersionFromNpm();
194186
if (!latestVersion) {
195187
logger.debug('No available versions found from npm.');
196188
return null;
197189
}
198-
const updateMessage = `${clc.dim('Update')} ${clc.bold('genkit-cli')} ${clc.dim('using your preferred package manager (npm, pnpm, yarn, etc.)')}`;
199-
return { latestVersion, updateMessage };
190+
return latestVersion;
200191
}
201192

202193
/**
@@ -206,7 +197,7 @@ async function getNpmUpdateInfo(): Promise<{
206197
*/
207198
export async function showUpdateNotification(): Promise<void> {
208199
try {
209-
if (areUpdateNotificationsDisabled()) {
200+
if (isUpdateNotificationsDisabled()) {
210201
return;
211202
}
212203

@@ -219,7 +210,7 @@ export async function showUpdateNotification(): Promise<void> {
219210
return;
220211
}
221212

222-
const { latestVersion, updateMessage } = updateInfo;
213+
const latestVersion = updateInfo;
223214
const current = normalizeVersion(currentVersion);
224215

225216
if (!semver.valid(latestVersion) || !semver.valid(current)) {
@@ -233,12 +224,20 @@ export async function showUpdateNotification(): Promise<void> {
233224
return;
234225
}
235226

236-
logger.info(
237-
`\n${clc.yellow('📦 Update available:')} ${clc.bold(`v${current}`)}${clc.bold(clc.green(`v${latestVersion}`))}\n` +
238-
updateMessage +
239-
'\n' +
240-
`${clc.dim('Run')} ${clc.bold('genkit config set updateNotificationsOptOut true')} ${clc.dim('to disable these notifications')}\n`
241-
);
227+
// Determine install method and update command for message
228+
const installMethod = isCompiledBinary ? "installer script" : "your package manager";
229+
const updateCommand = isCompiledBinary
230+
? "curl -sL cli.genkit.dev | uninstall=true bash"
231+
: "npm install -g genkit-cli";
232+
233+
const updateNotificationMessage =
234+
`Update available ${clc.gray(`v${current}`)}${clc.green(`v${latestVersion}`)}\n` +
235+
`To update to the latest version using ${installMethod}, run\n${clc.cyan(updateCommand)}\n` +
236+
`For other CLI management options, visit ${CLI_DOCS_URL}\n` +
237+
`${clc.dim('Run')} ${clc.bold('genkit config set updateNotificationsOptOut true')} ${clc.dim('to disable these notifications')}\n`;
238+
239+
logger.info(`\n${updateNotificationMessage}`);
240+
242241
} catch (e) {
243242
// Silently fail - update notifications shouldn't break the CLI
244243
logger.debug('Failed to show update notification', e);

0 commit comments

Comments
 (0)