code-mon-config 1.0.0 → 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 +74 -114
- package/package.json +2 -20
package/index.js
CHANGED
|
@@ -1,155 +1,115 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const express = require("express")
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const { exec } = require("child_process")
|
|
3
|
+
const express = require("express");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const cors = require("cors");
|
|
7
|
+
const { exec } = require("child_process");
|
|
8
8
|
|
|
9
|
-
const app = express()
|
|
10
|
-
const PORT = 3210
|
|
9
|
+
const app = express();
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
app.use(cors());
|
|
12
|
+
app.use(express.json());
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
app.use(express.json())
|
|
20
|
-
|
|
21
|
-
// allow requests from any website (you can restrict later)
|
|
22
|
-
app.use(cors({
|
|
23
|
-
origin: "*"
|
|
24
|
-
}))
|
|
25
|
-
|
|
26
|
-
// health check
|
|
27
|
-
app.get("/", (req, res) => {
|
|
28
|
-
res.json({
|
|
29
|
-
name: "code-mon-config",
|
|
30
|
-
status: "running",
|
|
31
|
-
workspace: WORKSPACE
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// 📂 LIST FILES
|
|
37
|
-
app.get("/list", (req, res) => {
|
|
38
|
-
|
|
39
|
-
fs.readdir(WORKSPACE, (err, files) => {
|
|
40
|
-
|
|
41
|
-
if (err) {
|
|
42
|
-
return res.status(500).json({ error: err.message })
|
|
43
|
-
}
|
|
14
|
+
const PORT = process.env.PORT || 3000;
|
|
15
|
+
const FILE_DIR = path.join(process.cwd(), "files");
|
|
44
16
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
17
|
+
if (!fs.existsSync(FILE_DIR)) {
|
|
18
|
+
fs.mkdirSync(FILE_DIR);
|
|
19
|
+
}
|
|
48
20
|
|
|
49
|
-
|
|
21
|
+
/* CREATE FILE */
|
|
22
|
+
app.post("/create", (req, res) => {
|
|
23
|
+
const { filename } = req.body;
|
|
50
24
|
|
|
25
|
+
if (!filename) return res.status(400).json({ error: "filename required" });
|
|
51
26
|
|
|
52
|
-
|
|
53
|
-
app.get("/load", (req, res) => {
|
|
27
|
+
const filePath = path.join(FILE_DIR, filename);
|
|
54
28
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!file) {
|
|
58
|
-
return res.status(400).json({ error: "file parameter required" })
|
|
29
|
+
if (fs.existsSync(filePath)) {
|
|
30
|
+
return res.status(400).json({ error: "File already exists" });
|
|
59
31
|
}
|
|
60
32
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
fs.readFile(filePath, "utf8", (err, data) => {
|
|
64
|
-
|
|
65
|
-
if (err) {
|
|
66
|
-
return res.status(404).json({ error: "file not found" })
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
res.json({ content: data })
|
|
70
|
-
|
|
71
|
-
})
|
|
33
|
+
fs.writeFileSync(filePath, "");
|
|
72
34
|
|
|
73
|
-
})
|
|
35
|
+
res.json({ success: true, filename });
|
|
36
|
+
});
|
|
74
37
|
|
|
75
|
-
|
|
76
|
-
// 💾 SAVE FILE
|
|
38
|
+
/* SAVE FILE */
|
|
77
39
|
app.post("/save", (req, res) => {
|
|
40
|
+
const { filename, content } = req.body;
|
|
78
41
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (!file) {
|
|
82
|
-
return res.status(400).json({ error: "file required" })
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const filePath = path.join(WORKSPACE, file)
|
|
86
|
-
|
|
87
|
-
fs.writeFile(filePath, content || "", err => {
|
|
42
|
+
if (!filename) return res.status(400).json({ error: "filename required" });
|
|
88
43
|
|
|
89
|
-
|
|
90
|
-
return res.status(500).json({ error: err.message })
|
|
91
|
-
}
|
|
44
|
+
const filePath = path.join(FILE_DIR, filename);
|
|
92
45
|
|
|
93
|
-
|
|
46
|
+
fs.writeFileSync(filePath, content || "");
|
|
94
47
|
|
|
95
|
-
})
|
|
48
|
+
res.json({ success: true });
|
|
49
|
+
});
|
|
96
50
|
|
|
97
|
-
|
|
51
|
+
/* LIST FILES */
|
|
52
|
+
app.get("/list", (req, res) => {
|
|
53
|
+
const files = fs.readdirSync(FILE_DIR);
|
|
54
|
+
res.json(files);
|
|
55
|
+
});
|
|
98
56
|
|
|
57
|
+
/* LOAD FILE */
|
|
58
|
+
app.get("/load", (req, res) => {
|
|
59
|
+
const filename = req.query.filename;
|
|
99
60
|
|
|
100
|
-
|
|
101
|
-
app.delete("/delete", (req, res) => {
|
|
61
|
+
if (!filename) return res.status(400).json({ error: "filename required" });
|
|
102
62
|
|
|
103
|
-
const
|
|
63
|
+
const filePath = path.join(FILE_DIR, filename);
|
|
104
64
|
|
|
105
|
-
if (!
|
|
106
|
-
return res.status(
|
|
65
|
+
if (!fs.existsSync(filePath)) {
|
|
66
|
+
return res.status(404).json({ error: "File not found" });
|
|
107
67
|
}
|
|
108
68
|
|
|
109
|
-
const
|
|
69
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
110
70
|
|
|
111
|
-
|
|
71
|
+
res.json({ content });
|
|
72
|
+
});
|
|
112
73
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
res.json({ status: "deleted" })
|
|
74
|
+
/* DELETE FILE */
|
|
75
|
+
app.delete("/delete", (req, res) => {
|
|
76
|
+
const { filename } = req.body;
|
|
118
77
|
|
|
119
|
-
|
|
78
|
+
const filePath = path.join(FILE_DIR, filename);
|
|
120
79
|
|
|
121
|
-
|
|
80
|
+
if (fs.existsSync(filePath)) {
|
|
81
|
+
fs.unlinkSync(filePath);
|
|
82
|
+
}
|
|
122
83
|
|
|
84
|
+
res.json({ success: true });
|
|
85
|
+
});
|
|
123
86
|
|
|
124
|
-
|
|
87
|
+
/* EXECUTE COMMAND */
|
|
125
88
|
app.post("/execute", (req, res) => {
|
|
89
|
+
const { command } = req.body;
|
|
126
90
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (!command) {
|
|
130
|
-
return res.status(400).json({ error: "command required" })
|
|
131
|
-
}
|
|
91
|
+
if (!command) return res.status(400).json({ error: "command required" });
|
|
132
92
|
|
|
133
|
-
exec(command,
|
|
93
|
+
exec(command, (error, stdout, stderr) => {
|
|
134
94
|
|
|
135
|
-
if (
|
|
136
|
-
return res.json({
|
|
95
|
+
if (error) {
|
|
96
|
+
return res.json({
|
|
97
|
+
success: false,
|
|
98
|
+
error: error.message,
|
|
99
|
+
stdout,
|
|
100
|
+
stderr
|
|
101
|
+
});
|
|
137
102
|
}
|
|
138
103
|
|
|
139
|
-
res.json({
|
|
104
|
+
res.json({
|
|
105
|
+
success: true,
|
|
106
|
+
stdout,
|
|
107
|
+
stderr
|
|
108
|
+
});
|
|
140
109
|
|
|
141
|
-
})
|
|
110
|
+
});
|
|
111
|
+
});
|
|
142
112
|
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// start server
|
|
147
113
|
app.listen(PORT, () => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
console.log("🚀 CodeMon Config Running")
|
|
151
|
-
console.log(`📡 Local API: http://localhost:${PORT}`)
|
|
152
|
-
console.log(`📂 Workspace: ${WORKSPACE}`)
|
|
153
|
-
console.log("")
|
|
154
|
-
|
|
155
|
-
})
|
|
114
|
+
console.log(`🚀 CodeMon Config running on http://localhost:${PORT}`);
|
|
115
|
+
});
|
package/package.json
CHANGED
|
@@ -1,26 +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.5",
|
|
21
|
-
"express": "^4.22.1"
|
|
22
|
-
},
|
|
23
|
-
"engines": {
|
|
24
|
-
"node": ">=16"
|
|
25
7
|
}
|
|
26
8
|
}
|