Skip to content

Commit

Permalink
Merge pull request #18 from theanupambista/main
Browse files Browse the repository at this point in the history
feat: choose database type from cli
  • Loading branch information
isarojdahal authored Sep 5, 2024
2 parents 0375e8f + df417a8 commit d3b024b
Showing 1 changed file with 44 additions and 22 deletions.
66 changes: 44 additions & 22 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ program
let backupNotification = "";
let slackWebhook = "";
let discordWebhook = "";
let databaseType = "";
let postgresHost = "";
let postgresDbName = "";
let postgresDbUser = "";
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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!"));
Expand Down

0 comments on commit d3b024b

Please sign in to comment.