openmagic 0.29.4 → 0.30.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.
package/dist/cli.js CHANGED
@@ -1449,7 +1449,7 @@ async function handleLlmChat(params, onChunk, onDone, onError) {
1449
1449
  }
1450
1450
 
1451
1451
  // src/server.ts
1452
- var VERSION = "0.29.4";
1452
+ var VERSION = "0.30.0";
1453
1453
  var __dirname = dirname2(fileURLToPath(import.meta.url));
1454
1454
  function attachOpenMagic(httpServer, roots) {
1455
1455
  function handleRequest(req, res) {
@@ -1991,7 +1991,7 @@ process.on("uncaughtException", (err) => {
1991
1991
  });
1992
1992
  var childProcesses = [];
1993
1993
  var lastDetectedPort = null;
1994
- var VERSION2 = "0.29.4";
1994
+ var VERSION2 = "0.30.0";
1995
1995
  function ask(question) {
1996
1996
  const rl = createInterface({ input: process.stdin, output: process.stdout });
1997
1997
  return new Promise((resolve3) => {
@@ -2217,8 +2217,58 @@ async function offerToStartDevServer(expectedPort) {
2217
2217
  const projectName = getProjectName();
2218
2218
  const scripts = detectDevScripts();
2219
2219
  if (scripts.length === 0) {
2220
+ const htmlPath = join5(process.cwd(), "index.html");
2221
+ if (existsSync5(htmlPath)) {
2222
+ console.log(
2223
+ chalk.dim(" No dev scripts found, but index.html detected.")
2224
+ );
2225
+ console.log("");
2226
+ const answer = await ask(
2227
+ chalk.white(" Serve this directory as a static site? ") + chalk.dim("(Y/n) ")
2228
+ );
2229
+ if (answer.toLowerCase() === "n" || answer.toLowerCase() === "no") {
2230
+ return false;
2231
+ }
2232
+ const staticPort = expectedPort || 8080;
2233
+ console.log(chalk.dim(` Starting static server on port ${staticPort}...`));
2234
+ const staticChild = spawn("node", ["-e", `
2235
+ const http = require("http");
2236
+ const fs = require("fs");
2237
+ const path = require("path");
2238
+ const mimes = {".html":"text/html",".css":"text/css",".js":"application/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".svg":"image/svg+xml",".ico":"image/x-icon",".gif":"image/gif",".woff2":"font/woff2",".woff":"font/woff"};
2239
+ http.createServer((req, res) => {
2240
+ let p = path.join(${JSON.stringify(process.cwd())}, req.url === "/" ? "/index.html" : req.url);
2241
+ try { p = decodeURIComponent(p); } catch {}
2242
+ fs.readFile(p, (err, data) => {
2243
+ if (err) { res.writeHead(404); res.end("Not found"); return; }
2244
+ const ext = path.extname(p).toLowerCase();
2245
+ res.writeHead(200, {"Content-Type": mimes[ext] || "application/octet-stream"});
2246
+ res.end(data);
2247
+ });
2248
+ }).listen(${staticPort}, "localhost", () => console.log("Static server ready on port ${staticPort}"));
2249
+ `], {
2250
+ cwd: process.cwd(),
2251
+ stdio: ["ignore", "pipe", "pipe"],
2252
+ detached: false
2253
+ });
2254
+ childProcesses.push(staticChild);
2255
+ staticChild.stdout?.on("data", (d) => {
2256
+ for (const line of d.toString().trim().split("\n")) {
2257
+ if (line.trim()) process.stdout.write(chalk.dim(` \u2502 ${line}
2258
+ `));
2259
+ }
2260
+ });
2261
+ const up = await waitForPort(staticPort, 5e3);
2262
+ if (up) {
2263
+ lastDetectedPort = staticPort;
2264
+ console.log(chalk.green(` \u2713 Static server running on port ${staticPort}`));
2265
+ return true;
2266
+ }
2267
+ console.log(chalk.red(" \u2717 Failed to start static server."));
2268
+ return false;
2269
+ }
2220
2270
  console.log(
2221
- chalk.yellow(" \u26A0 No dev server detected and no dev scripts found in package.json")
2271
+ chalk.yellow(" \u26A0 No dev server detected and no dev scripts found.")
2222
2272
  );
2223
2273
  console.log("");
2224
2274
  console.log(chalk.white(" Start your dev server manually, then run:"));