-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
67 lines (56 loc) · 2.25 KB
/
main.ts
File metadata and controls
67 lines (56 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as ts from 'typescript';
import { Filereader } from './filereader';
const filereader = new Filereader();
main();
async function main(): Promise<void> {
const result: UmlClass[] = [];
const data = await filereader.read('Stadt.ts.inspect');
// const data = await filereader.read('print.service.ts.inspect');
const sc = ts.createSourceFile('x.ts', data, ts.ScriptTarget.Latest, true);
let indent = 0;
function print(node: ts.Node) {
switch (node.kind) {
case ts.SyntaxKind.ClassDeclaration:
case ts.SyntaxKind.InterfaceDeclaration:
const classDeclaration: ts.ClassDeclaration = <ts.ClassDeclaration>node;
const newUmlClass: UmlClass = {
name: classDeclaration.name!.getFullText(),
isInterface: node.kind === ts.SyntaxKind.InterfaceDeclaration,
dependsOn: [],
inherits: []
};
if (classDeclaration.heritageClauses) {
const heritageClauses: ts.NodeArray<ts.HeritageClause> = classDeclaration.heritageClauses!;
heritageClauses.forEach(heritageClause => {
heritageClause.types.forEach(expressionWithTypeArguments => {
if (ts.isIdentifier(expressionWithTypeArguments.expression)) {
const identifier: ts.Identifier = <ts.Identifier>expressionWithTypeArguments.expression
newUmlClass.inherits.push(
identifier.text
);
}
});
});
}
result.push(newUmlClass);
break;
case ts.SyntaxKind.ImportDeclaration:
break;
default:
break;
}
console.log(new Array(indent + 1).join('.') + ts.SyntaxKind[node.kind] + ': ' + node.getFullText());
indent++;
ts.forEachChild(node, print);
indent--;
}
print(sc);
console.log(result);
return;
}
interface UmlClass {
name: string;
isInterface: boolean;
dependsOn: string[];
inherits: string[];
}