Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdax98 committed Jan 10, 2025
1 parent 2cc5018 commit a747e6c
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/v7/replace-exception-interceptor-with-exception-filter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { readFile, writeFile } from "fs/promises";
import { Project } from "ts-morph";

import { formatCode } from "../util/format-code.util";

Expand All @@ -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();
}

0 comments on commit a747e6c

Please sign in to comment.