openmagic 0.28.6 → 0.29.1

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
@@ -4,7 +4,8 @@
4
4
  import { Command } from "commander";
5
5
  import chalk from "chalk";
6
6
  import open from "open";
7
- import { resolve as resolve2 } from "path";
7
+ import { resolve as resolve2, join as join5 } from "path";
8
+ import { existsSync as existsSync5, readFileSync as readFileSync5 } from "fs";
8
9
  import { spawn } from "child_process";
9
10
  import { createInterface } from "readline";
10
11
 
@@ -1448,7 +1449,7 @@ async function handleLlmChat(params, onChunk, onDone, onError) {
1448
1449
  }
1449
1450
 
1450
1451
  // src/server.ts
1451
- var VERSION = "0.28.6";
1452
+ var VERSION = "0.29.1";
1452
1453
  var __dirname = dirname2(fileURLToPath(import.meta.url));
1453
1454
  function attachOpenMagic(httpServer, roots) {
1454
1455
  function handleRequest(req, res) {
@@ -1862,7 +1863,7 @@ async function detectDevServer() {
1862
1863
  if (scriptPorts.length > 0) {
1863
1864
  for (const port of scriptPorts) {
1864
1865
  if (await checkPort(port)) {
1865
- return { port, host: "localhost" };
1866
+ return { port, host: "localhost", fromScripts: true };
1866
1867
  }
1867
1868
  }
1868
1869
  return null;
@@ -1874,7 +1875,7 @@ async function detectDevServer() {
1874
1875
  const results = await Promise.all(checks);
1875
1876
  const foundPort = results.find((p) => p !== null);
1876
1877
  if (foundPort) {
1877
- return { port: foundPort, host: "127.0.0.1" };
1878
+ return { port: foundPort, host: "localhost", fromScripts: false };
1878
1879
  }
1879
1880
  return null;
1880
1881
  }
@@ -1902,7 +1903,7 @@ var FRAMEWORK_PATTERNS = [
1902
1903
  { match: /\brails\b/, framework: "Rails", defaultPort: 3e3 },
1903
1904
  { match: /\bphp\s+.*serve\b|artisan\s+serve/, framework: "PHP/Laravel", defaultPort: 8e3 }
1904
1905
  ];
1905
- var DEV_SCRIPT_NAMES = ["dev", "start", "serve", "develop", "dev:start", "start:dev"];
1906
+ var DEV_SCRIPT_NAMES = ["dev", "start", "serve", "develop", "dev:start", "start:dev", "server", "dev:server", "web", "frontend"];
1906
1907
  function detectDevScripts(cwd = process.cwd()) {
1907
1908
  const pkgPath = join4(cwd, "package.json");
1908
1909
  if (!existsSync4(pkgPath)) return [];
@@ -1990,7 +1991,7 @@ process.on("uncaughtException", (err) => {
1990
1991
  });
1991
1992
  var childProcesses = [];
1992
1993
  var lastDetectedPort = null;
1993
- var VERSION2 = "0.28.6";
1994
+ var VERSION2 = "0.29.1";
1994
1995
  function ask(question) {
1995
1996
  const rl = createInterface({ input: process.stdin, output: process.stdout });
1996
1997
  return new Promise((resolve3) => {
@@ -2128,9 +2129,23 @@ program.name("openmagic").description("AI-powered coding toolbar for any web app
2128
2129
  } else {
2129
2130
  console.log(chalk.dim(" Scanning for dev server..."));
2130
2131
  const detected = await detectDevServer();
2131
- if (detected) {
2132
+ if (detected && detected.fromScripts) {
2132
2133
  targetPort = detected.port;
2133
2134
  targetHost = detected.host;
2135
+ } else if (detected && !detected.fromScripts) {
2136
+ const answer = await ask(
2137
+ chalk.yellow(` Found a server on port ${detected.port}. Is this your project's dev server? `) + chalk.dim("(y/n) ")
2138
+ );
2139
+ if (answer.toLowerCase() === "y" || answer.toLowerCase() === "yes" || answer === "") {
2140
+ targetPort = detected.port;
2141
+ targetHost = detected.host;
2142
+ } else {
2143
+ console.log("");
2144
+ console.log(chalk.dim(" Start your dev server, then run:"));
2145
+ console.log(chalk.cyan(" npx openmagic --port <your-port>"));
2146
+ console.log("");
2147
+ process.exit(0);
2148
+ }
2134
2149
  } else {
2135
2150
  const started = await offerToStartDevServer();
2136
2151
  if (!started) {
@@ -2403,12 +2418,26 @@ async function offerToStartDevServer(expectedPort) {
2403
2418
  }
2404
2419
  if (childExited && !isUp) {
2405
2420
  console.log(
2406
- chalk.red(` \u2717 Dev server exited before it was ready.`)
2407
- );
2408
- console.log(
2409
- chalk.dim(` Check the error output above and fix the issue.`)
2421
+ chalk.red(` \u2717 Dev server failed to start.`)
2410
2422
  );
2411
2423
  console.log("");
2424
+ try {
2425
+ const pkgPath = join5(process.cwd(), "package.json");
2426
+ if (existsSync5(pkgPath)) {
2427
+ const pkg = JSON.parse(readFileSync5(pkgPath, "utf-8"));
2428
+ if (pkg.engines?.node) {
2429
+ console.log(chalk.yellow(` This project requires Node.js ${pkg.engines.node}`));
2430
+ console.log(chalk.dim(` You are running Node.js ${process.version}`));
2431
+ console.log("");
2432
+ }
2433
+ }
2434
+ } catch {
2435
+ }
2436
+ console.log(chalk.white(" Options:"));
2437
+ console.log(chalk.dim(" 1. Fix the error above and try again"));
2438
+ console.log(chalk.dim(" 2. Start the server manually, then run:"));
2439
+ console.log(chalk.cyan(" npx openmagic --port <your-port>"));
2440
+ console.log("");
2412
2441
  return false;
2413
2442
  }
2414
2443
  if (!isUp) {