From 4b7a144fab3a782ff45e93e84a65ead4174c1d02 Mon Sep 17 00:00:00 2001 From: manuelblum Date: Tue, 19 Nov 2024 09:58:56 +0100 Subject: [PATCH] Remove current user from createAuthResolver (#31) --- .../remove-current-user-from-auth-module.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/v8/remove-current-user-from-auth-module.ts diff --git a/src/v8/remove-current-user-from-auth-module.ts b/src/v8/remove-current-user-from-auth-module.ts new file mode 100644 index 0000000..e7e3e6d --- /dev/null +++ b/src/v8/remove-current-user-from-auth-module.ts @@ -0,0 +1,40 @@ +import { Project, SyntaxKind } from "ts-morph"; + +/** + * from + * + * createAuthResolver({ + * currentUser: CurrentUser, + * }), + * + * + * to + * + * createAuthResolver({}), + */ +export default async function removeCurrentUserFromAuthModule() { + console.log("Remove Current User From Auth Module"); + + const project = new Project({ tsConfigFilePath: "./api/tsconfig.json" }); + const sourceFiles = project.getSourceFiles("api/src/**/*.ts"); + sourceFiles.forEach((sourceFile) => { + const createAuthResolverCall = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression).find((callExpression) => { + const expression = callExpression.getExpression(); + return expression.getText() === "createAuthResolver"; + }); + + if (createAuthResolverCall) { + const argument = createAuthResolverCall.getArguments()[0]; + if (argument && argument.getKind() === SyntaxKind.ObjectLiteralExpression) { + const objectLiteral = argument.asKindOrThrow(SyntaxKind.ObjectLiteralExpression); + const currentUserProp = objectLiteral.getProperty("currentUser"); + if (currentUserProp) { + console.log("Found createAuthResolver and removed currentUser in ", sourceFile.getFilePath()); + + currentUserProp.remove(); + } + } + sourceFile.save(); + } + }); +}