mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-11 06:31:01 -07:00
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import updateNotifier, { UpdateInfo } from 'update-notifier';
|
|
import semver from 'semver';
|
|
import { getPackageJson } from '../../utils/package.js';
|
|
|
|
export interface UpdateObject {
|
|
message: string;
|
|
update: UpdateInfo;
|
|
}
|
|
|
|
export async function checkForUpdates(): Promise<UpdateObject | null> {
|
|
try {
|
|
// Skip update check when running from source (development mode)
|
|
if (process.env.DEV === 'true') {
|
|
return null;
|
|
}
|
|
|
|
const packageJson = await getPackageJson();
|
|
if (!packageJson || !packageJson.name || !packageJson.version) {
|
|
return null;
|
|
}
|
|
const notifier = updateNotifier({
|
|
pkg: {
|
|
name: packageJson.name,
|
|
version: packageJson.version,
|
|
},
|
|
// check every time
|
|
updateCheckInterval: 0,
|
|
// allow notifier to run in scripts
|
|
shouldNotifyInNpmScript: true,
|
|
});
|
|
|
|
const updateInfo = await notifier.fetchInfo();
|
|
|
|
if (updateInfo && semver.gt(updateInfo.latest, updateInfo.current)) {
|
|
return {
|
|
message: `Gemini CLI update available! ${updateInfo.current} → ${updateInfo.latest}`,
|
|
update: updateInfo,
|
|
};
|
|
}
|
|
|
|
return null;
|
|
} catch (e) {
|
|
console.warn('Failed to check for updates: ' + e);
|
|
return null;
|
|
}
|
|
}
|