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

Add script to remove the parent node relation #43

Closed
wants to merge 1 commit into from
Closed
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
38 changes: 38 additions & 0 deletions src/v8/remove-parent-node-relation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { glob } from "glob";
import { Project, SyntaxKind } from "ts-morph";

/**
* Removes the parent property from the PageTreeNode entity since the relation was moved to the library.
*/
export default async function removeParentNodeRelation() {
const project = new Project({ tsConfigFilePath: "./api/tsconfig.json" });
const files: string[] = glob.sync(["api/src/**/page-tree-node.entity.ts"]);

for (const filePath of files) {
console.log(`Processing ${filePath}`);
const sourceFile = project.getSourceFile(filePath);

if (!sourceFile) {
throw new Error(`Can't get source file for ${filePath}`);
}

// Find the class declaration for PageTreeNode
const classDeclaration = sourceFile.getClassOrThrow("PageTreeNode");

// Find the property declaration for parent and remove it along with its comment
const parentProperty = classDeclaration.getProperty("parent");

if (parentProperty) {
// Remove the comment above the parent property
const commentAbove = parentProperty.getPreviousSiblingIfKind(SyntaxKind.SingleLineCommentTrivia);

if (commentAbove?.getText().includes("must be overwritten too because PageTreeNode is different from BasePageTreeNode")) {
commentAbove.replaceWithText("");
}

parentProperty.remove();
}

await sourceFile.save();
}
}
Loading