From 312e925c1b3d8266d581afd8b5c1b0daf70724d3 Mon Sep 17 00:00:00 2001 From: Kai Ritthaler Date: Mon, 19 May 2025 08:17:00 +0200 Subject: [PATCH] changed the script to run even when .env exists but not all configs are set --- code/backend/scripts/install.json | 3 ++- code/backend/scripts/install.ts | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/code/backend/scripts/install.json b/code/backend/scripts/install.json index 54932e7..ef00102 100644 --- a/code/backend/scripts/install.json +++ b/code/backend/scripts/install.json @@ -7,5 +7,6 @@ "yarn prisma generate", "echo migrating database", "yarn prisma migrate dev --name init" - ] + ], + "requiredKeys": ["DATABASE_URL", "TOKEN_SECRET", "DB_USER", "DB_PASSWORD"] } diff --git a/code/backend/scripts/install.ts b/code/backend/scripts/install.ts index fbcb01b..86d6df7 100644 --- a/code/backend/scripts/install.ts +++ b/code/backend/scripts/install.ts @@ -5,15 +5,29 @@ const execPromise = util.promisify(exec); import fs, { read } from "fs"; import readlineSync from "readline-sync"; import crypto from "crypto"; +import dotenv from "dotenv"; +import { boolean } from "zod"; const json_path: string = "scripts/install.json"; // Path to the JSON file const raw = fs.readFileSync(json_path, "utf8"); const config = JSON.parse(raw); // Parse the JSON file -//check if there is a .env file and abort the installation +//check if there is a .env and if it has the correct settings +let allSet: boolean = true; if (fs.existsSync(".env")) { - // Check if the script has already been run - console.log("Already installed"); + dotenv.config(); + for (const key of config.requiredKeys) { + if (!process.env[key]) { + allSet = false; + break; + } + } +} else { + allSet = false; +} + +if (allSet) { + // if it`s all set abort the installation process.exit(0); } // getting user input for the PostgreSQL username and password