Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove current user from createAuthResolver #31

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/v8/remove-current-user-from-auth-module.ts
Original file line number Diff line number Diff line change
@@ -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();
}
});
}
Loading