create-mern-omar 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/index.js ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "fs";
4
+ import path from "path";
5
+ import url from "url";
6
+
7
+ /**
8
+ * Absolute path to:
9
+ * - where the user ran the command
10
+ * - NOT where the package lives
11
+ */
12
+ const targetDir = process.cwd();
13
+
14
+ /**
15
+ * Absolute path to the templates folder
16
+ * (inside your generator package)
17
+ */
18
+ const __filename = url.fileURLToPath(import.meta.url);
19
+ const __dirname = path.dirname(__filename);
20
+ const templateDir = path.join(__dirname, "templates");
21
+
22
+ console.log(`Generating project in: ${targetDir}`);
23
+
24
+ /**
25
+ * Copy files recursively
26
+ */
27
+ function copyRecursive(src, dest) {
28
+ if (!fs.existsSync(dest)) {
29
+ fs.mkdirSync(dest, { recursive: true });
30
+ }
31
+
32
+ for (const item of fs.readdirSync(src)) {
33
+ const srcPath = path.join(src, item);
34
+ const destPath = path.join(dest, item);
35
+
36
+ const stat = fs.statSync(srcPath);
37
+
38
+ if (stat.isDirectory()) {
39
+ copyRecursive(srcPath, destPath);
40
+ } else {
41
+ fs.copyFileSync(srcPath, destPath);
42
+ }
43
+ }
44
+ }
45
+
46
+ copyRecursive(templateDir, targetDir);
47
+
48
+ console.log("✅ Project structure created!");
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "create-mern-omar",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "bin": {
6
+ "create-express-mongoose": "./index.js"
7
+ },
8
+ "keywords": [
9
+ "express",
10
+ "mongoose",
11
+ "mern",
12
+ "generator",
13
+ "scaffold",
14
+ "cli"
15
+ ]
16
+ }
@@ -0,0 +1,15 @@
1
+ const mongoose = require("mongoose") // importing mongoose
2
+
3
+
4
+ async function conntectToDB(){ //connection to the database
5
+ try{
6
+ await mongoose.connect(process.env.MONGODB_URI)
7
+ console.log("Connected to Database")
8
+ }
9
+ catch(error){
10
+ console.log("Error Occured",error)
11
+ }
12
+ }
13
+
14
+
15
+ module.exports = conntectToDB