( child: StudioChildProcess, spinner: ReturnType<typeof clack.spinner>, projectName: string, options?: BrowserLaunchOptions, )
| 716 | } |
| 717 | |
| 718 | function attachStudioReadyHandler( |
| 719 | child: StudioChildProcess, |
| 720 | spinner: ReturnType<typeof clack.spinner>, |
| 721 | projectName: string, |
| 722 | options?: BrowserLaunchOptions, |
| 723 | ): void { |
| 724 | let detected = false; |
| 725 | |
| 726 | function handleOutput(data: Buffer): void { |
| 727 | const url = data.toString().match(/Local:\s+(http:\/\/localhost:\d+)/)?.[1]; |
| 728 | if (!url || detected) return; |
| 729 | |
| 730 | detected = true; |
| 731 | spinner.stop(c.success("Studio running")); |
| 732 | printStudioSummary(projectName, url, { footer: "Press Ctrl+C to stop" }); |
| 733 | openStudioBrowser(url, projectName, options); |
| 734 | child.stdout.removeListener("data", handleOutput); |
| 735 | child.stderr.removeListener("data", handleOutput); |
| 736 | } |
| 737 | |
| 738 | child.stdout.on("data", handleOutput); |
| 739 | child.stderr.on("data", handleOutput); |
| 740 | child.on("error", (err) => { |
| 741 | spinner.stop(c.error("Failed to start studio")); |
| 742 | console.error(c.dim(err.message)); |
| 743 | }); |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * Dev mode: spawn the studio dev server from the monorepo. |
no test coverage detected