code-mon-config 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 (2) hide show
  1. package/index.js +155 -0
  2. package/package.json +26 -0
package/index.js ADDED
@@ -0,0 +1,155 @@
1
+ #!/usr/bin/env node
2
+
3
+ const express = require("express")
4
+ const cors = require("cors")
5
+ const fs = require("fs")
6
+ const path = require("path")
7
+ const { exec } = require("child_process")
8
+
9
+ const app = express()
10
+ const PORT = 3210
11
+
12
+ // workspace folder
13
+ const WORKSPACE = path.join(process.cwd(), "codemon-workspace")
14
+
15
+ if (!fs.existsSync(WORKSPACE)) {
16
+ fs.mkdirSync(WORKSPACE)
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
+ }
44
+
45
+ res.json({ files })
46
+
47
+ })
48
+
49
+ })
50
+
51
+
52
+ // 📄 LOAD FILE
53
+ app.get("/load", (req, res) => {
54
+
55
+ const file = req.query.file
56
+
57
+ if (!file) {
58
+ return res.status(400).json({ error: "file parameter required" })
59
+ }
60
+
61
+ const filePath = path.join(WORKSPACE, file)
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
+ })
72
+
73
+ })
74
+
75
+
76
+ // 💾 SAVE FILE
77
+ app.post("/save", (req, res) => {
78
+
79
+ const { file, content } = req.body
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 => {
88
+
89
+ if (err) {
90
+ return res.status(500).json({ error: err.message })
91
+ }
92
+
93
+ res.json({ status: "saved" })
94
+
95
+ })
96
+
97
+ })
98
+
99
+
100
+ // 🗑 DELETE FILE
101
+ app.delete("/delete", (req, res) => {
102
+
103
+ const { file } = req.body
104
+
105
+ if (!file) {
106
+ return res.status(400).json({ error: "file required" })
107
+ }
108
+
109
+ const filePath = path.join(WORKSPACE, file)
110
+
111
+ fs.unlink(filePath, err => {
112
+
113
+ if (err) {
114
+ return res.status(404).json({ error: "file not found" })
115
+ }
116
+
117
+ res.json({ status: "deleted" })
118
+
119
+ })
120
+
121
+ })
122
+
123
+
124
+ // âš¡ EXECUTE COMMAND
125
+ app.post("/execute", (req, res) => {
126
+
127
+ const { command } = req.body
128
+
129
+ if (!command) {
130
+ return res.status(400).json({ error: "command required" })
131
+ }
132
+
133
+ exec(command, { cwd: WORKSPACE }, (err, stdout, stderr) => {
134
+
135
+ if (err) {
136
+ return res.json({ error: stderr })
137
+ }
138
+
139
+ res.json({ output: stdout })
140
+
141
+ })
142
+
143
+ })
144
+
145
+
146
+ // start server
147
+ app.listen(PORT, () => {
148
+
149
+ console.log("")
150
+ console.log("🚀 CodeMon Config Running")
151
+ console.log(`📡 Local API: http://localhost:${PORT}`)
152
+ console.log(`📂 Workspace: ${WORKSPACE}`)
153
+ console.log("")
154
+
155
+ })
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "code-mon-config",
3
+ "version": "1.0.0",
4
+ "description": "Local configuration and terminal API for CodeMon",
5
+ "bin": {
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
+ }
26
+ }