(apiClient: CliApiClient, dashboardUrl: string, projectRef?: string)
| 510 | } |
| 511 | |
| 512 | async function selectProject(apiClient: CliApiClient, dashboardUrl: string, projectRef?: string) { |
| 513 | return await tracer.startActiveSpan("selectProject", async (span) => { |
| 514 | try { |
| 515 | if (projectRef) { |
| 516 | const projectResponse = await apiClient.getProject(projectRef); |
| 517 | |
| 518 | if (!projectResponse.success) { |
| 519 | log.error( |
| 520 | `--project-ref ${projectRef} is not a valid project ref. Request to fetch data resulted in: ${projectResponse.error}` |
| 521 | ); |
| 522 | |
| 523 | throw new SkipCommandError(projectResponse.error); |
| 524 | } |
| 525 | |
| 526 | span.setAttributes({ |
| 527 | ...flattenAttributes(projectResponse.data, "cli.project"), |
| 528 | }); |
| 529 | |
| 530 | span.end(); |
| 531 | |
| 532 | return projectResponse.data; |
| 533 | } |
| 534 | |
| 535 | const projectsResponse = await apiClient.getProjects(); |
| 536 | |
| 537 | if (!projectsResponse.success) { |
| 538 | throw new Error(`Failed to get projects: ${projectsResponse.error}`); |
| 539 | } |
| 540 | |
| 541 | if (projectsResponse.data.length === 0) { |
| 542 | const newProjectLink = terminalLink( |
| 543 | "Create new project", |
| 544 | `${dashboardUrl}/projects/new?version=v3` |
| 545 | ); |
| 546 | |
| 547 | outro(`You don't have any projects yet. ${newProjectLink}`); |
| 548 | |
| 549 | throw new SkipCommandError(); |
| 550 | } |
| 551 | |
| 552 | const selectedProject = await select({ |
| 553 | message: "Select an existing Trigger.dev project", |
| 554 | options: projectsResponse.data.map((project) => ({ |
| 555 | value: project.externalRef, |
| 556 | label: `${project.name} - ${project.externalRef}`, |
| 557 | hint: project.organization.title, |
| 558 | })), |
| 559 | }); |
| 560 | |
| 561 | if (isCancel(selectedProject)) { |
| 562 | throw new OutroCommandError(); |
| 563 | } |
| 564 | |
| 565 | const projectData = projectsResponse.data.find( |
| 566 | (project) => project.externalRef === selectedProject |
| 567 | ); |
| 568 | |
| 569 | if (!projectData) { |
no test coverage detected
searching dependent graphs…