-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate-env.js
More file actions
53 lines (45 loc) · 1.81 KB
/
generate-env.js
File metadata and controls
53 lines (45 loc) · 1.81 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
45
46
47
48
49
50
51
52
53
const fs = require('fs');
const path = require('path');
// Load .env file for local dev (dotenv-style, manual parse to avoid extra dependencies)
function loadEnvFile(filePath) {
if (!fs.existsSync(filePath)) return;
const lines = fs.readFileSync(filePath, 'utf8').split('\n');
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#')) continue;
const eqIdx = trimmed.indexOf('=');
if (eqIdx === -1) continue;
const key = trimmed.slice(0, eqIdx).trim();
const value = trimmed.slice(eqIdx + 1).trim().replace(/^["']|["']$/g, '');
if (!(key in process.env)) process.env[key] = value;
}
}
loadEnvFile(path.join(__dirname, '.env'));
const supabaseUrl = process.env.SUPABASE_URL || '';
const supabaseAnonKey = process.env.SUPABASE_ANON_KEY || '';
if (!supabaseUrl || !supabaseAnonKey) {
console.warn('[generate-env] WARNING: SUPABASE_URL or SUPABASE_ANON_KEY is not set. Environment files will have empty values.');
}
const prodEnvContent = `
export const environment = {
production: true,
supabase: {
url: '${supabaseUrl}', // SAFE to expose — anon key with RLS enforced
key: '${supabaseAnonKey}' // SAFE to expose — anon key with RLS enforced
},
};
`;
const devEnvContent = `
// ⚠️ This file is gitignored and must NEVER be committed.
// Generated by generate-env.js — run: node generate-env.js
export const environment = {
production: false,
supabase: {
url: '${supabaseUrl}', // SAFE to expose — anon key with RLS enforced
key: '${supabaseAnonKey}' // SAFE to expose — anon key with RLS enforced
},
};
`;
fs.writeFileSync('src/environments/environment.prod.ts', prodEnvContent);
fs.writeFileSync('src/environments/environment.ts', devEnvContent);
console.log('[generate-env] environment.ts and environment.prod.ts written.');