feat: add environment configuration support

- Introduced .env.example file to provide a template for environment variables.
- Updated .gitignore to exclude .env files from version control.
- Implemented loadEnvFile function in client.ts to load environment variables from a .env file into process.env, enhancing configuration management.
This commit is contained in:
Mauricio Siu
2026-04-15 18:42:13 -06:00
parent 70f542990d
commit 4d604a1a75
3 changed files with 23 additions and 2 deletions

2
.env.example Normal file
View File

@@ -0,0 +1,2 @@
DOKPLOY_URL=""
DOKPLOY_API_KEY=""

3
.gitignore vendored
View File

@@ -11,5 +11,4 @@ oclif.manifest.json
yarn.lock yarn.lock
package-lock.json package-lock.json
.env

View File

@@ -13,7 +13,27 @@ export interface AuthConfig {
url: string; 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 { export function readAuthConfig(): AuthConfig {
loadEnvFile();
const envToken = const envToken =
process.env.DOKPLOY_API_KEY ?? process.env.DOKPLOY_AUTH_TOKEN; process.env.DOKPLOY_API_KEY ?? process.env.DOKPLOY_AUTH_TOKEN;
const envUrl = process.env.DOKPLOY_URL; const envUrl = process.env.DOKPLOY_URL;