-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.js
executable file
·43 lines (36 loc) · 1.13 KB
/
entrypoint.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
"use-strict;"
/* eslint-disable @typescript-eslint/no-var-requires */
const dotenv = require("dotenv");
const fs = require("fs");
const os = require("os");
let envFilePath = ".env"
let configRoot = "ENV_CONFIG"
let outputFile = "./public/env-config.js"
for (let i = 2; i < process.argv.length; i++) {
switch (process.argv[i]) {
case "-e":
envFilePath = process.argv[++i]
break;
case "-o":
outputFile = process.argv[++i]
break;
case "-c":
configRoot = process.argv[++i]
break;
default:
throw Error(`unknown option ${process.argv[i]}`)
}
}
if (fs.existsSync(envFilePath)) {
console.log(`Loading environment file from '${envFilePath}'`)
dotenv.config({
path: envFilePath
})
}
console.log(`Generating JS configuration output to: ${outputFile}`)
fs.writeFileSync(outputFile, `window.${configRoot} = {${os.EOL}${
Object.keys(process.env).filter(x => x.startsWith("REACT_APP_")).map(key => {
console.log(`- Found '${key}'`);
return `${key}: '${process.env[key]}',${os.EOL}`;
}).join("")
}${os.EOL}}`);