Skip to content

Commit d967a7a

Browse files
committed
feat: enhance environment loading by adding dynamic file selection and logging
1 parent 4e7beee commit d967a7a

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/loadEnvFile.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { join } from 'node:path';
44
// Simple .env loader without external dependencies
55
function loadEnvFile(filePath: string) {
66
if (!existsSync(filePath)) {
7+
console.warn(`Warning: File ${filePath} not found`);
78
return;
89
}
910

@@ -24,12 +25,22 @@ function loadEnvFile(filePath: string) {
2425
}
2526
}
2627
}
28+
console.log(`✅ Loaded: ${filePath}`);
2729
} catch (error) {
2830
console.warn(`Warning: Could not load ${filePath}`);
29-
console.warn('Make sure a valid .env.local file exists.');
3031
console.warn(error);
3132
}
3233
}
3334

34-
// Load local environment file if it exists
35-
loadEnvFile(join(process.cwd(), '.env.local'));
35+
// Determine environment (defaults to development)
36+
const nodeEnv = process.env.NODE_ENV || 'development';
37+
console.log(`🌍 Environment: ${nodeEnv}`);
38+
39+
// Load environment-specific config first (public values)
40+
const envFile = join(process.cwd(), `.env.${nodeEnv}`);
41+
loadEnvFile(envFile);
42+
43+
// Load local overrides and secrets second (overrides public config)
44+
// Required in both dev and prod for DISCORD_TOKEN
45+
const localEnvFile = join(process.cwd(), '.env.local');
46+
loadEnvFile(localEnvFile);

0 commit comments

Comments
 (0)