mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-27 21:44:25 -07:00
Add flag to update all extensions (#7321)
This commit is contained in:
@@ -44,6 +44,7 @@ export interface ExtensionInstallMetadata {
|
||||
}
|
||||
|
||||
export interface ExtensionUpdateInfo {
|
||||
name: string;
|
||||
originalVersion: string;
|
||||
updatedVersion: string;
|
||||
}
|
||||
@@ -444,10 +445,10 @@ export function toOutputString(extension: Extension): string {
|
||||
return output;
|
||||
}
|
||||
|
||||
export async function updateExtension(
|
||||
export async function updateExtensionByName(
|
||||
extensionName: string,
|
||||
cwd: string = process.cwd(),
|
||||
): Promise<ExtensionUpdateInfo | undefined> {
|
||||
): Promise<ExtensionUpdateInfo> {
|
||||
const installedExtensions = loadUserExtensions();
|
||||
const extension = installedExtensions.find(
|
||||
(installed) => installed.config.name === extensionName,
|
||||
@@ -457,16 +458,21 @@ export async function updateExtension(
|
||||
`Extension "${extensionName}" not found. Run gemini extensions list to see available extensions.`,
|
||||
);
|
||||
}
|
||||
return await updateExtension(extension, cwd);
|
||||
}
|
||||
|
||||
export async function updateExtension(
|
||||
extension: Extension,
|
||||
cwd: string = process.cwd(),
|
||||
): Promise<ExtensionUpdateInfo> {
|
||||
if (!extension.installMetadata) {
|
||||
throw new Error(
|
||||
`Extension cannot be updated because it is missing the .gemini-extension.install.json file. To update manually, uninstall and then reinstall the updated version.`,
|
||||
);
|
||||
throw new Error(`Extension ${extension.config.name} cannot be updated.`);
|
||||
}
|
||||
const originalVersion = extension.config.version;
|
||||
const tempDir = await ExtensionStorage.createTmpDir();
|
||||
try {
|
||||
await copyExtension(extension.path, tempDir);
|
||||
await uninstallExtension(extensionName, cwd);
|
||||
await uninstallExtension(extension.config.name, cwd);
|
||||
await installExtension(extension.installMetadata, cwd);
|
||||
|
||||
const updatedExtension = loadExtension(extension.path);
|
||||
@@ -475,6 +481,7 @@ export async function updateExtension(
|
||||
}
|
||||
const updatedVersion = updatedExtension.config.version;
|
||||
return {
|
||||
name: extension.config.name,
|
||||
originalVersion,
|
||||
updatedVersion,
|
||||
};
|
||||
@@ -537,3 +544,14 @@ function removeFromDisabledExtensions(
|
||||
settings.setValue(scope, 'extensions', extensionSettings);
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateAllUpdatableExtensions(
|
||||
cwd: string = process.cwd(),
|
||||
): Promise<ExtensionUpdateInfo[]> {
|
||||
const extensions = loadExtensions(cwd).filter(
|
||||
(extension) => !!extension.installMetadata,
|
||||
);
|
||||
return await Promise.all(
|
||||
extensions.map((extension) => updateExtension(extension, cwd)),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user