(path: string, anyOptions: any)
| 77 | type ServerEndpoint = TunnelEndpoint | ResolvedEndpoint; |
| 78 | |
| 79 | export async function devCommand(path: string, anyOptions: any) { |
| 80 | telemetryClient.dev.started(path, anyOptions); |
| 81 | |
| 82 | const result = DevCommandOptionsSchema.safeParse(anyOptions); |
| 83 | if (!result.success) { |
| 84 | logger.error(result.error.message); |
| 85 | telemetryClient.dev.failed("invalid_options", anyOptions, result.error); |
| 86 | return; |
| 87 | } |
| 88 | const options = result.data; |
| 89 | |
| 90 | const resolvedPath = resolvePath(path); |
| 91 | runtime = await getJsRuntime(resolvedPath, logger); |
| 92 | //check for outdated packages, don't immediately await this |
| 93 | const checkForOutdatedPackagesPromise = runtime.checkForOutdatedPackages(); |
| 94 | |
| 95 | // Read from package.json to get the endpointId |
| 96 | const endpointId = await getEndpointId(runtime, options.clientId); |
| 97 | if (!endpointId) { |
| 98 | logger.error( |
| 99 | "You must run the `init` command first to setup the project – you are missing \n'trigger.dev': { 'endpointId': 'your-client-id' } from your package.json file, or pass in the --client-id option to this command" |
| 100 | ); |
| 101 | telemetryClient.dev.failed("missing_endpoint_id", options); |
| 102 | return; |
| 103 | } |
| 104 | logger.success(`✔️ [trigger.dev] Detected TriggerClient id: ${endpointId}`); |
| 105 | |
| 106 | //resolve the options using the detected framework (use default if there isn't a matching framework) |
| 107 | const packageManager = await runtime.getUserPackageManager(); |
| 108 | const framework = await runtime.getFramework(); |
| 109 | const resolvedOptions = await resolveOptions(framework, resolvedPath, options); |
| 110 | |
| 111 | // Read from .env.local or .env to get the TRIGGER_API_KEY and TRIGGER_API_URL |
| 112 | const apiDetails = await getTriggerApiDetails(resolvedPath, resolvedOptions.envFile); |
| 113 | if (!apiDetails) { |
| 114 | telemetryClient.dev.failed("missing_api_key", resolvedOptions); |
| 115 | return; |
| 116 | } |
| 117 | const { apiUrl, apiKey, apiKeySource } = apiDetails; |
| 118 | logger.success(`✔️ [trigger.dev] Found API Key in ${apiKeySource}`); |
| 119 | |
| 120 | //verify that the endpoint can be reached |
| 121 | const verifiedEndpoint = await verifyEndpoint(resolvedOptions, endpointId, apiKey, framework); |
| 122 | if (!verifiedEndpoint) { |
| 123 | logger.error( |
| 124 | `✖ [trigger.dev] Your endpoint couldn't be verified. Make sure your app is running and try again. ${resolvedOptions.handlerPath}` |
| 125 | ); |
| 126 | logger.info( |
| 127 | ` [trigger.dev] You can use -H to specify a hostname, or -p to specify a port, or -s to specify https, or -t to specify the tunnel-url pointing to the local dev server.` |
| 128 | ); |
| 129 | telemetryClient.dev.failed("no_server_found", resolvedOptions); |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | telemetryClient.dev.serverRunning(path, resolvedOptions); |
| 134 | |
| 135 | // Setup tunnel |
| 136 | const endpointUrl = await resolveEndpointUrl(apiUrl, apiKey, verifiedEndpoint); |
no test coverage detected
searching dependent graphs…