forked from Zynx64/hydralite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
73 lines (60 loc) · 2.01 KB
/
setup.js
File metadata and controls
73 lines (60 loc) · 2.01 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
62
63
64
65
66
67
68
69
70
71
72
73
require("dotenv").config();
const fs = require("fs");
const inquirer = require("inquirer");
const chalk = require("chalk");
const prompt = async (args) =>
await inquirer.prompt([{ type: "input", ...args, name: "cmd" }]).then((a) => {
return args.parse ? args.parse(a.cmd) : a.cmd;
});
(async () => {
if (
process.env.GITHUB_CLIENT_ID ||
process.env.GITHUB_CLIENT_SECRET ||
process.env.DISCORD_CLIENT_ID ||
process.env.DISCORD_CLIENT_SECRET ||
process.env.DATABASE_URL
)
return console.log(
chalk.red("!") +
chalk.red.bold(" Skipping .env setup (.env values already exist).")
);
console.clear();
console.log(chalk.green("!") + chalk.blue.bold(" API .env Configurator\n"));
let env = {};
env.GITHUB_CLIENT_ID = await prompt({
message: `Please enter your GitHub Client ID:`,
});
env.GITHUB_CLIENT_SECRET = await prompt({
message: `Please enter your GitHub Client Secret:`,
});
env.DISCORD_CLIENT_ID = await prompt({
message: `Please enter your Discord Client ID:`,
});
env.DISCORD_CLIENT_SECRET = await prompt({
message: `Please enter your Discord Client Secret:`,
});
if (!process.env.IS_GITPOD) {
env.DATABASE_URL = await prompt({
message: `Please enter your PostgresSQL Database URL:`,
default: "postgresql://postgres@localhost/postgres",
});
} else {
env.DATABASE_URL = "postgresql://gitpod@localhost/postgres";
}
if (!process.env.IS_GITPOD) {
env.REDIS_URL = await prompt({
message: `Please enter your Redis URL:`,
default: "redis://localhost",
});
} else {
env.REDIS_URL = "redis://hydralitedev:764e2f151a1cc2c04d3dd80d0430453b759f79bee75d74fa25f5c104152ba82b@localhost";
}
console.log(
chalk.green("*") + chalk.magenta.bold(" Writing configuration...")
);
const mapped = Object.keys(env).map((k) => `${k}='${env[k]}'`);
fs.writeFile(`.env`, mapped.join("\n"), () => {});
console.log(
chalk.green("^") + chalk.yellow.bold(" Finished writing configuration!\n")
);
})();