-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset-env.js
More file actions
48 lines (40 loc) · 1.38 KB
/
set-env.js
File metadata and controls
48 lines (40 loc) · 1.38 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
const path = require('path');
const fs = require('fs');
const { execSync } = require('child_process');
const dotenv = require('dotenv');
dotenv.config({ path: path.resolve(__dirname, './.env') });
const envFilePath = path.resolve(__dirname, './src/environment.ts');
const envDir = path.dirname(envFilePath);
if (!fs.existsSync(envDir)) {
fs.mkdirSync(envDir, { recursive: true });
}
let branch = 'unknown';
try {
branch = execSync('git rev-parse --abbrev-ref HEAD', { stdio: 'pipe', shell: true })
.toString()
.trim();
} catch (err) {
console.warn('Could not detect Git branch, defaulting to "unknown"');
}
const isProduction = branch === 'main';
const apiUrl = process.env.API_URL || '';
const output = `export const environment = {
production: ${isProduction},
api: "${apiUrl}",
firebase: {
apiKey: "${process.env.FIREBASE_API_KEY}",
authDomain: "${process.env.FIREBASE_AUTH_DOMAIN}",
projectId: "${process.env.FIREBASE_PROJECT_ID}",
storageBucket: "${process.env.FIREBASE_STORAGE_BUCKET}",
messagingSenderId: "${process.env.FIREBASE_MESSAGING_SENDER_ID}",
appId: "${process.env.FIREBASE_APP_ID}",
measurementId: "${process.env.FIREBASE_MEASUREMENT_ID}"
}
};`;
console.log(
`===============================
apiUrl: ${apiUrl},
================================`
);
fs.writeFileSync(envFilePath, output);
console.log('File environment.ts created successfully!');