@captainulfur/server-cli 1.0.2 → 1.0.3
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/cli.js +132 -42
- package/package.json +2 -1
package/cli.js
CHANGED
|
@@ -1,63 +1,153 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import fs from
|
|
4
|
-
import path from
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
5
10
|
|
|
6
11
|
const projectName = process.argv[2];
|
|
7
12
|
|
|
8
13
|
if (!projectName) {
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
console.log(chalk.red('❌ Please enter project name:'));
|
|
15
|
+
console.log(chalk.yellow(' npx @captainulfur/server-cli my-app'));
|
|
16
|
+
process.exit(1);
|
|
11
17
|
}
|
|
12
18
|
|
|
13
|
-
const
|
|
19
|
+
const targetDir = path.join(process.cwd(), projectName);
|
|
14
20
|
|
|
15
|
-
|
|
21
|
+
console.log(chalk.blue(`🚀 Creating project: ${projectName}`));
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
const pkg = {
|
|
19
|
-
name: projectName,
|
|
20
|
-
version: "1.0.0",
|
|
21
|
-
type: "module",
|
|
22
|
-
scripts: {
|
|
23
|
-
start: "node server.js",
|
|
24
|
-
dev: "nodemon server.js"
|
|
25
|
-
},
|
|
26
|
-
dependencies: {
|
|
27
|
-
express: "^5.2.1",
|
|
28
|
-
mongoose: "^9.4.1",
|
|
29
|
-
dotenv: "^17.4.1",
|
|
30
|
-
cryptjs: "^3.0.3",
|
|
31
|
-
cors: "^2.8.6",
|
|
32
|
-
jsonwebtoken: "^9.0.3",
|
|
33
|
-
morgan: "^1.10.1",
|
|
34
|
-
multer: "^2.1.1",
|
|
35
|
-
nodemon: "^3.1.14"
|
|
36
|
-
}
|
|
37
|
-
};
|
|
23
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
38
24
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
25
|
+
const folders = [
|
|
26
|
+
'Controllers',
|
|
27
|
+
'Models',
|
|
28
|
+
'Utils',
|
|
29
|
+
'Routers',
|
|
30
|
+
'Middlewares',
|
|
31
|
+
'config'
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
folders.forEach(folder => {
|
|
35
|
+
fs.mkdirSync(path.join(targetDir, folder), { recursive: true });
|
|
36
|
+
console.log(chalk.green(`📁 Folder created: ${folder}`));
|
|
37
|
+
});
|
|
43
38
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
const files = {
|
|
40
|
+
'server.js': `import { app } from "./app.js";
|
|
41
|
+
import mongoose from "mongoose";
|
|
42
|
+
import dotenv from "dotenv";
|
|
43
|
+
|
|
44
|
+
dotenv.config();
|
|
45
|
+
|
|
46
|
+
const PORT = process.env.PORT || 5000;
|
|
47
|
+
|
|
48
|
+
app.listen(PORT, () => {
|
|
49
|
+
console.log(\`⚡ Server is running on port \${PORT}\`);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
mongoose.connect(process.env.DB_URL)
|
|
53
|
+
.then(() => console.log("⚡ Database connected"))
|
|
54
|
+
.catch(err => console.error("❌ Database connection error:", err));
|
|
55
|
+
`,
|
|
56
|
+
|
|
57
|
+
'app.js': `import express from "express";
|
|
58
|
+
import morgan from "morgan";
|
|
59
|
+
import cors from "cors";
|
|
49
60
|
|
|
50
61
|
const app = express();
|
|
51
|
-
|
|
62
|
+
|
|
63
|
+
app.use(express.json());
|
|
64
|
+
app.use(express.urlencoded({ extended: true }));
|
|
65
|
+
app.use(morgan("dev"));
|
|
66
|
+
app.use(cors());
|
|
67
|
+
|
|
68
|
+
import userRouter from "./Routers/user.routes.js";
|
|
69
|
+
|
|
70
|
+
app.use("/api/users", userRouter);
|
|
52
71
|
|
|
53
72
|
app.get("/", (req, res) => {
|
|
54
|
-
|
|
73
|
+
res.json({ message: "Welcome to the API 🚀" });
|
|
55
74
|
});
|
|
56
75
|
|
|
57
|
-
|
|
58
|
-
|
|
76
|
+
export { app };
|
|
77
|
+
`,
|
|
78
|
+
|
|
79
|
+
'.env.example': `PORT=5000
|
|
80
|
+
DB_URL=mongodb://localhost:27017/${projectName}
|
|
81
|
+
JWT_SECRET=your_jwt_secret_key_here
|
|
82
|
+
`,
|
|
83
|
+
|
|
84
|
+
'package.json': `{
|
|
85
|
+
"name": "${projectName}",
|
|
86
|
+
"version": "1.0.0",
|
|
87
|
+
"description": "Express + MongoDB backend",
|
|
88
|
+
"main": "server.js",
|
|
89
|
+
"type": "module",
|
|
90
|
+
"scripts": {
|
|
91
|
+
"start": "node server.js",
|
|
92
|
+
"dev": "nodemon server.js"
|
|
93
|
+
},
|
|
94
|
+
"dependencies": {
|
|
95
|
+
"bcryptjs": "^2.4.3",
|
|
96
|
+
"cors": "^2.8.5",
|
|
97
|
+
"dotenv": "^16.4.5",
|
|
98
|
+
"express": "^4.19.2",
|
|
99
|
+
"jsonwebtoken": "^9.0.2",
|
|
100
|
+
"mongoose": "^8.3.1",
|
|
101
|
+
"morgan": "^1.10.0"
|
|
102
|
+
},
|
|
103
|
+
"devDependencies": {
|
|
104
|
+
"nodemon": "^3.1.0"
|
|
105
|
+
}
|
|
106
|
+
}`,
|
|
107
|
+
|
|
108
|
+
'README.md': `# ${projectName}
|
|
109
|
+
|
|
110
|
+
Backend project created with @captainulfur/server-cli
|
|
111
|
+
|
|
112
|
+
## How to run
|
|
113
|
+
|
|
114
|
+
\`\`\`bash
|
|
115
|
+
cd ${projectName}
|
|
116
|
+
npm install
|
|
117
|
+
cp .env.example .env
|
|
118
|
+
npm run dev
|
|
119
|
+
\`\`\`
|
|
120
|
+
`,
|
|
121
|
+
|
|
122
|
+
'Routers/user.routes.js': `import express from "express";
|
|
123
|
+
const router = express.Router();
|
|
124
|
+
|
|
125
|
+
router.get("/", (req, res) => {
|
|
126
|
+
res.json({ message: "User routes working!" });
|
|
59
127
|
});
|
|
128
|
+
|
|
129
|
+
export default router;
|
|
130
|
+
`,
|
|
131
|
+
|
|
132
|
+
'Middlewares/auth.middleware.js': `export const protect = (req, res, next) => {
|
|
133
|
+
console.log("Auth middleware called");
|
|
134
|
+
next();
|
|
135
|
+
};
|
|
136
|
+
`,
|
|
137
|
+
|
|
138
|
+
'Utils/helpers.js': `export const generateRandomString = (length = 8) => {
|
|
139
|
+
return Math.random().toString(36).substring(2, length + 2);
|
|
140
|
+
};
|
|
60
141
|
`
|
|
61
|
-
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
Object.keys(files).forEach(fileName => {
|
|
145
|
+
const filePath = path.join(targetDir, fileName);
|
|
146
|
+
fs.writeFileSync(filePath, files[fileName]);
|
|
147
|
+
console.log(chalk.green(`📄 File created: ${fileName}`));
|
|
148
|
+
});
|
|
62
149
|
|
|
63
|
-
console.log(
|
|
150
|
+
console.log(chalk.bold.green('\n✅ Project created successfully!'));
|
|
151
|
+
console.log(chalk.cyan(`\n cd ${projectName}`));
|
|
152
|
+
console.log(chalk.cyan(` npm install`));
|
|
153
|
+
console.log(chalk.cyan(` npm run dev\n`));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@captainulfur/server-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"bcryptjs": "^3.0.3",
|
|
32
|
+
"chalk": "^5.6.2",
|
|
32
33
|
"cors": "^2.8.6",
|
|
33
34
|
"dotenv": "^17.4.1",
|
|
34
35
|
"express": "^5.2.1",
|