|
@@ -1,6 +1,5 @@
|
1
|
|
-import * as Typedoc from 'typedoc';
|
2
|
|
-import { OptionsReadMode } from 'typedoc/dist/lib/utils/options';
|
3
|
1
|
import * as fs from 'fs';
|
|
2
|
+import { ReflectionKind, ProjectReflection, DeclarationReflection, Application } from 'typedoc';
|
4
|
3
|
|
5
|
4
|
const OPTIONS = {
|
6
|
5
|
excludeExternals: true,
|
|
@@ -12,18 +11,39 @@ const OPTIONS = {
|
12
|
11
|
target: 'ES6'
|
13
|
12
|
};
|
14
|
13
|
|
|
14
|
+export interface Reflections {
|
|
15
|
+ classReflections: DeclarationReflection[];
|
|
16
|
+}
|
|
17
|
+
|
15
|
18
|
export class ReflectionsReader {
|
16
|
|
- private typedocApp: Typedoc.Application;
|
|
19
|
+ private typedocApp: Application;
|
17
|
20
|
|
18
|
21
|
constructor(tsconfigPath) {
|
19
|
22
|
const tsconfig = JSON.parse(fs.readFileSync(tsconfigPath).toString());
|
20
|
|
- this.typedocApp = new Typedoc.Application({ ...OPTIONS, ...tsconfig.compilerOptions });
|
|
23
|
+ this.typedocApp = new Application({ ...OPTIONS, ...tsconfig.compilerOptions });
|
21
|
24
|
}
|
22
|
25
|
|
23
|
|
- public read(rootPath: string): Typedoc.ProjectReflection {
|
|
26
|
+ // just class modules, TODO: extract interfaces and types to their own modules, generate docs for interfaces and types
|
|
27
|
+ public read(rootPath: string): Reflections {
|
24
|
28
|
const expandedFiles = this.typedocApp.expandInputFiles([rootPath]);
|
25
|
29
|
const projectReflection = this.typedocApp.convert(expandedFiles);
|
26
|
30
|
// console.log(JSON.stringify(this.typedocApp.serializer.projectToObject(projectReflection)));
|
27
|
|
- return projectReflection;
|
|
31
|
+
|
|
32
|
+ const externalModules = this.externalModulesWithoutTestsAndMocks(projectReflection);
|
|
33
|
+ const classReflections = this.classReflections(externalModules);
|
|
34
|
+
|
|
35
|
+ return {
|
|
36
|
+ classReflections
|
|
37
|
+ };
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ private externalModulesWithoutTestsAndMocks(projectReflection: ProjectReflection): DeclarationReflection[] {
|
|
41
|
+ return projectReflection.getChildrenByKind(ReflectionKind.ExternalModule)
|
|
42
|
+ .filter((m) => !m.name.endsWith('.mock"') && !m.name.endsWith('.test"'));
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ private classReflections(externalModules: DeclarationReflection[]): DeclarationReflection[] {
|
|
46
|
+ return externalModules.filter((m) => m.getChildrenByKind(ReflectionKind.Class).length === 1)
|
|
47
|
+ .map((m) => m.getChildrenByKind(ReflectionKind.Class)[0]);
|
28
|
48
|
}
|
29
|
49
|
}
|