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

Function devCommand

packages/cli/src/commands/dev.ts:79–192  ·  view source on GitHub ↗
(path: string, anyOptions: any)

Source from the content-addressed store, hash-verified

77type ServerEndpoint = TunnelEndpoint | ResolvedEndpoint;
78
79export 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);

Callers 1

index.tsFile · 0.90

Calls 15

callMethod · 0.95
resolvePathFunction · 0.90
getJsRuntimeFunction · 0.90
getTriggerApiDetailsFunction · 0.90
getEndpointIdFunction · 0.85
resolveOptionsFunction · 0.85
verifyEndpointFunction · 0.85
resolveEndpointUrlFunction · 0.85
errorMethod · 0.65
infoMethod · 0.65
logMethod · 0.65
onMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…