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 +48 -0
- package/package.json +16 -0
- package/templates/db/index.js +15 -0
- package/templates/package-lock.json +1116 -0
- package/templates/package.json +19 -0
- package/templates/server.js +55 -0
- package/test-proj/db/index.js +15 -0
- package/test-proj/package-lock.json +1116 -0
- package/test-proj/package.json +19 -0
- package/test-proj/server.js +55 -0
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,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
|