create-node-advance-app 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cli.js ADDED
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env node
2
+
3
+ const inquirer = require('inquirer');
4
+ const chalk = require('chalk');
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const templates = require('../lib/templates');
8
+
9
+ async function main() {
10
+ const args = process.argv.slice(2);
11
+ const projectName = args[0] || 'my-backend';
12
+
13
+ console.log(chalk.cyan.bold('\nšŸ”„ Backend Forge v2.0\n'));
14
+
15
+ // Get configuration
16
+ const config = await inquirer.prompt([
17
+ {
18
+ type: 'list',
19
+ name: 'language',
20
+ message: 'Select language:',
21
+ choices: ['TypeScript', 'JavaScript'],
22
+ default: 'TypeScript'
23
+ },
24
+ {
25
+ type: 'list',
26
+ name: 'database',
27
+ message: 'Select database:',
28
+ choices: [
29
+ { name: 'MongoDB (Mongoose)', value: 'mongodb' },
30
+ { name: 'PostgreSQL (Sequelize)', value: 'postgresql' },
31
+ { name: 'MySQL (Sequelize)', value: 'mysql' },
32
+ { name: 'None', value: 'none' }
33
+ ],
34
+ default: 'mongodb'
35
+ },
36
+ {
37
+ type: 'confirm',
38
+ name: 'auth',
39
+ message: 'Setup JWT authentication?',
40
+ default: true
41
+ },
42
+ {
43
+ type: 'list',
44
+ name: 'validation',
45
+ message: 'Select validation library:',
46
+ choices: [
47
+ { name: 'Zod (recommended for TypeScript)', value: 'zod' },
48
+ { name: 'Joi', value: 'joi' },
49
+ { name: 'None', value: 'none' }
50
+ ],
51
+ default: 'zod'
52
+ },
53
+ {
54
+ type: 'list',
55
+ name: 'logger',
56
+ message: 'Select logger:',
57
+ choices: ['Winston', 'Pino', 'None'],
58
+ default: 'Winston'
59
+ },
60
+ {
61
+ type: 'confirm',
62
+ name: 'errorHandling',
63
+ message: 'Include AppError and response utilities?',
64
+ default: true
65
+ },
66
+ {
67
+ type: 'confirm',
68
+ name: 'docker',
69
+ message: 'Include Docker support?',
70
+ default: true
71
+ }
72
+ ]);
73
+
74
+ config.projectName = projectName;
75
+ config.projectPath = path.join(process.cwd(), projectName);
76
+
77
+ // Check if directory exists
78
+ if (fs.existsSync(config.projectPath)) {
79
+ console.log(chalk.red(`\nāŒ Directory "${projectName}" already exists!\n`));
80
+ process.exit(1);
81
+ }
82
+
83
+ // Display configuration summary
84
+ console.log(chalk.yellow('\nšŸ“‹ Configuration Summary:'));
85
+ console.log(chalk.gray('─'.repeat(50)));
86
+ console.log(`${chalk.bold('Project:')} ${projectName}`);
87
+ console.log(`${chalk.bold('Language:')} ${config.language}`);
88
+ console.log(`${chalk.bold('Database:')} ${config.database === 'mongodb' ? 'MongoDB (Mongoose)' : config.database === 'postgresql' ? 'PostgreSQL (Sequelize)' : config.database === 'mysql' ? 'MySQL (Sequelize)' : 'None'}`);
89
+ console.log(`${chalk.bold('Auth:')} ${config.auth ? 'JWT āœ“' : 'No'}`);
90
+ console.log(`${chalk.bold('Validation:')} ${config.validation === 'none' ? 'None' : config.validation.charAt(0).toUpperCase() + config.validation.slice(1)}`);
91
+ console.log(`${chalk.bold('Logger:')} ${config.logger}`);
92
+ console.log(`${chalk.bold('Error Utils:')} ${config.errorHandling ? 'āœ“' : 'āœ—'}`);
93
+ console.log(`${chalk.bold('Docker:')} ${config.docker ? 'āœ“' : 'āœ—'}`);
94
+ console.log(chalk.gray('─'.repeat(50)));
95
+
96
+ const { confirm } = await inquirer.prompt([
97
+ {
98
+ type: 'confirm',
99
+ name: 'confirm',
100
+ message: 'Proceed with this configuration?',
101
+ default: true
102
+ }
103
+ ]);
104
+
105
+ if (!confirm) {
106
+ console.log(chalk.yellow('\nāŒ Project generation cancelled.\n'));
107
+ process.exit(0);
108
+ }
109
+
110
+ try {
111
+ console.log(chalk.yellow('\nšŸ“¦ Creating project...\n'));
112
+
113
+ await templates.createProject(config);
114
+
115
+ console.log(chalk.green('āœ… Project created successfully!\n'));
116
+ console.log(chalk.white('Next steps:\n'));
117
+ console.log(chalk.gray(` cd ${projectName}`));
118
+ console.log(chalk.gray(' npm install'));
119
+
120
+ if (config.database === 'postgresql' || config.database === 'mysql') {
121
+ console.log(chalk.green(' Create a Database in your DBMS'));
122
+ console.log(chalk.greenBright(' Update database name and credentials in .env'));
123
+
124
+ // console.log(chalk.gray(' npx sequelize-cli db:migrate'));
125
+ } else if (config.database === 'mongodb') {
126
+ console.log(chalk.gray(' # Configure MongoDB URI in .env'));
127
+ }
128
+
129
+ console.log(chalk.gray(' npm run dev\n'));
130
+
131
+ } catch (error) {
132
+ console.error(chalk.red('āŒ Error:'), error.message);
133
+ console.error(error.stack);
134
+ process.exit(1);
135
+ }
136
+ }
137
+
138
+ main();