forked from Onlineberatung/onlineBeratung-frontend
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdtsgen.ts
82 lines (78 loc) · 2.02 KB
/
dtsgen.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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { promises as fs } from 'fs';
import path from 'path';
import dtsgenerator, { readSchemaFromUrl } from 'dtsgenerator';
import prettier from 'prettier';
const rawOrgUrl = 'https://raw.githubusercontent.com/CaritasDeutschland';
const services = [
{
path: 'caritas-onlineBeratung-userService/develop/api/userservice.yaml',
namespace: 'UserService',
out: 'userservice.d.ts'
},
{
path: 'caritas-onlineBeratung-agencyService/develop/api/agencyservice.yaml',
namespace: 'AgencyService',
out: 'agencyservice.d.ts'
},
{
path: 'caritas-onlineBeratung-uploadService/develop/api/uploadservice.yaml',
namespace: 'UploadService',
out: 'uploadservice.d.ts'
},
{
path: 'caritas-onlineBeratung-messageService/develop/api/messageservice.yaml',
namespace: 'MessageService',
out: 'messageservice.d.ts'
},
{
path: 'caritas-onlineBeratung-mailService/develop/api/mailservice.yaml',
namespace: 'MailService',
out: 'mailservice.d.ts'
},
{
path: 'caritas-onlineBeratung-liveService/develop/api/liveservice.yaml',
namespace: 'LiveService',
out: 'liveservice.d.ts'
},
{
path: 'caritas-onlineBeratung-videoService/develop/api/videoservice.yaml',
namespace: 'VideoService',
out: 'videoservice.d.ts'
}
];
(async () => {
try {
const prettierConfigFile = await prettier.resolveConfigFile();
const prettierConfig = await prettier.resolveConfig(prettierConfigFile);
for (const service of services) {
const schema = await readSchemaFromUrl(
`${rawOrgUrl}/${service.path}`
);
const content = await dtsgenerator({
contents: [schema],
config: {
plugins: {
'@dtsgenerator/replace-namespace': {
map: [
{
from: ['Components', 'Schema'],
to: [service.namespace]
}
]
}
}
}
});
await fs.writeFile(
path.join('src', 'generated', service.out),
prettier.format(content, {
parser: 'typescript',
...prettierConfig
})
);
}
} catch (err) {
console.error(`Something went wrong: ${err}`);
process.exit(1);
}
})();