* Embedded mode: serve the pre-built studio SPA with a standalone Hono server. * Works without any additional dependencies — the studio is bundled in dist/. * * If an existing HyperFrames server for the same project is detected, * reuses it instead of starting a new one (unless --force-new is se
( dir: string, startPort: number, options?: EmbeddedStudioOptions, )
| 833 | * reuses it instead of starting a new one (unless --force-new is set). |
| 834 | */ |
| 835 | async function runEmbeddedMode( |
| 836 | dir: string, |
| 837 | startPort: number, |
| 838 | options?: EmbeddedStudioOptions, |
| 839 | ): Promise<void> { |
| 840 | const { createStudioServer, loadPreviewServerBuildSignature, resolveStudioBundle } = |
| 841 | await import("../server/studioServer.js"); |
| 842 | |
| 843 | const pName = options?.projectName ?? basename(dir); |
| 844 | const studioBundle = resolveStudioBundle(); |
| 845 | |
| 846 | clack.intro(c.bold("hyperframes preview")); |
| 847 | const s = clack.spinner(); |
| 848 | s.start("Starting studio..."); |
| 849 | |
| 850 | if (!studioBundle.available) { |
| 851 | s.stop(c.error("Studio build missing")); |
| 852 | console.error(); |
| 853 | console.error(` ${c.dim("Could not find")} ${c.accent("index.html")} ${c.dim("in:")}`); |
| 854 | for (const checkedPath of studioBundle.checkedPaths) { |
| 855 | console.error(` ${c.dim("-")} ${checkedPath}`); |
| 856 | } |
| 857 | console.error(); |
| 858 | console.error(` ${c.dim("Rebuild the CLI package with")} ${c.accent("bun run build")}`); |
| 859 | console.error(); |
| 860 | process.exitCode = 1; |
| 861 | return; |
| 862 | } |
| 863 | |
| 864 | const { app } = createStudioServer({ projectDir: dir, projectName: pName }); |
| 865 | const serverBuildSignature = await loadPreviewServerBuildSignature(); |
| 866 | |
| 867 | let result: FindPortResult; |
| 868 | try { |
| 869 | result = await findPortAndServe( |
| 870 | app.fetch, |
| 871 | startPort, |
| 872 | dir, |
| 873 | !!options?.forceNew, |
| 874 | serverBuildSignature, |
| 875 | ); |
| 876 | } catch (err: unknown) { |
| 877 | s.stop(c.error("Failed to start studio")); |
| 878 | console.error(); |
| 879 | console.error(` ${(err as Error).message}`); |
| 880 | console.error(); |
| 881 | process.exitCode = 1; |
| 882 | return; |
| 883 | } |
| 884 | |
| 885 | if (result.type === "already-running") { |
| 886 | const url = `http://localhost:${result.port}`; |
| 887 | s.stop(c.success("Already running")); |
| 888 | printStudioSummary(pName, url, { |
| 889 | details: ["Reusing existing server. Use --force-new to start a fresh instance."], |
| 890 | }); |
| 891 | openStudioBrowser(url, pName, options); |
| 892 | return; |
no test coverage detected