blob: e15bcd8fa7a33832eca0a3c40cc0decd5155af7d (
plain)
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
|
import type { ClassDeclaration, MethodDeclaration, SourceFile } from 'ts-morph';
import { getProject } from '../../../scripts/apidocs/project';
/**
* Loads the example methods.
*/
export function loadExampleMethods(): Record<string, MethodDeclaration> {
return Object.fromEntries(
loadProjectFile('test/scripts/apidocs/method.example.ts')
.getClassOrThrow('SignatureTest')
.getMethods()
.map((m) => [m.getName(), m] as const)
.sort(([a], [b]) => a.localeCompare(b)) // Relevant for Object.keys() order
);
}
/**
* Loads the example classes.
*/
export function loadExampleClasses(): Record<string, ClassDeclaration> {
return Object.fromEntries(
loadProjectFile('test/scripts/apidocs/class.example.ts')
.getClasses()
.map((m) => [m.getNameOrThrow(), m] as const)
.sort(([a], [b]) => a.localeCompare(b)) // Relevant for Object.keys() order
);
}
/**
* Loads the project.
*
* @param sourceFile The source file to load.
*/
function loadProjectFile(sourceFile: string): SourceFile {
const project = getProject();
return project.addSourceFileAtPath(sourceFile);
}
|