MCPcopy
hub / github.com/triggerdotdev/trigger.dev / _initCommand

Function _initCommand

packages/cli-v3/src/commands/init.ts:74–181  ·  view source on GitHub ↗
(dir: string, options: InitCommandOptions)

Source from the content-addressed store, hash-verified

72}
73
74async function _initCommand(dir: string, options: InitCommandOptions) {
75 const span = trace.getSpan(context.active());
76
77 intro("Initializing project");
78
79 const authorization = await login({
80 embedded: true,
81 defaultApiUrl: options.apiUrl,
82 profile: options.profile,
83 });
84
85 if (!authorization.ok) {
86 if (authorization.error === "fetch failed") {
87 throw new Error(
88 `Failed to connect to ${authorization.auth?.apiUrl}. Are you sure it's the correct URL?`
89 );
90 } else {
91 throw new Error("You must login first. Use `trigger.dev login` to login.");
92 }
93 }
94
95 span?.setAttributes({
96 "cli.userId": authorization.userId,
97 "cli.email": authorization.email,
98 "cli.config.apiUrl": authorization.auth.apiUrl,
99 "cli.config.profile": authorization.profile,
100 });
101
102 if (!options.overrideConfig) {
103 try {
104 // check to see if there is an existing trigger.dev config file in the project directory
105 const result = await readConfig(dir);
106
107 outro(
108 result.status === "file"
109 ? `Project already initialized: Found config file at ${result.path}. Pass --override-config to override`
110 : "Project already initialized"
111 );
112
113 return;
114 } catch (e) {
115 // continue
116 }
117 }
118
119 const apiClient = new CliApiClient(authorization.auth.apiUrl, authorization.auth.accessToken);
120
121 const selectedProject = await selectProject(
122 apiClient,
123 authorization.dashboardUrl,
124 options.projectRef
125 );
126
127 span?.setAttributes({
128 ...flattenAttributes(selectedProject, "cli.project"),
129 });
130
131 logger.debug("Selected project", selectedProject);

Callers 1

initCommandFunction · 0.85

Calls 12

loginFunction · 0.90
flattenAttributesFunction · 0.90
readConfigFunction · 0.85
selectProjectFunction · 0.85
createTriggerDirFunction · 0.85
writeConfigFileFunction · 0.85
addConfigFileToTsConfigFunction · 0.85
gitIgnoreDotTriggerDirFunction · 0.85
getSpanMethod · 0.80
installPackagesFunction · 0.70
debugMethod · 0.65
infoMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…