(
dir: string,
project: GetProjectResponseBody,
options: InitCommandOptions,
triggerDir: { location: string; isCustomValue: boolean }
)
| 450 | } |
| 451 | |
| 452 | async function writeConfigFile( |
| 453 | dir: string, |
| 454 | project: GetProjectResponseBody, |
| 455 | options: InitCommandOptions, |
| 456 | triggerDir: { location: string; isCustomValue: boolean } |
| 457 | ) { |
| 458 | return await tracer.startActiveSpan("writeConfigFile", async (span) => { |
| 459 | try { |
| 460 | const spnnr = spinner(); |
| 461 | spnnr.start("Creating config file"); |
| 462 | |
| 463 | const projectDir = resolve(process.cwd(), dir); |
| 464 | const templatePath = join(cliRootPath(), "templates", "trigger.config.ts.template"); |
| 465 | const outputPath = join(projectDir, "trigger.config.ts"); |
| 466 | |
| 467 | span.setAttributes({ |
| 468 | "cli.projectDir": projectDir, |
| 469 | "cli.templatePath": templatePath, |
| 470 | "cli.outputPath": outputPath, |
| 471 | }); |
| 472 | |
| 473 | const result = await createFileFromTemplate({ |
| 474 | templatePath, |
| 475 | replacements: { |
| 476 | projectRef: project.externalRef, |
| 477 | triggerDirectoriesOption: triggerDir.isCustomValue |
| 478 | ? `\n triggerDirectories: ["${triggerDir.location}"],` |
| 479 | : "", |
| 480 | }, |
| 481 | outputPath, |
| 482 | override: options.overrideConfig, |
| 483 | }); |
| 484 | |
| 485 | const relativePathToOutput = relative(process.cwd(), outputPath); |
| 486 | |
| 487 | spnnr.stop( |
| 488 | result.success |
| 489 | ? `Config file created at ${relativePathToOutput}` |
| 490 | : `Failed to create config file: ${result.error}` |
| 491 | ); |
| 492 | |
| 493 | if (!result.success) { |
| 494 | throw new SkipLoggingError(result.error); |
| 495 | } |
| 496 | |
| 497 | span.end(); |
| 498 | |
| 499 | return result.success; |
| 500 | } catch (e) { |
| 501 | if (!(e instanceof SkipCommandError)) { |
| 502 | recordSpanException(span, e); |
| 503 | } |
| 504 | |
| 505 | span.end(); |
| 506 | |
| 507 | throw e; |
| 508 | } |
| 509 | }); |
no test coverage detected
searching dependent graphs…