@kohryan/moodui 0.0.14 → 0.0.15

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/dist/cli.mjs CHANGED
@@ -1164,8 +1164,32 @@ async function runUI() {
1164
1164
  uiDir = path2.join(__dirname2, "..", "dist", "ui");
1165
1165
  }
1166
1166
  const PORT = 3e3;
1167
- console.log(`Starting MoodUI UI...`);
1167
+ const workingDir = process.cwd();
1168
+ console.log(`Starting MoodUI UI at http://localhost:${PORT}`);
1169
+ console.log(`Working directory: ${workingDir}`);
1168
1170
  const server = http.createServer(async (req, res) => {
1171
+ if (req.method === "POST" && req.url === "/api/save-file") {
1172
+ try {
1173
+ let body = "";
1174
+ for await (const chunk of req) {
1175
+ body += chunk.toString();
1176
+ }
1177
+ const { path: filePath2, code } = JSON.parse(body);
1178
+ const resolvedOut = path2.resolve(workingDir, filePath2);
1179
+ await fs6.mkdir(path2.dirname(resolvedOut), { recursive: true });
1180
+ await fs6.writeFile(resolvedOut, code, "utf8");
1181
+ res.writeHead(200, { "Content-Type": "application/json" });
1182
+ res.end(JSON.stringify({ success: true, path: resolvedOut }));
1183
+ console.log(`OK: wrote ${resolvedOut}`);
1184
+ return;
1185
+ } catch (err) {
1186
+ const errorMsg = err instanceof Error ? err.message : String(err);
1187
+ res.writeHead(500, { "Content-Type": "application/json" });
1188
+ res.end(JSON.stringify({ success: false, error: errorMsg }));
1189
+ console.error(`Error saving file: ${errorMsg}`);
1190
+ return;
1191
+ }
1192
+ }
1169
1193
  let filePath = path2.join(uiDir, req.url === "/" ? "index.html" : req.url);
1170
1194
  const extname = String(path2.extname(filePath)).toLowerCase();
1171
1195
  const mimeTypes = {