backend-scaffolder 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.
Files changed (4) hide show
  1. package/README.md +164 -0
  2. package/index.js +81 -0
  3. package/npmrc +1 -0
  4. package/package.json +14 -0
package/README.md ADDED
@@ -0,0 +1,164 @@
1
+ # Backend Scaffolder
2
+
3
+ A simple CLI tool that instantly generates a production-ready Node.js + Express backend folder structure.
4
+
5
+ ## Features
6
+
7
+ * Creates a clean backend architecture
8
+ * Generates common folders:
9
+
10
+ * config
11
+ * controllers
12
+ * middlewares
13
+ * models
14
+ * routes
15
+ * services
16
+ * sockets
17
+ * utils
18
+ * Generates starter files:
19
+
20
+ * server.js
21
+ * app.js
22
+ * package.json
23
+ * .gitignore
24
+ * Adds `.gitkeep` files to preserve empty directories
25
+ * Ready for Express development
26
+
27
+ ---
28
+
29
+ ## Installation
30
+
31
+ ### Global Installation
32
+
33
+ ```bash
34
+ npm install -g @abdurwebdev/backend-scaffolder
35
+ ```
36
+
37
+ ---
38
+
39
+ ## Usage
40
+
41
+ Create a new backend project:
42
+
43
+ ```bash
44
+ create-backend-layout my-api
45
+ ```
46
+
47
+ If no project name is provided:
48
+
49
+ ```bash
50
+ create-backend-layout
51
+ ```
52
+
53
+ Default folder name:
54
+
55
+ ```bash
56
+ my-backend-app
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Generated Structure
62
+
63
+ ```text
64
+ my-api/
65
+
66
+ ├── logs/
67
+
68
+ ├── src/
69
+ │ ├── config/
70
+ │ ├── controllers/
71
+ │ ├── middlewares/
72
+ │ ├── models/
73
+ │ ├── routes/
74
+ │ ├── services/
75
+ │ ├── sockets/
76
+ │ └── utils/
77
+
78
+ ├── server.js
79
+ ├── .gitignore
80
+ └── package.json
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Generated app.js
86
+
87
+ ```javascript
88
+ const express = require('express');
89
+ const cors = require('cors');
90
+
91
+ const app = express();
92
+
93
+ app.use(cors());
94
+ app.use(express.json());
95
+ app.use(express.urlencoded({ extended: true }));
96
+
97
+ app.get('/', (req, res) => {
98
+ res.json({ message: "API is running..." });
99
+ });
100
+
101
+ module.exports = app;
102
+ ```
103
+
104
+ ---
105
+
106
+ ## Getting Started
107
+
108
+ After generating the project:
109
+
110
+ ```bash
111
+ cd my-api
112
+ npm install
113
+ npm run dev
114
+ ```
115
+
116
+ Server starts on:
117
+
118
+ ```text
119
+ http://localhost:5000
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Example
125
+
126
+ ```bash
127
+ create-backend-layout ecommerce-api
128
+ ```
129
+
130
+ Output:
131
+
132
+ ```bash
133
+ 🚀 Scaffolding backend structure in:
134
+ ecommerce-api
135
+
136
+ ✅ Structure successfully created!
137
+
138
+ Next steps:
139
+ cd ecommerce-api
140
+ npm install
141
+ npm run dev
142
+ ```
143
+
144
+ ---
145
+
146
+ ## Requirements
147
+
148
+ * Node.js 18+
149
+ * npm
150
+
151
+ ---
152
+
153
+ ## Author
154
+
155
+ Abdur Rehman
156
+
157
+ * GitHub: https://github.com/abdurwebdev
158
+ * LinkedIn: https://www.linkedin.com/in/abdur-rehman-45178a322/
159
+
160
+ ---
161
+
162
+ ## License
163
+
164
+ ISC
package/index.js ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ // Get the project name from command line arguments, default to 'my-backend-app'
7
+ const projectName = process.argv[2] || 'my-backend-app';
8
+ const targetDir = path.join(process.cwd(), projectName);
9
+
10
+ // Define the complete directory structure based on your layout
11
+ const directories = [
12
+ 'logs',
13
+ 'src',
14
+ 'src/config',
15
+ 'src/controllers',
16
+ 'src/middlewares',
17
+ 'src/models',
18
+ 'src/routes',
19
+ 'src/services',
20
+ 'src/sockets',
21
+ 'src/utils',
22
+ ];
23
+
24
+ // Define boilerplate files to generate
25
+ const files = {
26
+ '.gitignore': `node_modules/\n.env\nlogs/\n.DS_Store`,
27
+
28
+ 'server.js': `const app = require('./src/app');\nconst http = require('http');\n\nconst PORT = process.env.PORT || 5000;\nconst server = http.createServer(app);\n\n// Initialize sockets or server listeners here\n\nserver.listen(PORT, () => {\n console.log(\`Server running on port \${PORT}\`);\n});`,
29
+
30
+ 'src/app.js': `const express = require('express');\nconst cors = require('cors');\n\nconst app = express();\n\n// Middlewares\napp.use(cors());\napp.use(express.json());\napp.use(express.urlencoded({ extended: true }));\n\n// Base Route\napp.get('/', (req, res) => {\n res.json({ message: "API is running..." });\n});\n\nmodule.exports = app;`,
31
+
32
+ 'package.json': JSON.stringify({
33
+ name: projectName,
34
+ version: "1.0.0",
35
+ description: "Backend service",
36
+ main: "server.js",
37
+ scripts: {
38
+ start: "node server.js",
39
+ dev: "nodemon server.js"
40
+ },
41
+ dependencies: {
42
+ express: "^4.19.2",
43
+ cors: "^2.8.5",
44
+ dotenv: "^16.4.5"
45
+ },
46
+ devDependencies: {
47
+ nodemon: "^3.1.0"
48
+ }
49
+ }, null, 2)
50
+ };
51
+
52
+ function createScaffold() {
53
+ console.log(`\n🚀 Scaffolding backend structure in: ${targetDir}...\n`);
54
+
55
+ // 1. Create base project directory
56
+ if (!fs.existsSync(targetDir)) {
57
+ fs.mkdirSync(targetDir, { recursive: true });
58
+ } else {
59
+ console.error(`❌ Error: Directory "${projectName}" already exists.`);
60
+ process.exit(1);
61
+ }
62
+
63
+ // 2. Create subdirectories
64
+ directories.forEach(dir => {
65
+ const dirPath = path.join(targetDir, dir);
66
+ fs.mkdirSync(dirPath, { recursive: true });
67
+ // Optional: Add a placeholder file so git tracks empty folders
68
+ fs.writeFileSync(path.join(dirPath, '.gitkeep'), '');
69
+ });
70
+
71
+ // 3. Create starter boilerplate files
72
+ Object.entries(files).forEach(([filePath, content]) => {
73
+ const fullPath = path.join(targetDir, filePath);
74
+ fs.writeFileSync(fullPath, content, 'utf8');
75
+ });
76
+
77
+ console.log(`✅ Structure successfully created!`);
78
+ console.log(`\nNext steps:\n cd ${projectName}\n npm install\n npm run dev\n`);
79
+ }
80
+
81
+ createScaffold();
package/npmrc ADDED
@@ -0,0 +1 @@
1
+ prefix=${APPDATA}\npm
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "backend-scaffolder",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },"bin": {
8
+ "create-backend-layout": "./index.js"
9
+ },
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "ISC",
13
+ "description": ""
14
+ }