( options: InitCommandOptions, path: string )
| 203 | }; |
| 204 | |
| 205 | const resolveOptionsWithPrompts = async ( |
| 206 | options: InitCommandOptions, |
| 207 | path: string |
| 208 | ): Promise<OptionsAfterPrompts> => { |
| 209 | const resolvedOptions: InitCommandOptions = { ...options }; |
| 210 | |
| 211 | try { |
| 212 | if (!options.triggerUrl) { |
| 213 | resolvedOptions.triggerUrl = await promptTriggerUrl(); |
| 214 | } |
| 215 | |
| 216 | if (resolvedOptions.triggerUrl === CLOUD_TRIGGER_URL) { |
| 217 | resolvedOptions.apiUrl = CLOUD_API_URL; |
| 218 | } else { |
| 219 | resolvedOptions.apiUrl = resolvedOptions.triggerUrl; |
| 220 | } |
| 221 | |
| 222 | telemetryClient.init.resolvedApiUrl(resolvedOptions.apiUrl, resolvedOptions); |
| 223 | |
| 224 | if (!options.apiKey) { |
| 225 | resolvedOptions.apiKey = await promptApiKey(resolvedOptions.triggerUrl!); |
| 226 | } |
| 227 | telemetryClient.init.resolvedApiKey(resolvedOptions); |
| 228 | |
| 229 | if (!options.endpointSlug) { |
| 230 | const packageJSONPath = pathModule.join(path, "package.json"); |
| 231 | const packageJSON = await readJSONFile(packageJSONPath); |
| 232 | |
| 233 | if (packageJSON && packageJSON["trigger.dev"] && packageJSON["trigger.dev"].endpointId) { |
| 234 | resolvedOptions.endpointSlug = packageJSON["trigger.dev"].endpointId; |
| 235 | telemetryClient.init.resolvedEndpointSlug(resolvedOptions); |
| 236 | } |
| 237 | } |
| 238 | } catch (err) { |
| 239 | // If the user is not calling the command from an interactive terminal, inquirer will throw an error with isTTYError = true |
| 240 | // If this happens, we catch the error, tell the user what has happened, and then continue to run the program with a default trigger project |
| 241 | // Otherwise we have to do some fancy namespace extension logic on the Error type which feels overkill for one line |
| 242 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 243 | if (err instanceof Error && (err as any).isTTYError) { |
| 244 | logger.warn(`'${COMMAND_NAME} init' needs an interactive terminal to provide options`); |
| 245 | |
| 246 | const { shouldContinue } = await inquirer.prompt<{ |
| 247 | shouldContinue: boolean; |
| 248 | }>({ |
| 249 | name: "shouldContinue", |
| 250 | type: "confirm", |
| 251 | message: `Continue initializing your trigger.dev project?`, |
| 252 | default: true, |
| 253 | }); |
| 254 | |
| 255 | if (!shouldContinue) { |
| 256 | telemetryClient.init.failed("non_interactive_terminal", options); |
| 257 | logger.info("Exiting..."); |
| 258 | throw err; |
| 259 | } |
| 260 | } else { |
| 261 | telemetryClient.init.failed("unknown", options, err); |
| 262 | throw err; |
no test coverage detected
searching dependent graphs…