2025-10-23 11:39:36 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import * as path from 'node:path';
|
|
|
|
|
import * as fs from 'node:fs';
|
|
|
|
|
import * as os from 'node:os';
|
|
|
|
|
import {
|
|
|
|
|
EXTENSION_SETTINGS_FILENAME,
|
|
|
|
|
EXTENSIONS_CONFIG_FILENAME,
|
|
|
|
|
} from './variables.js';
|
2026-01-06 20:09:39 -08:00
|
|
|
import { Storage, homedir } from '@google/gemini-cli-core';
|
2025-10-23 11:39:36 -07:00
|
|
|
|
|
|
|
|
export class ExtensionStorage {
|
|
|
|
|
private readonly extensionName: string;
|
|
|
|
|
|
|
|
|
|
constructor(extensionName: string) {
|
|
|
|
|
this.extensionName = extensionName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getExtensionDir(): string {
|
|
|
|
|
return path.join(
|
|
|
|
|
ExtensionStorage.getUserExtensionsDir(),
|
|
|
|
|
this.extensionName,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getConfigPath(): string {
|
|
|
|
|
return path.join(this.getExtensionDir(), EXTENSIONS_CONFIG_FILENAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getEnvFilePath(): string {
|
|
|
|
|
return path.join(this.getExtensionDir(), EXTENSION_SETTINGS_FILENAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getUserExtensionsDir(): string {
|
2026-01-06 20:09:39 -08:00
|
|
|
return new Storage(homedir()).getExtensionsDir();
|
2025-10-23 11:39:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async createTmpDir(): Promise<string> {
|
2025-12-02 07:11:40 +09:00
|
|
|
return fs.promises.mkdtemp(path.join(os.tmpdir(), 'gemini-extension'));
|
2025-10-23 11:39:36 -07:00
|
|
|
}
|
|
|
|
|
}
|