UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

1 lines • 12.4 kB
{"version":3,"file":"daemon.js","names":[],"sources":["esm/cli/daemon.js"],"sourcesContent":["import colors from \"picocolors\";\nimport { labelProcess } from \"./label-process\";\nasync function daemon(args) {\n const subcommand = args.subcommand || \"run\";\n switch (subcommand) {\n case \"run\":\n case \"start\":\n return daemonStart(args);\n case \"stop\":\n return daemonStop();\n case \"status\":\n return daemonStatus();\n case \"route\":\n return daemonRoute(args);\n default:\n console.log(`Unknown daemon subcommand: ${subcommand}`);\n console.log(\"Available: start, stop, status, route\");\n process.exit(1);\n }\n}\nasync function daemonStart(args) {\n labelProcess(\"daemon\");\n const { isDaemonRunning } = await import(\"../daemon/ipc\");\n if (await isDaemonRunning()) {\n console.log(colors.yellow(\"Daemon is already running\"));\n console.log(\"Use 'one daemon status' to see registered servers\");\n process.exit(1);\n }\n await suggestTrayApp();\n const { startDaemon } = await import(\"../daemon/server\");\n const useTUI = args.tui ?? process.stdin.isTTY;\n const { state } = await startDaemon({\n port: args.port ? parseInt(args.port, 10) : void 0,\n host: args.host,\n quiet: useTUI\n // suppress normal logs when TUI is active\n });\n if (useTUI) {\n const { startTUI } = await import(\"../daemon/tui\");\n startTUI(state);\n }\n}\nasync function daemonStop() {\n const { isDaemonRunning, getSocketPath } = await import(\"../daemon/ipc\");\n if (!await isDaemonRunning()) {\n console.log(colors.yellow(\"Daemon is not running\"));\n process.exit(1);\n }\n console.log(\n colors.yellow(\n \"Note: daemon runs in foreground. Press Ctrl+C in the daemon terminal to stop.\"\n )\n );\n console.log(colors.dim(`Socket path: ${getSocketPath()}`));\n}\nasync function daemonStatus() {\n const { isDaemonRunning, getDaemonStatus, getLastActiveDaemonServer } = await import(\"../daemon/ipc\");\n if (!await isDaemonRunning()) {\n console.log(colors.yellow(\"Daemon is not running\"));\n console.log(colors.dim(\"Start with 'one daemon'\"));\n process.exit(1);\n }\n try {\n const status = await getDaemonStatus();\n const lastActive = await getLastActiveDaemonServer();\n console.log(colors.cyan(\"\\n\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\"));\n console.log(colors.cyan(\" one daemon status\"));\n console.log(colors.cyan(\"\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\u2550\\n\"));\n if (status.servers.length === 0) {\n console.log(colors.dim(\" No servers registered\"));\n } else {\n console.log(\" Registered servers:\");\n for (const server of status.servers) {\n const shortRoot = server.root.replace(process.env.HOME || \"\", \"~\");\n const isActive = lastActive?.id === server.id;\n const activeMarker = isActive ? colors.yellow(\" \\u2605\") : \"\";\n console.log(\n ` ${colors.green(server.id)} ${server.bundleId} \\u2192 :${server.port} (${shortRoot})${activeMarker}`\n );\n }\n if (lastActive) {\n console.log(colors.dim(\"\\n \\u2605 = last active (used by oi/oa)\"));\n }\n }\n if (status.routes.length > 0) {\n console.log(\"\\n Active routes:\");\n for (const route of status.routes) {\n console.log(` ${route.key} \\u2192 ${route.serverId}`);\n }\n }\n console.log(\"\");\n } catch (err) {\n console.log(colors.red(\"Failed to get daemon status\"));\n console.error(err);\n process.exit(1);\n }\n}\nasync function openPlatform(platform) {\n const { isDaemonRunning, getDaemonStatus, setDaemonRoute, touchDaemonServer } = await import(\"../daemon/ipc\");\n const { getBundleIdFromConfig } = await import(\"../daemon/utils\");\n const cwd = process.cwd();\n const bundleId = getBundleIdFromConfig(cwd);\n if (!bundleId) {\n console.log(colors.yellow(\"No app.json found in current directory\"));\n console.log(colors.dim(\"Run this command from a One project directory\"));\n process.exit(1);\n }\n if (await isDaemonRunning()) {\n try {\n const status = await getDaemonStatus();\n const server = status.servers.find((s) => s.root === cwd);\n if (server) {\n await setDaemonRoute(bundleId, server.id);\n await touchDaemonServer(server.id);\n console.log(colors.cyan(`[daemon] Route set: ${bundleId} \\u2192 this project`));\n } else {\n console.log(colors.yellow(`[daemon] No server registered for this project`));\n console.log(\n colors.dim(`Run 'one dev' first, or the simulator will connect directly`)\n );\n }\n } catch (err) {\n console.log(colors.dim(`[daemon] Could not set route: ${err}`));\n }\n }\n if (platform === \"ios\") {\n const { run } = await import(\"./runIos\");\n await run({});\n } else {\n const { run } = await import(\"./runAndroid\");\n await run({});\n }\n}\nasync function daemonRoute(args) {\n const { isDaemonRunning, getDaemonStatus, setDaemonRoute } = await import(\"../daemon/ipc\");\n if (!await isDaemonRunning()) {\n console.log(colors.yellow(\"Daemon is not running\"));\n process.exit(1);\n }\n if (!args.app) {\n console.log(colors.red(\"Missing --app parameter\"));\n console.log(\"Usage: one daemon route --app=com.example.app --slot=0\");\n console.log(\" or: one daemon route --app=com.example.app --project=~/myapp\");\n process.exit(1);\n }\n const status = await getDaemonStatus();\n let targetServer;\n if (args.slot !== void 0) {\n const slotIndex = parseInt(args.slot, 10);\n const matchingServers = status.servers.filter((s) => s.bundleId === args.app);\n if (slotIndex < 0 || slotIndex >= matchingServers.length) {\n console.log(colors.red(`Invalid slot: ${args.slot}`));\n console.log(`Available slots for ${args.app}: 0-${matchingServers.length - 1}`);\n process.exit(1);\n }\n targetServer = matchingServers[slotIndex];\n } else if (args.project) {\n const normalizedProject = args.project.replace(/^~/, process.env.HOME || \"\");\n targetServer = status.servers.find(\n (s) => s.bundleId === args.app && s.root === normalizedProject\n );\n if (!targetServer) {\n console.log(colors.red(`No server found for ${args.app} at ${args.project}`));\n process.exit(1);\n }\n } else {\n console.log(colors.red(\"Missing --slot or --project parameter\"));\n process.exit(1);\n }\n await setDaemonRoute(args.app, targetServer.id);\n const shortRoot = targetServer.root.replace(process.env.HOME || \"\", \"~\");\n console.log(colors.green(`Route set: ${args.app} \\u2192 ${targetServer.id} (${shortRoot})`));\n}\nasync function suggestTrayApp() {\n const { existsSync } = await import(\"node:fs\");\n const trayPaths = [\n \"/Applications/OneTray.app\",\n `${process.env.HOME}/Applications/OneTray.app`\n ];\n const installed = trayPaths.some((p) => existsSync(p));\n if (!installed) {\n console.log(\n colors.dim(\" Tip: install OneTray.app for a native macOS cable interface\")\n );\n console.log(colors.dim(\" https://github.com/onejs/one/releases?q=one-tray\"));\n console.log(\"\");\n }\n}\nexport {\n daemon,\n openPlatform\n};\n//# sourceMappingURL=daemon.js.map\n"],"mappings":";;;;AAEA,eAAe,OAAO,MAAM;CAC1B,MAAM,aAAa,KAAK,cAAc;CACtC,QAAQ,YAAR;EACE,KAAK;EACL,KAAK,SACH,OAAO,YAAY,IAAI;EACzB,KAAK,QACH,OAAO,WAAW;EACpB,KAAK,UACH,OAAO,aAAa;EACtB,KAAK,SACH,OAAO,YAAY,IAAI;EACzB;GACE,QAAQ,IAAI,8BAA8B,YAAY;GACtD,QAAQ,IAAI,uCAAuC;GACnD,QAAQ,KAAK,CAAC;CAClB;AACF;AACA,eAAe,YAAY,MAAM;CAC/B,aAAa,QAAQ;CACrB,MAAM,EAAE,oBAAoB,MAAM,OAAO;CACzC,IAAI,MAAM,gBAAgB,GAAG;EAC3B,QAAQ,IAAI,OAAO,OAAO,2BAA2B,CAAC;EACtD,QAAQ,IAAI,mDAAmD;EAC/D,QAAQ,KAAK,CAAC;CAChB;CACA,MAAM,eAAe;CACrB,MAAM,EAAE,gBAAgB,MAAM,OAAO;CACrC,MAAM,SA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