From df417a84182ac5dee5484f015f734a1c75c9a7c5 Mon Sep 17 00:00:00 2001 From: Anupam Bista Date: Thu, 5 Sep 2024 18:45:28 +0545 Subject: [PATCH] feat: choose database type from cli --- index.mjs | 66 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/index.mjs b/index.mjs index 84be324..5571394 100644 --- a/index.mjs +++ b/index.mjs @@ -39,6 +39,7 @@ program let backupNotification = ""; let slackWebhook = ""; let discordWebhook = ""; + let databaseType = ""; let postgresHost = ""; let postgresDbName = ""; let postgresDbUser = ""; @@ -108,29 +109,51 @@ program process.exit(1); } - postgresHost = await input({ - message: "Enter your postgres host:", - }); - postgresDbName = await input({ - message: "Enter your postgres database name:", - }); - postgresDbUser = await input({ - message: "Enter your postgres database user:", - }); - postgresDbPassword = await input({ - message: "Enter your postgres database password:", - }); - mysqlHost = await input({ message: "Enter your mysql host:" }); - mysqlDbName = await input({ - message: "Enter your mysql database name:", - }); - mysqlDbUser = await input({ - message: "Enter your mysql database user:", - }); - mysqlDbPassword = await input({ - message: "Enter your mysql database password:", + databaseType = await select({ + message: "Please choose a database type:", + choices: [ + { + name: "Postgres", + value: "POSTGRES", + }, + { + name: "MySQL", + value: "MYSQL", + }, + { + name: "Both", + value: "BOTH", + }, + ], }); + if (databaseType === "POSTGRES" || databaseType === "BOTH") { + postgresHost = await input({ + message: "Enter your postgres host:", + }); + postgresDbName = await input({ + message: "Enter your postgres database name:", + }); + postgresDbUser = await input({ + message: "Enter your postgres database user:", + }); + postgresDbPassword = await input({ + message: "Enter your postgres database password:", + }); + } + if (databaseType === "MYSQL" || databaseType === "BOTH") { + mysqlHost = await input({ message: "Enter your mysql host:" }); + mysqlDbName = await input({ + message: "Enter your mysql database name:", + }); + mysqlDbUser = await input({ + message: "Enter your mysql database user:", + }); + mysqlDbPassword = await input({ + message: "Enter your mysql database password:", + }); + } + let envVariables = `#MAIL MAIL_USER=${mailUser} MAIL_PASSWORD=${mailPass} @@ -234,7 +257,6 @@ program // now write the new data to the .env file fs.writeFileSync(".env", data); - // fs.writeFileSync(".env", envVariables); console.log(chalk.green("Environment variables updated successfully!")); } catch (error) { console.log(chalk.red("Failed to write environment variables!"));