-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathinit.ts
More file actions
822 lines (671 loc) · 23.8 KB
/
Copy pathinit.ts
File metadata and controls
822 lines (671 loc) · 23.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
import { intro, isCancel, log, multiselect, outro, select, text } from "@clack/prompts";
import { context, trace } from "@opentelemetry/api";
import {
GetProjectResponseBody,
LogLevel,
flattenAttributes,
tryCatch,
} from "@trigger.dev/core/v3";
import { recordSpanException } from "@trigger.dev/core/v3/workers";
import chalk from "chalk";
import { Command, Option as CommandOption } from "commander";
import { applyEdits, findNodeAtLocation, getNodeValue, modify, parseTree } from "jsonc-parser";
import { writeFile } from "node:fs/promises";
import { join, relative, resolve } from "node:path";
import { addDependency, addDevDependency } from "nypm";
import { resolveTSConfig } from "pkg-types";
import { z } from "zod";
import { CliApiClient } from "../apiClient.js";
import {
CommonCommandOptions,
OutroCommandError,
SkipCommandError,
SkipLoggingError,
commonOptions,
handleTelemetry,
tracer,
wrapCommandAction,
} from "../cli/common.js";
import { loadConfig } from "../config.js";
import { cliLink } from "../utilities/cliOutput.js";
import {
createFileFromTemplate,
generateTemplateUrl,
} from "../utilities/createFileFromTemplate.js";
import { createFile, pathExists, readFile } from "../utilities/fileSystem.js";
import { printStandloneInitialBanner } from "../utilities/initialBanner.js";
import { logger } from "../utilities/logger.js";
import { spinner } from "../utilities/windows.js";
import { VERSION } from "../version.js";
import { login } from "./login.js";
import {
readConfigHasSeenMCPInstallPrompt,
writeConfigHasSeenMCPInstallPrompt,
} from "../utilities/configFiles.js";
import { installMcpServer } from "./install-mcp.js";
import { installSkillsFromInit, markSkillsPromptSeen } from "./skills.js";
const cliVersion = VERSION as string;
const cliTag = cliVersion.includes("v4-beta") ? "v4-beta" : "latest";
const InitCommandOptions = CommonCommandOptions.extend({
projectRef: z.string().optional(),
overrideConfig: z.boolean().default(false),
tag: z.string().default(cliVersion),
skipPackageInstall: z.boolean().default(false),
runtime: z.string().default("node"),
pkgArgs: z.string().optional(),
gitRef: z.string().default("main"),
javascript: z.boolean().default(false),
yes: z.boolean().default(false),
browser: z.boolean().default(true),
});
type InitCommandOptions = z.infer<typeof InitCommandOptions>;
export function configureInitCommand(program: Command) {
return commonOptions(
program
.command("init")
.summary("Initialize your existing project for development with Trigger.dev")
.description(
`Initialize your existing project for development with Trigger.dev.
Examples:
# Interactive setup
$ trigger.dev init
# Non-interactive (CI / scripts)
$ trigger.dev init --yes --project-ref proj_abc123
# Headless / agent (no browser)
$ trigger.dev init --yes --project-ref proj_abc123 --no-browser
# Use a named profile
$ trigger.dev init --profile staging`
)
.argument("[path]", "The path to the project", ".")
.option(
"-p, --project-ref <project ref>",
"The project ref to use when initializing the project"
)
.option("--javascript", "Initialize the project with JavaScript instead of TypeScript", false)
.option(
"-t, --tag <package tag>",
"The version of the @trigger.dev/sdk package to install",
cliVersion
)
.option(
"-r, --runtime <runtime>",
"Which runtime to use for the project. Currently only supports node and bun",
"node"
)
.option("--skip-package-install", "Skip installing the @trigger.dev/sdk package")
.option("--override-config", "Override the existing config file if it exists")
.option(
"--pkg-args <args>",
"Additional arguments to pass to the package manager, accepts CSV for multiple args"
)
.option("-y, --yes", "Skip all prompts and use defaults (requires --project-ref)")
.option("--no-browser", "Don't automatically open the browser during login; print the URL only")
)
.addOption(
new CommandOption(
"--git-ref <git ref>",
"The git ref to use when fetching templates from GitHub"
).hideHelp()
)
.action(async (path, options) => {
await handleTelemetry(async () => {
await printStandloneInitialBanner(true, options.profile);
await initCommand(path, options);
});
});
}
export async function initCommand(dir: string, options: unknown) {
return await wrapCommandAction("initCommand", InitCommandOptions, options, async (opts) => {
return await _initCommand(dir, opts);
});
}
async function _initCommand(dir: string, options: InitCommandOptions) {
const span = trace.getSpan(context.active());
// Validate --yes flag requirements
if (options.yes && !options.projectRef) {
throw new Error("--project-ref is required when using --yes flag");
}
// Refuse to run interactively when stdin isn't a TTY (CI, agent harness, etc).
// Previously this silently default-and-exited at the first prompt, leaving the
// project half-initialized.
if (!options.yes && !process.stdin.isTTY) {
throw new Error(
"Interactive prompts cannot be used in non-TTY environments. Pass --yes (and --project-ref) to run non-interactively."
);
}
const hasSeenMCPInstallPrompt = readConfigHasSeenMCPInstallPrompt();
// Skip the AI-tooling prompt when --yes is set: the user explicitly chose the CLI
// scaffold by running `trigger.dev init` non-interactively, and the prompt would
// otherwise hang on a fresh machine where `hasSeenMCPInstallPrompt` is false.
if (!hasSeenMCPInstallPrompt && !options.yes) {
const tooling = await multiselect({
message: "Set up AI tooling for your coding assistant? (optional, space to toggle)",
options: [
{
value: "mcp",
label: "MCP server",
hint: "live access to your project: trigger tasks, deploy, monitor runs",
},
{
value: "skills",
label: "Agent skills",
hint: "teach your AI to write Trigger.dev code, version-matched to your SDK",
},
],
required: false,
});
writeConfigHasSeenMCPInstallPrompt(true);
const selectedTooling = isCancel(tooling) ? [] : tooling;
// Track what actually installed (not just what was selected), so the AI hand-off is
// only offered, and only described, in terms of tooling that really landed.
let installedSkills = false;
let installedMcp = false;
// Skills are auth-free and bundled in the CLI. The user opted in here, so install
// straight away (no extra confirm). If they declined, still mark the prompt seen so
// `trigger dev` doesn't ask about skills a second time.
if (selectedTooling.includes("skills")) {
log.step("Installing the Trigger.dev agent skills");
const [skillsError, installed] = await tryCatch(installSkillsFromInit());
if (skillsError) {
log.warn(`Skipped agent skills: ${skillsError.message}`);
} else {
installedSkills = installed === true;
}
} else {
await tryCatch(markSkillsPromptSeen());
}
// The MCP server is also auth-free.
if (selectedTooling.includes("mcp")) {
log.step("Welcome to the Trigger.dev MCP server install wizard 🧙");
const [installError] = await tryCatch(
installMcpServer({
yolo: false,
tag: options.tag,
logLevel: options.logLevel,
})
);
if (installError) {
outro(`Failed to install MCP server: ${installError.message}`);
return;
}
installedMcp = true;
}
// Vibe path: once AI tooling is actually installed, the user can hand scaffolding to
// their assistant instead of the CLI. Only offered when something landed, and the
// hand-off message names only the tooling that did.
if (installedSkills || installedMcp) {
const setupChoice = await select({
message: "How do you want to set up your project?",
options: [
{
value: "cli",
label: "Scaffold it now with the CLI",
hint: "log in, create trigger.config.ts and an example task",
},
{
value: "ai",
label: "Let my AI assistant set it up",
hint: "hand off and let your assistant bootstrap the project",
},
],
});
if (!isCancel(setupChoice) && setupChoice === "ai") {
outro(
installedSkills
? "Your AI tooling is ready. Ask your assistant to set up Trigger.dev and it will use the getting-started skill to add the SDK, config, and your first task."
: "The MCP server is installed. Ask your assistant to set up Trigger.dev using the MCP server."
);
return;
}
}
}
intro("Initializing project");
const cwd = resolve(process.cwd(), dir);
const authorization = await login({
embedded: true,
defaultApiUrl: options.apiUrl,
profile: options.profile,
browser: options.browser,
});
if (!authorization.ok) {
if (authorization.error === "fetch failed") {
throw new Error(
`Failed to connect to ${authorization.auth?.apiUrl}. Are you sure it's the correct URL?`
);
} else {
throw new Error("You must login first. Use `trigger.dev login` to login.");
}
}
span?.setAttributes({
"cli.userId": authorization.userId,
"cli.email": authorization.email,
"cli.config.apiUrl": authorization.auth.apiUrl,
"cli.config.profile": authorization.profile,
});
const tsconfigPath = await tryResolveTsConfig(cwd);
if (!options.overrideConfig) {
try {
// check to see if there is an existing trigger.dev config file in the project directory
const result = await loadConfig({ cwd });
if (result.configFile && result.configFile !== "trigger.config") {
outro(
result.configFile
? `Project already initialized: Found config file at ${result.configFile}. Pass --override-config to override`
: "Project already initialized"
);
return;
}
} catch (e) {
// continue
}
}
const apiClient = new CliApiClient(authorization.auth.apiUrl, authorization.auth.accessToken);
const selectedProject = await selectProject(
apiClient,
authorization.dashboardUrl,
options.projectRef
);
span?.setAttributes({
...flattenAttributes(selectedProject, "cli.project"),
});
logger.debug("Selected project", selectedProject);
log.step(`Configuring project "${selectedProject.name}" (${selectedProject.externalRef})`);
// Install @trigger.dev/sdk package
if (!options.skipPackageInstall) {
await installPackages(
cwd,
options.tag,
new CLIInstallPackagesOutputter(options.logLevel, options.tag)
);
} else {
log.info("Skipping package installation");
}
const language = options.javascript ? "javascript" : "typescript";
// Create the trigger dir
const triggerDir = await createTriggerDir(dir, options, language);
// Create the config file
await writeConfigFile(dir, selectedProject, options, triggerDir, language);
// Add trigger.config.ts to tsconfig.json
if (tsconfigPath && language === "typescript") {
await addConfigFileToTsConfig(tsconfigPath, options);
}
// Ignore .trigger dir
await gitIgnoreDotTriggerDir(dir, options);
const projectDashboard = cliLink(
"project dashboard",
`${authorization.dashboardUrl}/projects/v3/${selectedProject.externalRef}`
);
log.success("Successfully initialized your Trigger.dev project 🫡");
log.info("Next steps:");
log.info(
` 1. To start developing, run ${chalk.green(
`npx trigger.dev@${cliTag} dev${options.profile ? ` --profile ${options.profile}` : ""}`
)} in your project directory`
);
log.info(` 2. Visit your ${projectDashboard} to view your newly created tasks.`);
log.info(
` 3. Head over to our ${cliLink("v3 docs", "https://trigger.dev/docs")} to learn more.`
);
log.info(
` 4. Need help? Join our ${cliLink(
"Discord community",
"https://trigger.dev/discord"
)} or email us at ${chalk.cyan("help@trigger.dev")}`
);
outro(`Project initialized successfully. Happy coding!`);
}
async function createTriggerDir(
dir: string,
options: InitCommandOptions,
language: "typescript" | "javascript"
) {
return await tracer.startActiveSpan("createTriggerDir", async (span) => {
try {
const defaultValue = join(dir, "src", "trigger");
let location: string;
let example: string;
if (options.yes) {
// Use defaults when --yes flag is set
location = defaultValue;
example = "simple";
} else {
const locationPrompt = await text({
message: "Where would you like to create the Trigger.dev directory?",
defaultValue: defaultValue,
placeholder: defaultValue,
});
if (isCancel(locationPrompt)) {
throw new OutroCommandError();
}
location = locationPrompt;
const exampleSelection = await select({
message: `Choose an example to create in the ${location} directory`,
options: [
{ value: "simple", label: "Simple (Hello World)" },
{ value: "schedule", label: "Scheduled Task" },
{
value: "none",
label: "None",
hint: "skip creating an example",
},
],
});
if (isCancel(exampleSelection)) {
throw new OutroCommandError();
}
example = exampleSelection as string;
}
// Ensure that the path is always relative by stripping leading '/' if present
const relativeLocation = location.replace(/^\//, "");
const triggerDir = resolve(process.cwd(), relativeLocation);
logger.debug({ triggerDir });
span.setAttributes({
"cli.triggerDir": triggerDir,
});
if (await pathExists(triggerDir)) {
throw new Error(`Directory already exists at ${triggerDir}`);
}
span.setAttributes({
"cli.example": example,
});
if (example === "none") {
// Create a .gitkeep file in the trigger dir
await createFile(join(triggerDir, ".gitkeep"), "");
log.step(`Created directory at ${location}`);
span.end();
return { location, isCustomValue: location !== defaultValue };
}
const templateUrl = generateTemplateUrl(
`examples/${example}.${language === "typescript" ? "ts" : "mjs"}`,
options.gitRef
);
const outputPath = join(triggerDir, `example.${language === "typescript" ? "ts" : "mjs"}`);
await createFileFromTemplate({
templateUrl,
outputPath,
replacements: {},
});
const relativeOutputPath = relative(process.cwd(), outputPath);
log.step(`Created example file at ${relativeOutputPath}`);
span.end();
return { location, isCustomValue: location !== defaultValue };
} catch (e) {
if (!(e instanceof SkipCommandError)) {
recordSpanException(span, e);
}
span.end();
throw e;
}
});
}
async function gitIgnoreDotTriggerDir(dir: string, options: InitCommandOptions) {
return await tracer.startActiveSpan("gitIgnoreDotTriggerDir", async (span) => {
try {
const projectDir = resolve(process.cwd(), dir);
const gitIgnorePath = join(projectDir, ".gitignore");
span.setAttributes({
"cli.projectDir": projectDir,
"cli.gitIgnorePath": gitIgnorePath,
});
if (!(await pathExists(gitIgnorePath))) {
// Create .gitignore file
await createFile(gitIgnorePath, ".trigger");
log.step(`Added .trigger to .gitignore`);
span.end();
return;
}
// Check if .gitignore already contains .trigger
const gitIgnoreContent = await readFile(gitIgnorePath);
if (gitIgnoreContent.includes(".trigger")) {
span.end();
return;
}
const newGitIgnoreContent = `${gitIgnoreContent}\n.trigger`;
await writeFile(gitIgnorePath, newGitIgnoreContent, "utf-8");
log.step(`Added .trigger to .gitignore`);
span.end();
} catch (e) {
if (!(e instanceof SkipCommandError)) {
recordSpanException(span, e);
}
span.end();
throw e;
}
});
}
async function addConfigFileToTsConfig(tsconfigPath: string, options: InitCommandOptions) {
return await tracer.startActiveSpan("addConfigFileToTsConfig", async (span) => {
try {
span.setAttributes({
"cli.tsconfigPath": tsconfigPath,
});
const tsconfigContent = await readFile(tsconfigPath);
const tsconfigContentTree = parseTree(tsconfigContent, undefined);
if (!tsconfigContentTree) {
span.end();
return;
}
const tsconfigIncludeOption = findNodeAtLocation(tsconfigContentTree, ["include"]);
if (!tsconfigIncludeOption) {
span.end();
return;
}
const tsConfigFileName = "trigger.config.ts";
const tsconfigIncludeOptionValue: string[] = getNodeValue(tsconfigIncludeOption);
if (tsconfigIncludeOptionValue.includes(tsConfigFileName)) {
span.end();
return;
}
const edits = modify(tsconfigContent, ["include", -1], tsConfigFileName, {
isArrayInsertion: true,
formattingOptions: {
tabSize: 2,
insertSpaces: true,
eol: "\n",
},
});
logger.debug("tsconfig.json edits", { edits });
const newTsconfigContent = applyEdits(tsconfigContent, edits);
logger.debug("new tsconfig.json content", { newTsconfigContent });
await writeFile(tsconfigPath, newTsconfigContent, "utf-8");
log.step(`Added trigger.config.ts to tsconfig.json`);
span.end();
} catch (e) {
if (!(e instanceof SkipCommandError)) {
recordSpanException(span, e);
}
span.end();
throw e;
}
});
}
export interface InstallPackagesOutputter {
startSDK: () => void;
installedSDK: () => void;
startBuild: () => void;
installedBuild: () => void;
stoppedWithError: () => void;
}
class CLIInstallPackagesOutputter implements InstallPackagesOutputter {
private installSpinner: ReturnType<typeof spinner>;
constructor(
private readonly logLevel: LogLevel,
private readonly tag: string
) {
this.installSpinner = spinner();
}
startSDK() {
this.installSpinner.start(`Adding @trigger.dev/sdk@${this.tag}`);
}
installedSDK() {
this.installSpinner.stop(`@trigger.dev/sdk@${this.tag} installed`);
}
startBuild() {
this.installSpinner.start(`Adding @trigger.dev/build@${this.tag} to devDependencies`);
}
installedBuild() {
this.installSpinner.stop(`@trigger.dev/build@${this.tag} installed`);
}
stoppedWithError() {
if (this.logLevel === "debug") {
this.installSpinner.stop(`Failed to install @trigger.dev/sdk@${this.tag}.`);
} else {
this.installSpinner.stop(
`Failed to install @trigger.dev/sdk@${this.tag}. Rerun command with --log-level debug for more details.`
);
}
}
}
class SilentInstallPackagesOutputter implements InstallPackagesOutputter {
startSDK() {}
installedSDK() {}
startBuild() {}
installedBuild() {}
stoppedWithError() {}
}
export async function installPackages(
projectDir: string,
tag: string,
outputter: InstallPackagesOutputter = new SilentInstallPackagesOutputter()
) {
try {
outputter.startSDK();
await addDependency(`@trigger.dev/sdk@${tag}`, { cwd: projectDir, silent: true });
outputter.installedSDK();
outputter.startBuild();
await addDevDependency(`@trigger.dev/build@${tag}`, {
cwd: projectDir,
silent: true,
});
outputter.installedBuild();
} catch (e) {
outputter.stoppedWithError();
throw e;
}
}
async function writeConfigFile(
dir: string,
project: GetProjectResponseBody,
options: InitCommandOptions,
triggerDir: { location: string; isCustomValue: boolean },
language: "typescript" | "javascript"
) {
return await tracer.startActiveSpan("writeConfigFile", async (span) => {
try {
const spnnr = spinner();
spnnr.start("Creating config file");
const projectDir = resolve(process.cwd(), dir);
const outputPath = join(
projectDir,
`trigger.config.${language === "typescript" ? "ts" : "mjs"}`
);
const templateUrl = generateTemplateUrl(
`trigger.config.${language === "typescript" ? "ts" : "mjs"}`,
options.gitRef
);
span.setAttributes({
"cli.projectDir": projectDir,
"cli.templatePath": templateUrl,
"cli.outputPath": outputPath,
"cli.runtime": options.runtime,
});
const result = await createFileFromTemplate({
templateUrl,
replacements: {
projectRef: project.externalRef,
runtime: options.runtime,
triggerDirectoriesOption: triggerDir.isCustomValue
? `\n dirs: ["${triggerDir.location}"],`
: `\n dirs: ["./src/trigger"],`,
},
outputPath,
override: options.overrideConfig,
});
const relativePathToOutput = relative(process.cwd(), outputPath);
spnnr.stop(
result.success
? `Config file created at ${relativePathToOutput}`
: `Failed to create config file: ${result.error}`
);
if (!result.success) {
throw new SkipLoggingError(result.error);
}
span.end();
return result.success;
} catch (e) {
if (!(e instanceof SkipCommandError)) {
recordSpanException(span, e);
}
span.end();
throw e;
}
});
}
async function selectProject(apiClient: CliApiClient, dashboardUrl: string, projectRef?: string) {
return await tracer.startActiveSpan("selectProject", async (span) => {
try {
if (projectRef) {
const projectResponse = await apiClient.getProject(projectRef);
if (!projectResponse.success) {
log.error(
`--project-ref ${projectRef} is not a valid project ref. Request to fetch data resulted in: ${projectResponse.error}`
);
throw new SkipCommandError(projectResponse.error);
}
span.setAttributes({
...flattenAttributes(projectResponse.data, "cli.project"),
});
span.end();
return projectResponse.data;
}
const projectsResponse = await apiClient.getProjects();
if (!projectsResponse.success) {
throw new Error(`Failed to get projects: ${projectsResponse.error}`);
}
if (projectsResponse.data.length === 0) {
const newProjectLink = cliLink(
"Create new project",
`${dashboardUrl}/projects/new?version=v3`
);
outro(`You don't have any projects yet. ${newProjectLink}`);
throw new SkipCommandError();
}
const selectedProject = await select({
message: "Select an existing Trigger.dev project",
options: projectsResponse.data.map((project) => ({
value: project.externalRef,
label: `${project.name} - ${project.externalRef}`,
hint: project.organization.title,
})),
});
if (isCancel(selectedProject)) {
throw new OutroCommandError();
}
const projectData = projectsResponse.data.find(
(project) => project.externalRef === selectedProject
);
if (!projectData) {
throw new Error("Invalid project ref");
}
span.setAttributes({
...flattenAttributes(projectData, "cli.project"),
});
span.end();
return projectData;
} catch (e) {
if (!(e instanceof SkipCommandError)) {
recordSpanException(span, e);
}
span.end();
throw e;
}
});
}
async function tryResolveTsConfig(cwd: string) {
try {
const tsconfigPath = await resolveTSConfig(cwd);
return tsconfigPath;
} catch (e) {
return;
}
}