mirror of
https://github.com/bubblecup-12/VogelSocialMedia.git
synced 2025-07-06 15:18:48 +00:00
.env generator
This commit is contained in:
parent
ec67454987
commit
3a35ed4073
5 changed files with 38 additions and 3 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -132,7 +132,7 @@ code/frontend/node_modules
|
|||
|
||||
# production
|
||||
build/
|
||||
|
||||
dist/
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
DATABASE_URL="postgres://postgres:YourPassword@localhost:5432/prisma"
|
||||
TOKEN_SECRET=ThisIsVeryImportantChangeThisToSomethingSecureThisIsUsedToEncryptTheJWT
|
||||
DB_USER=postgres
|
||||
DB_PASSWORD=YourPassword
|
|
@ -6,6 +6,7 @@
|
|||
"dependencies": {
|
||||
"@prisma/client": "^6.7.0",
|
||||
"@types/bcryptjs": "^3.0.0",
|
||||
"@types/readline-sync": "^1.4.8",
|
||||
"bcryptjs": "^3.0.2",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.5.0",
|
||||
|
@ -32,7 +33,7 @@
|
|||
"typescript": "^5.8.3"
|
||||
},
|
||||
"scripts": {
|
||||
"start-containers": "docker-compose -f ../db/docker-compose.yaml up -d",
|
||||
"start-containers": "docker-compose -f ../db/docker-compose.yaml --env-file .env up -d",
|
||||
"stop-containers": "docker-compose down",
|
||||
"start": "yarn start-containers && nodemon src/server.ts",
|
||||
"start-no-docker": "nodemon src/server.ts",
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -349,6 +349,11 @@
|
|||
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.7.tgz#50ae4353eaaddc04044279812f52c8c65857dbcb"
|
||||
integrity sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==
|
||||
|
||||
"@types/readline-sync@^1.4.8":
|
||||
version "1.4.8"
|
||||
resolved "https://registry.yarnpkg.com/@types/readline-sync/-/readline-sync-1.4.8.tgz#dc9767a93fc83825d90331f2549a2e90fc3255f0"
|
||||
integrity sha512-BL7xOf0yKLA6baAX6MMOnYkoflUyj/c7y3pqMRfU0va7XlwHAOTOIo4x55P/qLfMsuaYdJJKubToLqRVmRtRZA==
|
||||
|
||||
"@types/send@*":
|
||||
version "0.17.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/send/-/send-0.17.4.tgz#6619cd24e7270793702e4e6a4b958a9010cfc57a"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue