-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathpull-env.js
43 lines (36 loc) · 1.09 KB
/
pull-env.js
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
import fetch from 'node-fetch';
import { outputFile } from 'fs-extra';
const fetchEnvs = async () => {
let apiEndPt = 'https://tools.holdex.io/api/env/pull?project=holdex-venture-studio';
let result = await fetch(apiEndPt, {
method: 'GET',
headers: {
'x-holdex-authorization': 'Bearer XtKojAp1',
},
});
return await result.json();
};
const escapeValue = (value) =>
value
? value
.replace(new RegExp('\\n', 'g'), '\\n') // combine newlines (unix) into one line
.replace(new RegExp('\\r', 'g'), '\\r') // combine newlines (windows) into one line
: '';
const updateEnvs = async () => {
let data = await fetchEnvs();
let envVars = data.data.env;
let envContent = '';
envContent +=
Object.keys(envVars)
.sort()
.map((key) => `${key}="${escapeValue(envVars[key])}"`)
.join('\n') + '\n';
const filename = '.env';
try {
await outputFile(filename, envContent, 'utf8');
console.log(`${filename} file updated successfully.`);
} catch (error) {
console.error('Error updating .env file:', error);
}
};
updateEnvs();