summaryrefslogtreecommitdiff
path: root/packages/server/src/config/config.ts
diff options
context:
space:
mode:
authorEvan Senter <[email protected]>2025-04-19 19:45:42 +0100
committerGitHub <[email protected]>2025-04-19 19:45:42 +0100
commit3fce6cea27d3e6129d6c06e528b62e1b11bf7094 (patch)
tree244b8e9ab94f902d65d4bda8739a6538e377ed17 /packages/server/src/config/config.ts
parent0c9e1ef61be7db53e6e73b7208b649cd8cbed6c3 (diff)
Starting to modularize into separate cli / server packages. (#55)
* Starting to move a lot of code into packages/server * More of the massive refactor, builds and runs, some issues though. * Fixing outstanding issue with double messages. * Fixing a minor UI issue. * Fixing the build post-merge. * Running formatting. * Addressing comments.
Diffstat (limited to 'packages/server/src/config/config.ts')
-rw-r--r--packages/server/src/config/config.ts65
1 files changed, 65 insertions, 0 deletions
diff --git a/packages/server/src/config/config.ts b/packages/server/src/config/config.ts
new file mode 100644
index 00000000..86cd7a6c
--- /dev/null
+++ b/packages/server/src/config/config.ts
@@ -0,0 +1,65 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import * as dotenv from 'dotenv';
+import * as fs from 'node:fs';
+import * as path from 'node:path';
+import process from 'node:process';
+
+export class Config {
+ private apiKey: string;
+ private model: string;
+ private targetDir: string;
+
+ constructor(apiKey: string, model: string, targetDir: string) {
+ this.apiKey = apiKey;
+ this.model = model;
+ this.targetDir = targetDir;
+ }
+
+ getApiKey(): string {
+ return this.apiKey;
+ }
+
+ getModel(): string {
+ return this.model;
+ }
+
+ getTargetDir(): string {
+ return this.targetDir;
+ }
+}
+
+function findEnvFile(startDir: string): string | null {
+ let currentDir = path.resolve(startDir);
+ 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 {
+ const envFilePath = findEnvFile(process.cwd());
+ if (!envFilePath) {
+ return;
+ }
+ dotenv.config({ path: envFilePath });
+}
+
+export function createServerConfig(
+ apiKey: string,
+ model: string,
+ targetDir: string,
+): Config {
+ return new Config(apiKey, model, path.resolve(targetDir));
+}