MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / runEmbeddedMode

Function runEmbeddedMode

packages/cli/src/commands/preview.ts:835–975  ·  view source on GitHub ↗

* 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,
)

Source from the content-addressed store, hash-verified

833 * reuses it instead of starting a new one (unless --force-new is set).
834 */
835async 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;

Callers 1

runFunction · 0.85

Calls 14

basenameFunction · 0.85
resolveStudioBundleFunction · 0.85
createStudioServerFunction · 0.85
findPortAndServeFunction · 0.85
printStudioSummaryFunction · 0.85
openStudioBrowserFunction · 0.85
killTrackedProcessesFunction · 0.85
errorMethod · 0.80
warnMethod · 0.80
onceMethod · 0.80
onMethod · 0.65

Tested by

no test coverage detected