-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathindex-file.ts
33 lines (31 loc) · 1 KB
/
index-file.ts
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
import {
ExportDeclarationStructure,
SourceFileStructure,
StructureKind
} from 'ts-morph';
import { VdmServiceMetadata } from '../vdm-types';
import { hasEntities } from '../generator-utils';
export function indexFile(service: VdmServiceMetadata): SourceFileStructure {
return {
kind: StructureKind.SourceFile,
statements: [
...service.entities.map(entity => exportStatement(entity.className)),
...service.entities.map(entity =>
exportStatement(`${entity.className}RequestBuilder`)
),
...service.complexTypes.map(complexType =>
exportStatement(complexType.typeName)
),
...(service.functionImports && service.functionImports.length
? [exportStatement('function-imports')]
: []),
...(hasEntities(service) ? [exportStatement('BatchRequest')] : [])
]
};
}
function exportStatement(moduleName: string): ExportDeclarationStructure {
return {
kind: StructureKind.ExportDeclaration,
moduleSpecifier: `./${moduleName}`
};
}