UNPKG

xpress-mvc

Version:

An MVC framework based on Express.js

123 lines (98 loc) • 3.77 kB
const inquirer = require("inquirer"); const chalk = require("chalk"); const figlet = require("figlet"); const config = require("./config"); const dbConfig = require('./dbConfig'); const { firstLetterUpperCase, spaceToDash } = require("./functions"); async function askRepoName() { console.clear(); // Clears the console for a clean look console.log( chalk.cyan(figlet.textSync("Xpress-MVC", { horizontalLayout: "fitted" })) ); console.log(chalk.green("\nLet's set up your repository!\n")); const answers = await inquirer.prompt([ { type: "input", name: "repoName", message: chalk.yellow("šŸš€ Enter your repository name:"), validate: (input) => input.trim() ? true : "āŒ Repository name cannot be empty!", }, ]); console.log(chalk.blue(`\nāœ… Your repository name is: ${chalk.bold( spaceToDash(answers.repoName) )}\n`)); return answers.repoName; } async function askORMChoice() { console.log( chalk.cyan( figlet.textSync("Choose an ORM", { horizontalLayout: "fitted" }) ) ); const answers = await inquirer.prompt([ { type: "list", name: "orm", message: chalk.bold.yellow("Which ORM do you prefer?"), choices: [ { name: chalk.green("🟢 Sequelize (SQL-based ORM)"), value: "sequelize" }, { name: chalk.blue("šŸ”µ Objection.js + Knex.js (Query Builder)"), value: "ObjectionKnex" }, ], }, ]); console.log(`\n\n\n`) const ormDetails = { sequelize: { name: chalk.green.bold("Sequelize"), description: chalk.green("A promise-based ORM for Node.js with easy-to-use syntax."), }, ObjectionKnex: { name: chalk.blue.bold("Objection.js + Knex.js"), description: chalk.blue("A powerful SQL query builder for Node.js with full ORM features."), }, }; const ormName = { sequelize: ['sequelize','sequelize-cli'], ObjectionKnex: ['objection','knex'] } config.orm = ormName[answers.orm] config.ormName = answers.orm console.log(chalk.bold("\n✨ You selected: ") + ormDetails[answers.orm].name); console.log(chalk.dim("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")); console.log(chalk.bold("šŸ“Œ Description: ") + ormDetails[answers.orm].description); console.log(chalk.dim("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n")); return answers.orm; } async function askDatabaseChoice() { console.clear(); console.log( chalk.cyan(figlet.textSync("DATABASE", { horizontalLayout: "fitted" })) ); console.log(chalk.green("\nLet's configure your database!\n")); const answers = await inquirer.prompt([ { type: "list", name: "database", message: chalk.yellow("šŸ›¢ Select your preferred database:"), choices: [ { name: "MySQL", value: "mysql" }, { name: "PostgreSQL", value: "postgres" }, { name: "SQLite", value: "sqlite" }, { name: 'Oracle', value: 'oracle'}, { name: 'Microsoft SQL Server' , value : 'mssql'}, { name: 'Amazon Redshift' , value: 'redshift' } ], }, ]); const dbDrivers = { mysql: "mysql2", postgres: "pg", sqlite: "sqlite3", oracle: "oracledb", mssql: "mssql", redshift: "pg", }; config.development = dbConfig[config.ormName][answers.database] config.databaseDriver = dbDrivers[answers.database] config.database = answers.database return answers.database; } module.exports = { askRepoName,askORMChoice,askDatabaseChoice };