code-mon-config 1.0.1 → 1.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.
- package/index.js +22 -74
- package/package.json +2 -21
package/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
1
3
|
const express = require("express");
|
|
2
4
|
const fs = require("fs");
|
|
3
5
|
const path = require("path");
|
|
@@ -9,24 +11,18 @@ const app = express();
|
|
|
9
11
|
app.use(cors());
|
|
10
12
|
app.use(express.json());
|
|
11
13
|
|
|
12
|
-
const PORT = 3000;
|
|
14
|
+
const PORT = process.env.PORT || 3000;
|
|
13
15
|
const FILE_DIR = path.join(process.cwd(), "files");
|
|
14
16
|
|
|
15
|
-
// create files directory if not exists
|
|
16
17
|
if (!fs.existsSync(FILE_DIR)) {
|
|
17
18
|
fs.mkdirSync(FILE_DIR);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
/*
|
|
21
|
-
CREATE FILE
|
|
22
|
-
POST /create
|
|
23
|
-
*/
|
|
21
|
+
/* CREATE FILE */
|
|
24
22
|
app.post("/create", (req, res) => {
|
|
25
23
|
const { filename } = req.body;
|
|
26
24
|
|
|
27
|
-
if (!filename) {
|
|
28
|
-
return res.status(400).json({ error: "filename required" });
|
|
29
|
-
}
|
|
25
|
+
if (!filename) return res.status(400).json({ error: "filename required" });
|
|
30
26
|
|
|
31
27
|
const filePath = path.join(FILE_DIR, filename);
|
|
32
28
|
|
|
@@ -36,57 +32,33 @@ app.post("/create", (req, res) => {
|
|
|
36
32
|
|
|
37
33
|
fs.writeFileSync(filePath, "");
|
|
38
34
|
|
|
39
|
-
res.json({
|
|
40
|
-
success: true,
|
|
41
|
-
message: "File created",
|
|
42
|
-
filename
|
|
43
|
-
});
|
|
35
|
+
res.json({ success: true, filename });
|
|
44
36
|
});
|
|
45
37
|
|
|
46
|
-
/*
|
|
47
|
-
SAVE FILE
|
|
48
|
-
POST /save
|
|
49
|
-
*/
|
|
38
|
+
/* SAVE FILE */
|
|
50
39
|
app.post("/save", (req, res) => {
|
|
51
40
|
const { filename, content } = req.body;
|
|
52
41
|
|
|
53
|
-
if (!filename) {
|
|
54
|
-
return res.status(400).json({ error: "filename required" });
|
|
55
|
-
}
|
|
42
|
+
if (!filename) return res.status(400).json({ error: "filename required" });
|
|
56
43
|
|
|
57
44
|
const filePath = path.join(FILE_DIR, filename);
|
|
58
45
|
|
|
59
46
|
fs.writeFileSync(filePath, content || "");
|
|
60
47
|
|
|
61
|
-
res.json({
|
|
62
|
-
success: true,
|
|
63
|
-
message: "File saved"
|
|
64
|
-
});
|
|
48
|
+
res.json({ success: true });
|
|
65
49
|
});
|
|
66
50
|
|
|
67
|
-
/*
|
|
68
|
-
LIST FILES
|
|
69
|
-
GET /list
|
|
70
|
-
*/
|
|
51
|
+
/* LIST FILES */
|
|
71
52
|
app.get("/list", (req, res) => {
|
|
72
53
|
const files = fs.readdirSync(FILE_DIR);
|
|
73
|
-
|
|
74
|
-
res.json({
|
|
75
|
-
success: true,
|
|
76
|
-
files
|
|
77
|
-
});
|
|
54
|
+
res.json(files);
|
|
78
55
|
});
|
|
79
56
|
|
|
80
|
-
/*
|
|
81
|
-
LOAD FILE CONTENT
|
|
82
|
-
GET /load?filename=test.js
|
|
83
|
-
*/
|
|
57
|
+
/* LOAD FILE */
|
|
84
58
|
app.get("/load", (req, res) => {
|
|
85
59
|
const filename = req.query.filename;
|
|
86
60
|
|
|
87
|
-
if (!filename) {
|
|
88
|
-
return res.status(400).json({ error: "filename required" });
|
|
89
|
-
}
|
|
61
|
+
if (!filename) return res.status(400).json({ error: "filename required" });
|
|
90
62
|
|
|
91
63
|
const filePath = path.join(FILE_DIR, filename);
|
|
92
64
|
|
|
@@ -96,50 +68,29 @@ app.get("/load", (req, res) => {
|
|
|
96
68
|
|
|
97
69
|
const content = fs.readFileSync(filePath, "utf8");
|
|
98
70
|
|
|
99
|
-
res.json({
|
|
100
|
-
success: true,
|
|
101
|
-
filename,
|
|
102
|
-
content
|
|
103
|
-
});
|
|
71
|
+
res.json({ content });
|
|
104
72
|
});
|
|
105
73
|
|
|
106
|
-
/*
|
|
107
|
-
DELETE FILE
|
|
108
|
-
DELETE /delete
|
|
109
|
-
*/
|
|
74
|
+
/* DELETE FILE */
|
|
110
75
|
app.delete("/delete", (req, res) => {
|
|
111
76
|
const { filename } = req.body;
|
|
112
77
|
|
|
113
|
-
if (!filename) {
|
|
114
|
-
return res.status(400).json({ error: "filename required" });
|
|
115
|
-
}
|
|
116
|
-
|
|
117
78
|
const filePath = path.join(FILE_DIR, filename);
|
|
118
79
|
|
|
119
|
-
if (
|
|
120
|
-
|
|
80
|
+
if (fs.existsSync(filePath)) {
|
|
81
|
+
fs.unlinkSync(filePath);
|
|
121
82
|
}
|
|
122
83
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
res.json({
|
|
126
|
-
success: true,
|
|
127
|
-
message: "File deleted"
|
|
128
|
-
});
|
|
84
|
+
res.json({ success: true });
|
|
129
85
|
});
|
|
130
86
|
|
|
131
|
-
/*
|
|
132
|
-
EXECUTE COMMAND
|
|
133
|
-
POST /execute
|
|
134
|
-
*/
|
|
87
|
+
/* EXECUTE COMMAND */
|
|
135
88
|
app.post("/execute", (req, res) => {
|
|
136
89
|
const { command } = req.body;
|
|
137
90
|
|
|
138
|
-
if (!command) {
|
|
139
|
-
return res.status(400).json({ error: "command required" });
|
|
140
|
-
}
|
|
91
|
+
if (!command) return res.status(400).json({ error: "command required" });
|
|
141
92
|
|
|
142
|
-
exec(command,
|
|
93
|
+
exec(command, (error, stdout, stderr) => {
|
|
143
94
|
|
|
144
95
|
if (error) {
|
|
145
96
|
return res.json({
|
|
@@ -159,9 +110,6 @@ app.post("/execute", (req, res) => {
|
|
|
159
110
|
});
|
|
160
111
|
});
|
|
161
112
|
|
|
162
|
-
/*
|
|
163
|
-
START SERVER
|
|
164
|
-
*/
|
|
165
113
|
app.listen(PORT, () => {
|
|
166
|
-
console.log(`🚀 CodeMon Config running
|
|
114
|
+
console.log(`🚀 CodeMon Config running on http://localhost:${PORT}`);
|
|
167
115
|
});
|
package/package.json
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "code-mon-config",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"main": "index.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"code-mon-config": "./index.js"
|
|
7
|
-
},
|
|
8
|
-
"scripts": {
|
|
9
|
-
"start": "node index.js"
|
|
10
|
-
},
|
|
11
|
-
"keywords": [
|
|
12
|
-
"codemon",
|
|
13
|
-
"terminal",
|
|
14
|
-
"local-api",
|
|
15
|
-
"dev-tools"
|
|
16
|
-
],
|
|
17
|
-
"author": "Your Name",
|
|
18
|
-
"license": "MIT",
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"cors": "^2.8.6",
|
|
21
|
-
"express": "^4.22.1",
|
|
22
|
-
"ws": "^8.19.0"
|
|
23
|
-
},
|
|
24
|
-
"engines": {
|
|
25
|
-
"node": ">=16"
|
|
26
7
|
}
|
|
27
8
|
}
|