mirror of
https://github.com/bubblecup-12/VogelSocialMedia.git
synced 2025-07-07 18:48:50 +00:00
.env generator
This commit is contained in:
parent
9cab0d09dc
commit
95b30e5008
5 changed files with 38 additions and 3 deletions
|
@ -1,7 +1,9 @@
|
|||
import { exec } from "child_process";
|
||||
import util from "util";
|
||||
const execPromise = util.promisify(exec);
|
||||
import fs from "fs";
|
||||
import fs, { read } from "fs";
|
||||
import readlineSync from "readline-sync";
|
||||
import crypto from "crypto";
|
||||
|
||||
const json_path: string = "scripts/install.json"; // Path to the JSON file
|
||||
const raw = fs.readFileSync(json_path, "utf8");
|
||||
|
@ -12,6 +14,31 @@ if (config.installed) {
|
|||
console.log("Already installed");
|
||||
process.exit(0);
|
||||
}
|
||||
// getting user input for the PostgreSQL username and password
|
||||
console.log("generrating .env file");
|
||||
const postgresUser: string = readlineSync.question(
|
||||
"Enter the PostgreSQL username (default: postgres): ",
|
||||
{ defaultInput: "postgres" }
|
||||
);
|
||||
let postgresPassword: string = "";
|
||||
while (!postgresPassword) {
|
||||
postgresPassword = readlineSync.question("Enter the PostgreSQL password: ", {
|
||||
hideEchoBack: true, // Hides the characters
|
||||
});
|
||||
!postgresPassword && console.log("Password cannot be empty");
|
||||
}
|
||||
const jwtSecret: string = crypto.randomBytes(32).toString("hex"); // 64 Zeichen
|
||||
const env: string = `DATABASE_URL="postgresql://${postgresUser}:${postgresPassword}@localhost:5432/prisma"
|
||||
JWT_SECRET="${jwtSecret}"
|
||||
DB_USER="${postgresUser}"
|
||||
DB_PASSWORD="${postgresPassword}"`;
|
||||
try {
|
||||
fs.writeFileSync("./scripts/.env", env);
|
||||
console.log("File has been written successfully.");
|
||||
} catch (err) {
|
||||
console.error("Error writing to file:", err);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
for (const command of config.commands) {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue