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

Function addConfigFileToTsConfig

packages/cli-v3/src/commands/init.ts:320–384  ·  view source on GitHub ↗
(dir: string, options: InitCommandOptions)

Source from the content-addressed store, hash-verified

318}
319
320async function addConfigFileToTsConfig(dir: string, options: InitCommandOptions) {
321 return await tracer.startActiveSpan("createTriggerDir", async (span) => {
322 try {
323 const projectDir = resolve(process.cwd(), dir);
324 const tsconfigPath = join(projectDir, "tsconfig.json");
325
326 span.setAttributes({
327 "cli.projectDir": projectDir,
328 "cli.tsconfigPath": tsconfigPath,
329 });
330
331 const tsconfigContent = await readFile(tsconfigPath);
332 const tsconfigContentTree = parseTree(tsconfigContent, undefined);
333 if (!tsconfigContentTree) {
334 span.end();
335
336 return;
337 }
338
339 const tsconfigIncludeOption = findNodeAtLocation(tsconfigContentTree, ["include"]);
340 if (!tsconfigIncludeOption) {
341 span.end();
342
343 return;
344 }
345
346 const tsConfigFileName = "trigger.config.ts";
347 const tsconfigIncludeOptionValue: string[] = getNodeValue(tsconfigIncludeOption);
348 if (tsconfigIncludeOptionValue.includes(tsConfigFileName)) {
349 span.end();
350
351 return;
352 }
353
354 const edits = modify(tsconfigContent, ["include", -1], tsConfigFileName, {
355 isArrayInsertion: true,
356 formattingOptions: {
357 tabSize: 2,
358 insertSpaces: true,
359 eol: "\n",
360 },
361 });
362
363 logger.debug("tsconfig.json edits", { edits });
364
365 const newTsconfigContent = applyEdits(tsconfigContent, edits);
366
367 logger.debug("new tsconfig.json content", { newTsconfigContent });
368
369 await writeFile(tsconfigPath, newTsconfigContent, "utf-8");
370
371 log.step(`Added trigger.config.ts to tsconfig.json`);
372
373 span.end();
374 } catch (e) {
375 if (!(e instanceof SkipCommandError)) {
376 recordSpanException(span, e);
377 }

Callers 1

_initCommandFunction · 0.85

Calls 4

readFileFunction · 0.90
recordSpanExceptionFunction · 0.85
startActiveSpanMethod · 0.80
debugMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…