summaryrefslogtreecommitdiff
path: root/packages/cli/src/config/env.ts
diff options
context:
space:
mode:
authorJaana Dogan <[email protected]>2025-04-18 11:12:18 -0700
committerGitHub <[email protected]>2025-04-18 11:12:18 -0700
commit3afaa8033bdd9d6af99ff378cafcd84afd76c59e (patch)
treeeecba3f035a7147281dfe4db5ca015108ae9d3dc /packages/cli/src/config/env.ts
parente1fac4025606246e284b3e370d22100e8a25d652 (diff)
Introduce a config module to manage configuration (#22)
* Introduce a config module to manage configuration * Remove public modifier
Diffstat (limited to 'packages/cli/src/config/env.ts')
-rw-r--r--packages/cli/src/config/env.ts48
1 files changed, 0 insertions, 48 deletions
diff --git a/packages/cli/src/config/env.ts b/packages/cli/src/config/env.ts
deleted file mode 100644
index 51fc0a9c..00000000
--- a/packages/cli/src/config/env.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import * as dotenv from 'dotenv';
-import * as fs from 'node:fs';
-import * as path from 'node:path';
-import process from 'node:process';
-
-function findEnvFile(startDir: string): string | null {
- // Start search from the provided directory (e.g., current working directory)
- let currentDir = path.resolve(startDir); // Ensure absolute path
- while (true) {
- const envPath = path.join(currentDir, '.env');
- if (fs.existsSync(envPath)) {
- return envPath;
- }
-
- const parentDir = path.dirname(currentDir);
- if (parentDir === currentDir || !parentDir) {
- return null;
- }
- currentDir = parentDir;
- }
-}
-
-export function loadEnvironment(): void {
- // Start searching from the current working directory by default
- const envFilePath = findEnvFile(process.cwd());
-
- if (envFilePath) {
- dotenv.config({ path: envFilePath });
- }
-
- if (!process.env.GEMINI_API_KEY?.length) {
- console.error(
- 'Error: GEMINI_API_KEY environment variable is not set. Please visit https://ai.google.dev/gemini-api/docs/api-key to set up a new one.',
- );
- process.exit(0);
- }
-}
-
-export function getApiKey(): string {
- loadEnvironment();
- const apiKey = process.env.GEMINI_API_KEY;
- if (!apiKey) {
- throw new Error(
- 'GEMINI_API_KEY environment variable is not set. Please visit https://ai.google.dev/gemini-api/docs/api-key to set up a new one.',
- );
- }
- return apiKey;
-}