cobalt/src/modules/setup.js

53 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-07-08 19:17:56 +01:00
import { existsSync, unlinkSync, appendFileSync } from "fs";
import { createInterface } from "readline";
2022-07-17 12:21:51 +01:00
import { Cyan, Bright, Green } from "./sub/consoleText.js";
2022-07-08 19:17:56 +01:00
import { execSync } from "child_process";
let envPath = './.env';
let q = `${Cyan('?')} \x1b[1m`;
let ob = {}
2022-08-16 08:14:19 +01:00
let rl = createInterface({ input: process.stdin, output: process.stdout });
2022-07-08 19:17:56 +01:00
2022-09-01 14:51:18 +01:00
let final = () => {
if (existsSync(envPath)) {
unlinkSync(envPath)
}
for (let i in ob) {
appendFileSync(envPath, `${i}=${ob[i]}\n`)
}
2022-11-04 08:49:58 +00:00
console.log(Bright("\nAwesome! I've created a fresh .env file for you."))
2022-09-01 14:51:18 +01:00
console.log(`${Bright("Now I'll run")} ${Cyan("npm install")} ${Bright("to install all dependencies. It shouldn't take long.\n\n")}`)
execSync('npm install', { stdio: [0, 1, 2] });
2022-11-04 08:49:58 +00:00
console.log(`\n\n${Cyan("All done!\n")}`)
console.log(Bright("You can re-run this script at any time to update the configuration."))
console.log(Bright("\nYou're now ready to start cobalt. Simply run ") + Cyan("npm start") + Bright('!\nHave fun :)'))
2022-09-01 14:51:18 +01:00
rl.close()
}
2022-07-08 19:17:56 +01:00
console.log(
2022-11-04 08:49:58 +00:00
`${Cyan("Welcome to cobalt!")}\n${Bright("Let's start by creating a new ")}${Cyan(".env")}${Bright(" file. You can always change it later.")}`
2022-07-08 19:17:56 +01:00
)
console.log(
2022-11-04 08:49:58 +00:00
Bright("\nWhat's the domain this instance will be running on? (localhost)\nExample: co.wukko.me")
2022-07-08 19:17:56 +01:00
)
rl.question(q, r1 => {
ob['selfURL'] = `http://localhost:9000/`
ob['port'] = 9000
if (r1) ob['selfURL'] = `https://${r1}/`
2022-11-04 08:49:58 +00:00
console.log(Bright("\nGreat! Now, what's the port it'll be running on? (9000)"))
2022-07-08 19:17:56 +01:00
rl.question(q, r2 => {
if (r2) ob['port'] = r2
if (!r1 && r2) ob['selfURL'] = `http://localhost:${r2}/`
2023-04-09 13:04:03 +01:00
console.log(Bright("\nWould you like to enable CORS? It allows other websites and extensions to use your instance's API.\n y/n (n)"))
rl.question(q, r3 => {
if (r3.toLowerCase() !== 'y') ob['cors'] = '0'
final()
})
2022-07-08 19:17:56 +01:00
});
})