4bnode 3.5.3 → 4.0.2

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 (62) hide show
  1. package/README.md +144 -109
  2. package/add-api.js +288 -156
  3. package/add-crud.js +226 -0
  4. package/add-login.js +152 -319
  5. package/add-mongo-delete.js +67 -138
  6. package/add-mongo-insert.js +87 -204
  7. package/add-mongo-read.js +100 -216
  8. package/add-mongo-schema.js +431 -199
  9. package/add-mongo-update.js +89 -202
  10. package/add-mongo.js +125 -218
  11. package/add-serialport.js +53 -98
  12. package/add-socket.js +43 -66
  13. package/add-websocket.js +68 -140
  14. package/index.js +341 -156
  15. package/lib/env.js +18 -0
  16. package/lib/indexFile.js +134 -0
  17. package/lib/names.js +21 -0
  18. package/lib/project.js +122 -0
  19. package/lib/routeFile.js +56 -0
  20. package/lib/ui.js +161 -0
  21. package/package.json +9 -16
  22. package/skeleton/.4bnode/assets/fonts/NotoSans-Bold.woff2 +0 -0
  23. package/skeleton/.4bnode/assets/fonts/NotoSans-Light.woff2 +0 -0
  24. package/skeleton/.4bnode/assets/fonts/NotoSans-Medium.woff2 +0 -0
  25. package/skeleton/.4bnode/assets/fonts/NotoSans-Regular.woff2 +0 -0
  26. package/skeleton/.4bnode/assets/fonts/NotoSans-SemiBold.woff2 +0 -0
  27. package/skeleton/.4bnode/assets/images/mongo.png +0 -0
  28. package/skeleton/.4bnode/assets/images/mysql.png +0 -0
  29. package/skeleton/.4bnode/assets/images/postgresql.png +0 -0
  30. package/skeleton/.4bnode/assets/images/sqlite.png +0 -0
  31. package/skeleton/.4bnode/assets/js/App.js +115 -0
  32. package/skeleton/.4bnode/assets/js/Root.js +44 -0
  33. package/skeleton/.4bnode/assets/js/components/Modal.js +52 -0
  34. package/skeleton/.4bnode/assets/js/components/Sidebar.js +68 -0
  35. package/skeleton/.4bnode/assets/js/components/ToastContainer.js +15 -0
  36. package/skeleton/.4bnode/assets/js/context.js +7 -0
  37. package/skeleton/.4bnode/assets/js/lib.js +83 -0
  38. package/skeleton/.4bnode/assets/js/main.js +5 -0
  39. package/skeleton/.4bnode/assets/js/pages/ApiTesterPage.js +1594 -0
  40. package/skeleton/.4bnode/assets/js/pages/DashboardPage.js +435 -0
  41. package/skeleton/.4bnode/assets/js/pages/DatabasePage.js +461 -0
  42. package/skeleton/.4bnode/assets/js/pages/EnvironmentPage.js +141 -0
  43. package/skeleton/.4bnode/assets/js/pages/RealtimePage.js +186 -0
  44. package/skeleton/.4bnode/assets/js/pages/RoutesPage.js +1656 -0
  45. package/skeleton/.4bnode/assets/js/pages/SchemasPage.js +901 -0
  46. package/skeleton/.4bnode/assets/js/pages/SerialPortPage.js +170 -0
  47. package/skeleton/.4bnode/assets/js/screens/PasskeyScreen.js +105 -0
  48. package/skeleton/.4bnode/assets/js/screens/SplashScreen.js +66 -0
  49. package/skeleton/.4bnode/dev-api.js +2930 -0
  50. package/skeleton/.4bnode/ui.html +1556 -0
  51. package/skeleton/index.js +70 -17
  52. package/skeleton/package.json +9 -5
  53. package/skeleton/public/index.html +288 -86
  54. package/README_4bnode.md +0 -197
  55. package/src/auth/passport.js +0 -21
  56. package/src/db.js +0 -13
  57. package/test-server/.env.development +0 -1
  58. package/test-server/.env.production +0 -1
  59. package/test-server/index.js +0 -82
  60. package/test-server/package-lock.json +0 -1267
  61. package/test-server/package.json +0 -20
  62. package/test-server/public/index.html +0 -90
