mksrvr 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/bin/index.js ADDED
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "fs";
4
+ import path from "path";
5
+ import { execSync } from "child_process";
6
+
7
+ import { appFile } from "../files/app.js";
8
+ import { serverJsFile } from "../files/server.js";
9
+ import { gitIgnore } from "../files/gitIgnore.js";
10
+
11
+
12
+ const projectName = process.argv[2];
13
+
14
+ if (!projectName) {
15
+ console.log("⚠️ Provide a folder name or '.' for current directory");
16
+ process.exit(1);
17
+ }
18
+
19
+ const currentDir = process.cwd();
20
+ const projectPath =
21
+ projectName === "." ? currentDir : path.join(currentDir, projectName);
22
+
23
+ // create folder only if not current dir
24
+ if (projectName !== ".") {
25
+ if (fs.existsSync(projectPath)) {
26
+ console.log("❌ Folder already exists");
27
+ process.exit(1);
28
+ }
29
+ fs.mkdirSync(projectPath);
30
+ }
31
+
32
+ console.log(
33
+ projectName === "."
34
+ ? "✅ Using current directory"
35
+ : `✅ Folder "${projectName}" created`
36
+ );
37
+
38
+
39
+ // create src folder
40
+ const srcPath = path.join(projectPath, "src");
41
+
42
+ if (!fs.existsSync(srcPath)) {
43
+ fs.mkdirSync(srcPath);
44
+ }
45
+
46
+ const pkg = {
47
+ name: projectName === "." ? path.basename(currentDir) : projectName,
48
+ version: "1.0.0",
49
+ private: true,
50
+ type: "module",
51
+ scripts: {
52
+ dev: "nodemon server.js",
53
+ start: "node server.js"
54
+ },
55
+ };
56
+
57
+ // create package.json
58
+ fs.writeFileSync(
59
+ path.join(projectPath, "package.json"),
60
+ JSON.stringify(pkg, null, 2)
61
+ );
62
+
63
+
64
+ // create env
65
+ fs.writeFileSync(
66
+ path.join(projectPath, ".env"),
67
+ "PORT=5000\n"
68
+ );
69
+
70
+
71
+ // create app.js
72
+ fs.writeFileSync(
73
+ path.join(srcPath, "app.js"),
74
+ appFile()
75
+ );
76
+
77
+ // create server.js
78
+ fs.writeFileSync(
79
+ path.join(projectPath, "server.js"),
80
+ serverJsFile()
81
+ );
82
+
83
+ // create gitignore
84
+ fs.writeFileSync(
85
+ path.join(projectPath, ".gitignore"),
86
+ gitIgnore()
87
+ );
88
+
89
+
90
+ // make folders
91
+
92
+ // create src folder
93
+ const routesPath = path.join(srcPath, "routes");
94
+ const modelPath = path.join(srcPath, "models");
95
+ const middleWarePath = path.join(srcPath, "middlewares");
96
+ const controllerPath = path.join(srcPath, "controllers");
97
+ const servicesPath = path.join(srcPath, "services");
98
+ const configPath = path.join(srcPath, "config");
99
+
100
+ fs.mkdirSync(routesPath);
101
+ fs.mkdirSync(modelPath);
102
+ fs.mkdirSync(middleWarePath);
103
+ fs.mkdirSync(controllerPath);
104
+ fs.mkdirSync(servicesPath);
105
+ fs.mkdirSync(configPath);
106
+
107
+ // install dependencies
108
+
109
+ console.log("📦 Installing dependencies...");
110
+
111
+
112
+ try {
113
+ console.log("📦 Installing dependencies...");
114
+ execSync(
115
+ "npm install express dotenv nodemon",
116
+ { cwd: projectPath, stdio: "inherit" }
117
+ );
118
+ } catch (err) {
119
+ console.log("⚠️ Dependency install failed.");
120
+ console.log("👉 You can run `npm install` manually.");
121
+ }
122
+
123
+
124
+ console.log("Starting server...");
125
+
126
+ execSync(
127
+ "npm run dev",
128
+ { cwd: projectPath, stdio: "inherit" }
129
+ );
package/files/app.js ADDED
@@ -0,0 +1,16 @@
1
+ export function appFile() {
2
+ return `import express from "express";
3
+ import cors from "cors";
4
+ const app = express();
5
+
6
+ // middleware
7
+ app.use(express.json());
8
+ app.use(cors());
9
+
10
+
11
+ app.get("/", (req, res) => {
12
+ res.send("API running 🚀");
13
+ });
14
+
15
+ export default app;`;
16
+ }
@@ -0,0 +1,12 @@
1
+ export function gitIgnore() {
2
+ return `node_modules
3
+ .env
4
+ .DS_Store
5
+ Thumbs.db
6
+ .yarnrc
7
+ yarn.lock
8
+ package-lock.json
9
+ yarn-error.log
10
+ `;
11
+ }
12
+
@@ -0,0 +1,11 @@
1
+ export function serverJsFile() {
2
+ return `import app from "./src/app.js";
3
+
4
+ import dotenv from 'dotenv';
5
+ dotenv.config();
6
+
7
+ const PORT = process.env.PORT || 5000;
8
+
9
+ app.listen(PORT, () => {
10
+ console.log(\`🚀 Server Started http://localhost:\${PORT}\`)});`
11
+ }
package/package.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "mksrvr",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "bin": {
6
+ "mksrvr": "bin/index.js"
7
+ }
8
+ }