(dir: string, options: InitCommandOptions)
| 72 | } |
| 73 | |
| 74 | async 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); |
no test coverage detected
searching dependent graphs…