|
1 | 1 | import { intro, isCancel, log, outro, select, text } from "@clack/prompts"; |
2 | 2 | import { context, trace } from "@opentelemetry/api"; |
3 | | -import { GetProjectResponseBody, LogLevel, flattenAttributes } from "@trigger.dev/core/v3"; |
| 3 | +import { |
| 4 | + GetProjectResponseBody, |
| 5 | + LogLevel, |
| 6 | + flattenAttributes, |
| 7 | + tryCatch, |
| 8 | +} from "@trigger.dev/core/v3"; |
4 | 9 | import { recordSpanException } from "@trigger.dev/core/v3/workers"; |
5 | 10 | import chalk from "chalk"; |
6 | 11 | import { Command, Option as CommandOption } from "commander"; |
@@ -33,6 +38,11 @@ import { logger } from "../utilities/logger.js"; |
33 | 38 | import { spinner } from "../utilities/windows.js"; |
34 | 39 | import { VERSION } from "../version.js"; |
35 | 40 | import { login } from "./login.js"; |
| 41 | +import { |
| 42 | + readConfigHasSeenMCPInstallPrompt, |
| 43 | + writeConfigHasSeenMCPInstallPrompt, |
| 44 | +} from "../utilities/configFiles.js"; |
| 45 | +import { installMcpServer } from "./install-mcp.js"; |
36 | 46 |
|
37 | 47 | const cliVersion = VERSION as string; |
38 | 48 | const cliTag = cliVersion.includes("v4-beta") ? "v4-beta" : "latest"; |
@@ -108,6 +118,43 @@ async function _initCommand(dir: string, options: InitCommandOptions) { |
108 | 118 | throw new Error("--project-ref is required when using --yes flag"); |
109 | 119 | } |
110 | 120 |
|
| 121 | + const hasSeenMCPInstallPrompt = readConfigHasSeenMCPInstallPrompt(); |
| 122 | + |
| 123 | + if (!hasSeenMCPInstallPrompt) { |
| 124 | + const installChoice = await select({ |
| 125 | + message: "Choose how you want to initialize your project:", |
| 126 | + options: [ |
| 127 | + { |
| 128 | + value: "mcp", |
| 129 | + label: "Trigger.dev MCP", |
| 130 | + hint: "Automatically install the Trigger.dev MCP server and then vibe your way to a new project.", |
| 131 | + }, |
| 132 | + { value: "cli", label: "CLI", hint: "Continue with the CLI" }, |
| 133 | + ], |
| 134 | + }); |
| 135 | + |
| 136 | + const continueWithCLI = isCancel(installChoice) || installChoice === "cli"; |
| 137 | + |
| 138 | + if (!continueWithCLI) { |
| 139 | + log.step("Welcome to the Trigger.dev MCP server install wizard 🧙"); |
| 140 | + |
| 141 | + const [installError] = await tryCatch( |
| 142 | + installMcpServer({ |
| 143 | + yolo: false, |
| 144 | + tag: options.tag, |
| 145 | + logLevel: options.logLevel, |
| 146 | + }) |
| 147 | + ); |
| 148 | + |
| 149 | + if (installError) { |
| 150 | + outro(`Failed to install MCP server: ${installError.message}`); |
| 151 | + return; |
| 152 | + } |
| 153 | + |
| 154 | + return; |
| 155 | + } |
| 156 | + } |
| 157 | + |
111 | 158 | intro("Initializing project"); |
112 | 159 |
|
113 | 160 | const cwd = resolve(process.cwd(), dir); |
@@ -204,7 +251,7 @@ async function _initCommand(dir: string, options: InitCommandOptions) { |
204 | 251 | `${authorization.dashboardUrl}/projects/v3/${selectedProject.externalRef}` |
205 | 252 | ); |
206 | 253 |
|
207 | | - log.success("Successfully initialized project for Trigger.dev v3 🫡"); |
| 254 | + log.success("Successfully initialized your Trigger.dev project 🫡"); |
208 | 255 | log.info("Next steps:"); |
209 | 256 | log.info( |
210 | 257 | ` 1. To start developing, run ${chalk.green( |
|
0 commit comments