diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..1ec2f2a --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +DOKPLOY_URL="" +DOKPLOY_API_KEY="" diff --git a/.gitignore b/.gitignore index 57a8bbf..3d9fde0 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,4 @@ oclif.manifest.json yarn.lock package-lock.json - - +.env diff --git a/src/client.ts b/src/client.ts index 509c955..dc31d14 100644 --- a/src/client.ts +++ b/src/client.ts @@ -13,7 +13,27 @@ export interface AuthConfig { url: string; } +function loadEnvFile(): void { + const envPath = path.resolve(process.cwd(), ".env"); + if (!fs.existsSync(envPath)) return; + + const content = fs.readFileSync(envPath, "utf8"); + for (const line of content.split("\n")) { + const trimmed = line.trim(); + if (!trimmed || trimmed.startsWith("#")) continue; + const eqIndex = trimmed.indexOf("="); + if (eqIndex === -1) continue; + const key = trimmed.slice(0, eqIndex).trim(); + const value = trimmed.slice(eqIndex + 1).trim().replace(/^["']|["']$/g, ""); + if (!process.env[key]) { + process.env[key] = value; + } + } +} + export function readAuthConfig(): AuthConfig { + loadEnvFile(); + const envToken = process.env.DOKPLOY_API_KEY ?? process.env.DOKPLOY_AUTH_TOKEN; const envUrl = process.env.DOKPLOY_URL;