Extract all the classes using ts-morph but not work?

79 Views Asked by At

I cloned the opensource project and I want to extract all the classes from it.

import { Project } from "ts-morph";

const project = new Project();
project.addSourceFilesAtPaths("/Users/mark/github_repo/XFlow/packages/xflow-core/src/**/*.ts[x]");

// get all the classes
const classes = project.getSourceFiles().flatMap(sf => sf.getClasses());

// get the inherit relations
const classInherits = classes.reduce((result, clazz) => {
  const superClass = clazz.getBaseClass();
  if (superClass) {
    const superClassName = superClass.getName();
    result[clazz.getName()] = superClassName;
  }
  return result;
}, {});

console.log(classInherits);

but it get {}(nothing here),


and I an sure my code is available, because I change the path to

project.addSourceFilesAtPaths("/Users/mark/github_repo/XFlow/packages/xflow-core/**/*.ts");

It will print out all the classes under it.

Why the below paths do not work?

/Users/mark/github_repo/XFlow/packages/xflow-core/src/**/*.ts
/Users/mark/github_repo/XFlow/packages/xflow-core/**/*.ts[x]

In my code there is class: in /Users/mark/github_repo/XFlow/packages/xflow-core/src/menu/menu-registry.ts:

export class MenuRegistry implements IMenuService, IFrontendApplicationContribution {...}
0

There are 0 best solutions below