mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-23 19:44:30 -07:00
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
|
|
/**
|
||
|
|
* @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';
|
||
|
|
import { Storage } from '@google/gemini-cli-core';
|
||
|
|
|
||
|
|
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 {
|
||
|
|
return new Storage(os.homedir()).getExtensionsDir();
|
||
|
|
}
|
||
|
|
|
||
|
|
static async createTmpDir(): Promise<string> {
|
||
|
|
return await fs.promises.mkdtemp(
|
||
|
|
path.join(os.tmpdir(), 'gemini-extension'),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|