package/README_4bnode.md DELETED
@@ -1,197 +0,0 @@
1
- # 4Brains Node Generator
2
-
3
- A comprehensive CLI tool to streamline the generation and management of Node.js applications by 4Brains Technologies.
4
-
5
- ## Installation
6
-
7
- To install the 4Brains Node Generator globally, use the following command:
8
-
9
- ```sh
10
- npm install -g 4brains-node-generator
11
- ```
12
-
13
- ## Available Commands
14
-
15
- ### `4bnode init <projectName>`
16
-
17
- Initialize a new Node.js project with the specified name.
18
-
19
- ```sh
20
- 4bnode init my-project
21
- ```
22
-
23
- ### `4bnode add-api <endpointName>`
24
-
25
- Add a new API endpoint to your project.
26
-
27
- ```sh
28
- 4bnode add-api users
29
- ```
30
-
31
- ### `4bnode add-mongo`
32
-
33
- Integrate MongoDB into your project. This command sets up the necessary MongoDB configuration.
34
-
35
- ```sh
36
- 4bnode add-mongo
37
- ```
38
-
39
- ### `4bnode add-mongo-schema <schemaName>`
40
-
41
- Create a new MongoDB schema. You will be prompted to enter field details for the schema.
42
-
43
- ```sh
44
- 4bnode add-mongo-schema User
45
- ```
46
-
47
- ### `4bnode add-login`
48
-
49
- Add a login template to an existing route in your project. You will be prompted to select a route and a model, and then enter the login fields.
50
-
51
- ```sh
52
- 4bnode add-login
53
- ```
54
-
55
- ### `4bnode add-mongo-insert`
56
-
57
- Add a template for inserting data into a MongoDB collection. This command allows you to easily create routes for data insertion.
58
-
59
- ```sh
60
- 4bnode add-mongo-insert
61
- ```
62
-
63
- ### `4bnode add-mongo-update`
64
-
65
- Add a template for updating data in a MongoDB collection. This facilitates creating routes for updating documents.
66
-
67
- ```sh
68
- 4bnode add-mongo-update
69
- ```
70
-
71
- ### `4bnode add-mongo-read`
72
-
73
- Add a template for reading data from a MongoDB collection, helping you to quickly set up read operations.
74
-
75
- ```sh
76
- 4bnode add-mongo-read
77
- ```
78
-
79
- ### `4bnode add-mongo-delete`
80
-
81
- Add a template for deleting data from a MongoDB collection, making it easy to handle deletion operations.
82
-
83
- ```sh
84
- 4bnode add-mongo-delete
85
- ```
86
-
87
- ### `4bnode add-socket`
88
-
89
- Integrate Socket.io into your project for real-time communication capabilities.
90
-
91
- ```sh
92
- 4bnode add-socket
93
- ```
94
-
95
- ### `4bnode add-websocket`
96
-
97
- Add native WebSocket support to your project.
98
-
99
- ```sh
100
- 4bnode add-websocket
101
- ```
102
-
103
- ### `4bnode add-serialport`
104
-
105
- Integrate SerialPort functionality into your project. This command does the following:
106
- - Prompts for Serial Port path and baud rate
107
- - Automatically updates `.env.development` and `.env.production` with `SERIALPORT_PATH` and `BAUDRATE`
108
- - Adds SerialPort and Readline parser setup to your `index.js`
109
- - Installs required dependencies: `serialport` and `@serialport/parser-readline`
110
-
111
- ```sh
112
- 4bnode add-serialport
113
- ```
114
-
115
- Once added, your project will automatically initialize the serial port with the specified configuration and log incoming data.
116
-
117
- Example incoming data log:
118
- ```sh
119
- Received data: <data from serial device>
120
- ```
121
-
122
- ## Examples
123
-
124
- ### Adding MongoDB Schema
125
-
126
- When you run the command to add a MongoDB schema, you will be prompted to enter the field details.
127
-
128
- ```sh
129
- 4bnode add-mongo-schema User
130
- ```
131
-
132
- ### Adding a Login Template
133
-
134
- When you run the command to add a login template, you will be prompted to select a route and a model, and then enter the login fields.
135
-
136
- ```sh
137
- 4bnode add-login
138
- ```
139
-
140
- ## Real-time Communication Integration
141
-
142
- ### WebSocket Integration
143
-
144
- When you add WebSocket integration, it will automatically be added to your project.
145
-
146
- ```sh
147
- 4bnode add-websocket
148
- ```
149
-
150
- To use `req.wss` in your route endpoints, you can access the WebSocket server as follows:
151
-
152
- ```js
153
- router.get("/some-endpoint", (req, res) => {
154
- req.wss.clients.forEach((client) => {
155
- if (client.readyState === WebSocket.OPEN) {
156
- client.send("Hello, client!");
157
- }
158
- });
159
- res.send("Message sent to all WebSocket clients.");
160
- });
161
- ```
162
-
163
- ### Socket.io Integration
164
-
165
- When you add Socket.io integration, it will automatically be added to your project.
166
-
167
- ```sh
168
- 4bnode add-socket
169
- ```
170
-
171
- To use `req.io` in your route endpoints, you can access the Socket.io server as follows:
172
-
173
- ```js
174
- router.get("/some-endpoint", (req, res) => {
175
- req.io.emit("message", "Hello, Socket.io clients!");
176
- res.send("Message sent to all Socket.io clients.");
177
- });
178
- ```
179
-
180
- ## Help
181
-
182
- If you enter an invalid command, you will see the following message:
183
-
184
- ```sh
185
- Unknown command. Use -h or --help for help.
186
- ```
187
-
188
- You can also use `-h` or `--help` to get help information.
189
-
190
- ```sh
191
- 4bnode -h
192
- 4bnode --help
193
- ```
194
-
195
- ## License
196
-
197
- This project is licensed under the ISC License.
@@ -1,21 +0,0 @@
1
- import passport from 'passport';
2
- import { Strategy as JwtStrategy, ExtractJwt } from 'passport-jwt';
3
- import mongoose from 'mongoose';
4
- import User from '../models/User.js'; // Adjust the path to your user model
5
-
6
- const opts = {};
7
- opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
8
- opts.secretOrKey = process.env.JWT_SECRET;
9
-
10
- passport.use(new JwtStrategy(opts, (jwt_payload, done) => {
11
- User.findById(jwt_payload.id)
12
- .then(user => {
13
- if (user) {
14
- return done(null, user);
15
- }
16
- return done(null, false);
17
- })
18
- .catch(err => console.error(err));
19
- }));
20
-
21
- export default passport;
package/src/db.js DELETED
@@ -1,13 +0,0 @@
1
- import mongoose from 'mongoose';
2
-
3
- const connectDB = async () => {
4
- try {
5
- const conn = await mongoose.connect(process.env.MONGO_URI);
6
- console.log(`MongoDB connected: ${conn.connection.host}`);
7
- } catch (err) {
8
- console.error(err);
9
- process.exit(1);
10
- }
11
- };
12
-
13
- export default connectDB;
@@ -1 +0,0 @@
1
- PORT=3000
@@ -1 +0,0 @@
1
- PORT=3000
@@ -1,82 +0,0 @@
1
- import { WebSocketServer } from 'ws';
2
- import http from 'http';
3
- import express from "express";
4
- import dotenv from "dotenv";
5
- import bodyParser from "body-parser";
6
- import path from "path";
7
- import cors from "cors";
8
- import os from "os";
9
-
10
- const env = process.env.NODE_ENV || "development";
11
- dotenv.config({ path: `.env.${env}` });
12
-
13
- const app = express();
14
- const port = process.env.PORT || 3000;
15
-
16
- // Middleware
17
-
18
- const server = http.createServer(app);
19
- const wsServer = new WebSocketServer({ server });
20
- console.log(`WebSocket server is running on the same port as the server (${port})`);
21
-
22
- wsServer.on('connection', (ws) => {
23
- console.log('A client connected');
24
-
25
- ws.on('message', (message) => {
26
- try {
27
- const parsedMessage = JSON.parse(message);
28
- console.log('Received:', parsedMessage);
29
-
30
- // Broadcast to all clients except sender
31
- wsServer.clients.forEach((client) => {
32
- if (client !== ws && client.readyState === ws.OPEN) {
33
- client.send(JSON.stringify(parsedMessage));
34
- }
35
- });
36
- } catch (error) {
37
- console.error('Invalid message format:', error);
38
- }
39
- });
40
-
41
- ws.on('close', () => {
42
- console.log('Client disconnected');
43
- });
44
- });
45
-
46
- app.use((req, res, next) => {
47
- req.wss = wsServer;
48
- next();
49
- });
50
- app.use(bodyParser.json({ limit: "50mb" }));
51
- app.use(bodyParser.urlencoded({ extended: true, limit: "50mb" }));
52
- app.use(cors({ origin: "*" }));
53
-
54
- // Serve static files from the public directory
55
- const __dirname = path.resolve();
56
- app.use(express.static(path.join(__dirname, "public")));
57
-
58
- // Get local network IP address
59
- function getLocalNetworkIp() {
60
- const interfaces = os.networkInterfaces();
61
- for (const name of Object.keys(interfaces)) {
62
- for (const iface of interfaces[name]) {
63
- if (iface.family === "IPv4" && !iface.internal) {
64
- return iface.address;
65
- }
66
- }
67
- }
68
- return null;
69
- }
70
-
71
- // Start server
72
-
73
-
74
- server.listen(port, () => {
75
- const localIp = getLocalNetworkIp();
76
- console.log(`App is running on http://localhost:${port}`);
77
- if (localIp) {
78
- console.log(
79
- `App is also accessible on your local network at http://${localIp}:${port}`
80
- );
81
- }
82
- });