mirror of
https://github.com/Dokploy/cli.git
synced 2026-06-15 20:25:22 +02:00
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:
2
.env.example
Normal file
2
.env.example
Normal file
@@ -0,0 +1,2 @@
|
||||
DOKPLOY_URL=""
|
||||
DOKPLOY_API_KEY=""
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -11,5 +11,4 @@ oclif.manifest.json
|
||||
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
|
||||
|
||||
.env
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user