From a747e6c7f0091cf9b2a4d6e7f4df1b4f84afc0b2 Mon Sep 17 00:00:00 2001 From: Thomas Dax Date: Fri, 10 Jan 2025 10:57:20 +0100 Subject: [PATCH] Simplify --- ...ption-interceptor-with-exception-filter.ts | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/v7/replace-exception-interceptor-with-exception-filter.ts b/src/v7/replace-exception-interceptor-with-exception-filter.ts index a6f73be..de3f74d 100644 --- a/src/v7/replace-exception-interceptor-with-exception-filter.ts +++ b/src/v7/replace-exception-interceptor-with-exception-filter.ts @@ -1,5 +1,4 @@ import { readFile, writeFile } from "fs/promises"; -import { Project } from "ts-morph"; import { formatCode } from "../util/format-code.util"; @@ -15,24 +14,11 @@ export default async function replaceExceptionInterceptorWithExceptionFilter() { return; } - const searchString = "app.useGlobalInterceptors\\(new ExceptionInterceptor\\(config.debug\\)\\);"; - const re = new RegExp(`^.*${searchString}.*$`, "gm"); - fileContent = fileContent.replace(re, "app.useGlobalFilters(new ExceptionFilter(config.debug));"); + fileContent = fileContent.replace( + "app.useGlobalInterceptors(new ExceptionInterceptor(config.debug));", + "app.useGlobalFilters(new ExceptionFilter(config.debug));", + ); + fileContent = fileContent.replace("ExceptionInterceptor", "ExceptionFilter"); await writeFile(filePath, await formatCode(fileContent, filePath)); - - const project = new Project({ tsConfigFilePath: "./api/tsconfig.json" }); - - const sourceFile = project.getSourceFile(filePath); - - if (!sourceFile) { - throw new Error(`Can't get source file for ${filePath}`); - } - - sourceFile.addImportDeclaration({ - namedImports: ["ExceptionFilter"], - moduleSpecifier: "@comet/cms-api", - }); - - sourceFile.saveSync(); }