( projectDir: string, startPort: number, json: boolean, preferredPort?: number, )
| 360 | } |
| 361 | |
| 362 | async function printCurrentSelection( |
| 363 | projectDir: string, |
| 364 | startPort: number, |
| 365 | json: boolean, |
| 366 | preferredPort?: number, |
| 367 | ): Promise<void> { |
| 368 | const { |
| 369 | AmbiguousPreviewServerError, |
| 370 | PreviewServerPortMismatchError, |
| 371 | fetchStudioSelection, |
| 372 | findPreviewServerForProject, |
| 373 | } = await import("../utils/studioSelectionClient.js"); |
| 374 | let server: Awaited<ReturnType<typeof findPreviewServerForProject>>; |
| 375 | try { |
| 376 | server = await findPreviewServerForProject( |
| 377 | projectDir, |
| 378 | startPort, |
| 379 | undefined, |
| 380 | undefined, |
| 381 | preferredPort === undefined ? undefined : { preferredPort }, |
| 382 | ); |
| 383 | } catch (err) { |
| 384 | if (err instanceof AmbiguousPreviewServerError) { |
| 385 | printSelectionFailure("ambiguous-preview-server", err.message, json); |
| 386 | return; |
| 387 | } |
| 388 | if (err instanceof PreviewServerPortMismatchError) { |
| 389 | printSelectionFailure("preview-port-mismatch", err.message, json); |
| 390 | return; |
| 391 | } |
| 392 | throw err; |
| 393 | } |
| 394 | if (!server) { |
| 395 | printSelectionFailure( |
| 396 | "preview-not-running", |
| 397 | "No running Studio preview found for this project. Start one with: npx hyperframes preview", |
| 398 | json, |
| 399 | ); |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | let response: Awaited<ReturnType<typeof fetchStudioSelection>>; |
| 404 | try { |
| 405 | response = await fetchStudioSelection(server); |
| 406 | } catch (err) { |
| 407 | printSelectionFailure("selection-unavailable", errorMessage(err), json); |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | if (!response.selection) { |
| 412 | printSelectionFailure( |
| 413 | "no-selection", |
| 414 | "Studio is running, but no element is selected. Select an element in Studio and rerun this command.", |
| 415 | json, |
| 416 | ); |
| 417 | return; |
| 418 | } |
| 419 |
no test coverage detected