forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-env-example.ts
More file actions
44 lines (36 loc) · 1.16 KB
/
Copy pathgenerate-env-example.ts
File metadata and controls
44 lines (36 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as fs from 'fs';
import * as path from 'path';
import { envSchema } from '../apps/api/src/config/env';
function generateEnvExample(): void {
const schema = envSchema._def.shape();
const lines: string[] = [];
lines.push('# Environment Variables');
lines.push('# Copy this file to .env and fill in your values');
lines.push('');
for (const [key, def] of Object.entries(schema)) {
const description = def.description || '';
const defaultValue = def._def.defaultValue?.();
const isRequired = !def._def.defaultValue;
// Add comment
if (description) {
lines.push(`# ${description}`);
}
if (!isRequired && defaultValue !== undefined) {
lines.push(`# Default: ${defaultValue}`);
}
if (isRequired) {
lines.push('# Required');
}
// Add the variable
if (defaultValue !== undefined) {
lines.push(`${key}=${defaultValue}`);
} else {
lines.push(`${key}=`);
}
lines.push('');
}
const outputPath = path.join(process.cwd(), '.env.example');
fs.writeFileSync(outputPath, lines.join('\n'));
console.log(`✅ Generated .env.example at ${outputPath}`);
}
generateEnvExample();