@saboosanket/code-generator
Version:
This npm package is a versatile setup tool tailored for Node.js projects, enabling users to generate customized project structures and functionalities. It supports integration with Google Cloud Platform (GCP), RabbitMQ, Redis, a Prisma query generator, an
100 lines (98 loc) • 3.36 kB
JavaScript
#!/usr/bin/env node
import inquirer from 'inquirer'
import chalk from 'chalk'
import { createFilesHandler } from './src/utils/create_files_handler.js'
const prompt = inquirer.createPromptModule()
prompt([
// {
// type: 'confirm',
// name: 'baseProject',
// message: chalk.blue.bold('Do you want the base project structure?'),
// default: true
// },
{
type: 'checkbox',
name: 'cloudProviders',
// , AWS, or both
message: chalk.green('Select cloud provider functionality (GCP):'),
choices: [
{
name: chalk.cyan('GCP - Google Cloud Platform'),
value: { 'gcp': true }
}
// { name: chalk.cyan('AWS - Amazon Web Services'), value: 'aws' },
// { name: chalk.cyan('Both - Include both GCP and AWS functionalities'), value: 'bothProviders' }
]
},
{
type: 'confirm',
name: 'rabbitmq',
message:
chalk.yellow('Do you want RabbitMQ functionality?\n') +
chalk.dim(
'(RabbitMQ is a message broker that helps with message queuing.)'
),
default: false
},
{
type: 'confirm',
name: 'redis',
message:
chalk.yellow('Do you want Redis functionality?\n') +
chalk.dim(
'(Redis is an in-memory data store commonly used as a message broker and for caching to improve application performance. )'
),
default: false
},
{
type: 'confirm',
name: 'httpModule',
message:
chalk.magenta('Do you want the HTTP module?\n') +
chalk.dim(
'(This helps you manage all your API calls with retries, backoff, etc.)'
),
default: true
},
{
type: 'confirm',
name: 'dbQueriesIndividualModelPrisma',
message:
chalk.magenta(
'Do you want the db queries for a specific model?\n'
) +
chalk.dim(
'(This reads the specific prisma model and generates the CRUD queries for it along with pagination support for get routes)'
),
default: false
},
{
type: 'input',
name: 'modelName',
message: chalk.green('Please enter the Prisma model name:'),
when: (answers) => answers.dbQueriesIndividualModelPrisma === true, // Only ask this if individual model queries are requested
validate: (input) => (input ? true : 'Model name cannot be empty.')
},
{
type: 'confirm',
name: 'dbQueriesAllModelsPrisma',
message:
chalk.magenta('Do you want the db queries all models?\n') +
chalk.dim(
'(This reads the all prisma models and generates the CRUD queries for it along with pagination support for get routes)'
),
default: true
}
])
.then((answers) => {
if (answers) {
console.info(chalk.bold.green('Your selections:'))
console.info(chalk.cyan(JSON.stringify(answers, null, 2)))
createFilesHandler(answers)
} else {
console.info(chalk.red('Oops, closed.'))
}
})
.catch((_error) => {
console.info(chalk.red('Oops, closed.'))
})