-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvFileGenerator.js
More file actions
61 lines (49 loc) · 1.74 KB
/
envFileGenerator.js
File metadata and controls
61 lines (49 loc) · 1.74 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
54
55
56
57
58
59
60
61
const fs = require("node:fs");
const readline = require("node:readline");
const variables = [
{ prompt: "MongoDB user:", name: "MONGODB_USER" },
{ prompt: "MongoDB password:", name: "MONGODB_PASSWORD" },
{ prompt: "MongoDB database name:", name: "MONGODB_DATABASE" },
{ prompt: "MongoDB port:", name: "MONGODB_DOCKER_PORT" },
{ prompt: "JWT Secret key:", name: "JWT_SECRET" },
];
const cloudinaryVariables = [
{ prompt: "Cloudinary cloud name:", name: "CLOUD_NAME" },
{ prompt: "Cloudinary api key:", name: "API_KEY" },
{ prompt: "Cloudinary api secret:", name: "API_SECRET" },
];
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const askQuestion = (question) => {
return new Promise((resolve) => rl.question(question, resolve));
};
const createEnvMap = async (
variablesInfoArray,
cloudinaryVariablesInfoArray
) => {
const envMap = new Map();
for (const variableInfo of variablesInfoArray) {
const value = await askQuestion(variableInfo.prompt);
envMap.set(variableInfo.name, value);
}
const haveCloudinaryInfo = await askQuestion(
"Do you have Cloudinary api keys [yes/no]"
);
for (const variableInfo of cloudinaryVariablesInfoArray) {
let value = "";
if (haveCloudinaryInfo.trim() === "yes") {
value = await askQuestion(variableInfo.prompt);
}
envMap.set(variableInfo.name, value);
}
rl.close();
return envMap;
};
createEnvMap(variables, cloudinaryVariables).then((environmentMap) => {
const writer = fs.createWriteStream("./.env", { flags: "w" });
for (const [key, value] of environmentMap.entries()) {
writer.write(`${key}=\"${value}\"\n`);
}
});