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

Function initCommand

packages/cli/src/commands/init.ts:37–160  ·  view source on GitHub ↗
(options: InitCommandOptions)

Source from the content-addressed store, hash-verified

35type ResolvedOptions = Required<InitCommandOptions>;
36
37export const initCommand = async (options: InitCommandOptions) => {
38 telemetryClient.init.started(options);
39
40 const resolvedPath = resolvePath(options.projectPath);
41
42 // assuming nodejs by default
43 let runtimeId: string = "nodejs";
44 try {
45 runtimeId = (await getJsRuntime(resolvedPath, logger)).id;
46 } catch {}
47 if (runtimeId !== "nodejs") {
48 logger.error(
49 `We currently only support automatic setup for NodeJS projects. This is a ${runtimeId} project. View our manual installation guides here: https://trigger.dev/docs/documentation/quickstarts/introduction`
50 );
51 telemetryClient.init.failed("not_supported_runtime", options);
52 return;
53 }
54
55 await renderTitle(resolvedPath);
56
57 if (options.triggerUrl === CLOUD_TRIGGER_URL) {
58 logger.info(`✨ Initializing project in Trigger.dev Cloud`);
59 } else if (typeof options.triggerUrl === "string") {
60 logger.info(`✨ Initializing project using Trigger.dev at ${options.triggerUrl}`);
61 } else {
62 logger.info(`✨ Initializing Trigger.dev in project`);
63 }
64
65 const packageManager = await getUserPackageManager(resolvedPath);
66 const framework = await getFramework(resolvedPath, packageManager);
67
68 if (!framework) {
69 logger.error(
70 `We currently only support automatic setup for ${frameworkNames()} projects (we didn't detect one). View our manual installation guides for all frameworks: https://trigger.dev/docs/documentation/quickstarts/introduction`
71 );
72 telemetryClient.init.failed("not_supported_project", options);
73 return;
74 }
75 logger.success(`✔ Detected ${framework.name} project`);
76
77 const hasGitChanges = await detectGitChanges(resolvedPath);
78 if (hasGitChanges) {
79 // Warn the user that they have git changes
80 logger.warn(
81 "⚠️ You have uncommitted git changes, you may want to commit them before continuing."
82 );
83 }
84
85 const isTypescriptProject = await detectTypescriptProject(resolvedPath);
86 telemetryClient.init.isTypescriptProject(isTypescriptProject, options);
87
88 const optionsAfterPrompts = await resolveOptionsWithPrompts(options, resolvedPath);
89 const apiKey = optionsAfterPrompts.apiKey;
90
91 if (!apiKey) {
92 logger.error("You must provide an API key to continue.");
93 telemetryClient.init.failed("no_api_key", optionsAfterPrompts);
94 return;

Callers 1

index.tsFile · 0.90

Calls 15

whoamiMethod · 0.95
resolvePathFunction · 0.90
getJsRuntimeFunction · 0.90
renderTitleFunction · 0.90
getUserPackageManagerFunction · 0.90
getFrameworkFunction · 0.90
frameworkNamesFunction · 0.90
addDependenciesFunction · 0.90
getEnvFilenameFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…