omni-gen 1.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/Readme.md ADDED
@@ -0,0 +1,21 @@
1
+ # omni-gen šŸš€
2
+
3
+ **omni-gen** is a lightweight CLI tool designed to scaffold a professional MERN (MongoDB, Express, React, Node) backend structure in seconds. Stop wasting time on boilerplate and start coding your logic immediately.
4
+
5
+ ---
6
+
7
+ ## ✨ Features
8
+
9
+ - šŸ“ **Complete Folder Structure**: Automatically creates `controllers`, `models`, `routes`, `middleware`, and `config`.
10
+ - āš™ļø **Pre-configured Server**: Generates a `server.js` with Express, Dotenv, Mongoose, and CORS already set up.
11
+ - šŸ“¦ **Auto-Dependency Install**: Automatically runs `npm init` and installs `express`, `mongoose`, `dotenv`, and `cors`.
12
+ - šŸ”’ **Security Ready**: Generates a `.gitignore` and `.env` template to keep your secrets safe.
13
+
14
+ ---
15
+
16
+ ## šŸš€ Installation
17
+
18
+ You can run it directly using `npx` (no installation required):
19
+
20
+ ```bash
21
+ npx omni-gen
package/bin/cli.js ADDED
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs-extra');
4
+ const path = require('path');
5
+ const inquirer = require('inquirer');
6
+ const chalk = require('chalk');
7
+ const ora = require('ora');
8
+ const { execSync } = require('child_process');
9
+
10
+ async function startGen() {
11
+ console.log(chalk.magenta.bold('\n✨ OMNI-GEN: MERN Backend Generator\n'));
12
+
13
+ const input = await inquirer.prompt([
14
+ {
15
+ type: 'input',
16
+ name: 'projectName',
17
+ message: 'What is your project name?',
18
+ default: 'mern-server'
19
+ }
20
+ ]);
21
+
22
+ const projectPath = path.join(process.cwd(), input.projectName);
23
+
24
+ if (fs.existsSync(projectPath)) {
25
+ console.log(chalk.red(`\nāŒ Error: Folder "${input.projectName}" already exists!`));
26
+ return;
27
+ }
28
+
29
+ // Define the path to your package's templates folder
30
+ // __dirname is the 'bin' folder, so we go up one level to find 'templates'
31
+ const templateDir = path.join(__dirname, '../templates');
32
+
33
+ const spinner = ora('Generating your folder...').start();
34
+
35
+ try {
36
+ // 1. Create the Folder Structure
37
+ const folders = ['controllers', 'models', 'routes', 'middleware', 'config', 'utils'];
38
+ for (const folder of folders) {
39
+ await fs.ensureDir(path.join(projectPath, folder));
40
+ }
41
+
42
+ // 2. Copy Boilerplate Files from your templates folder
43
+ fs.copySync(path.join(templateDir, 'serverTemplate.js'), path.join(projectPath, 'server.js'));
44
+ fs.copySync(path.join(templateDir, 'envTemplate.js'), path.join(projectPath, '.env'));
45
+ fs.copySync(path.join(templateDir, 'dbTemplate.js'), path.join(projectPath, 'config/db.js'));
46
+
47
+ // Create gitignore directly (it's short enough)
48
+ await fs.writeFile(path.join(projectPath, '.gitignore'), 'node_modules\n.env');
49
+
50
+ spinner.text = 'Initializing npm and installing packages...';
51
+
52
+ // 3. Initialize NPM and Install
53
+ execSync('npm init -y', { cwd: projectPath, stdio: 'ignore' });
54
+
55
+ console.log(chalk.cyan(`\nšŸ“¦ Installing: express, dotenv, cors, mongoose...`));
56
+ execSync(`npm install express dotenv cors mongoose`, {
57
+ cwd: projectPath,
58
+ stdio: 'inherit'
59
+ });
60
+
61
+ spinner.succeed(chalk.green.bold(`\nDone! Your project "${input.projectName}" is ready.`));
62
+ console.log(chalk.white(`\nNext steps: \n1. cd ${input.projectName} \n2. node server.js \n3. Check .env credentials`));
63
+
64
+ } catch (error) {
65
+ spinner.fail('Something went wrong during generation.');
66
+ console.error(error);
67
+ }
68
+ }
69
+
70
+ startGen();
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "omni-gen",
3
+ "version": "1.0.0",
4
+ "description": "Professional MERN Backend folder structure generator",
5
+ "main": "bin/cli.js",
6
+ "bin": {
7
+ "omni-gen": "./bin/cli.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "templates"
12
+ ],
13
+ "keywords": ["mern", "mongodb", "express", "scaffold", "backend"],
14
+ "author": "Anupam Pandey",
15
+ "license": "ISC",
16
+ "dependencies": {
17
+ "inquirer": "^8.2.4",
18
+ "chalk": "^4.1.2",
19
+ "fs-extra": "^10.1.0",
20
+ "ora": "^5.4.1"
21
+ }
22
+ }
@@ -0,0 +1,13 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const connectDB = async () => {
4
+ try {
5
+ const conn = await mongoose.connect(process.env.MONGO_URI);
6
+ console.log(`šŸš€ MongoDB Connected: ${conn.connection.host}`);
7
+ } catch (error) {
8
+ console.error(`Error: ${error.message}`);
9
+ process.exit(1); // Stop the server if connection fails
10
+ }
11
+ };
12
+
13
+ module.exports = connectDB;
@@ -0,0 +1,2 @@
1
+ PORT=5000
2
+ MONGO_URI=mongodb://localhost:27017/your_database
@@ -0,0 +1,25 @@
1
+ const express = require('express');
2
+ const dotenv = require('dotenv');
3
+ const cors = require('cors');
4
+ const mongoose = require('mongoose');
5
+ const connectDB = require('./config/db');
6
+
7
+ dotenv.config();
8
+ const app = express();
9
+
10
+ // Connect to Database
11
+ // Name Your Database into ".env file"
12
+ connectDB();
13
+
14
+
15
+ // Middleware
16
+ app.use(cors());
17
+ app.use(express.json());
18
+
19
+
20
+ app.get('/', (req, res) => {
21
+ res.send('API is running with CORS enabled...');
22
+ });
23
+
24
+ const PORT = process.env.PORT || 5000;
25
+ app.listen(PORT, () => console.log(`Server running on port ${PORT}`));