Skip to content

Commit 4d604a1

Browse files
committed
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.
1 parent 70f5429 commit 4d604a1

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DOKPLOY_URL=""
2+
DOKPLOY_API_KEY=""

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ oclif.manifest.json
1111

1212
yarn.lock
1313
package-lock.json
14-
15-
14+
.env

src/client.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,27 @@ export interface AuthConfig {
1313
url: string;
1414
}
1515

16+
function loadEnvFile(): void {
17+
const envPath = path.resolve(process.cwd(), ".env");
18+
if (!fs.existsSync(envPath)) return;
19+
20+
const content = fs.readFileSync(envPath, "utf8");
21+
for (const line of content.split("\n")) {
22+
const trimmed = line.trim();
23+
if (!trimmed || trimmed.startsWith("#")) continue;
24+
const eqIndex = trimmed.indexOf("=");
25+
if (eqIndex === -1) continue;
26+
const key = trimmed.slice(0, eqIndex).trim();
27+
const value = trimmed.slice(eqIndex + 1).trim().replace(/^["']|["']$/g, "");
28+
if (!process.env[key]) {
29+
process.env[key] = value;
30+
}
31+
}
32+
}
33+
1634
export function readAuthConfig(): AuthConfig {
35+
loadEnvFile();
36+
1737
const envToken =
1838
process.env.DOKPLOY_API_KEY ?? process.env.DOKPLOY_AUTH_TOKEN;
1939
const envUrl = process.env.DOKPLOY_URL;

0 commit comments

Comments
 (0)