-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
55 lines (47 loc) · 1.46 KB
/
index.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
import { AsyncAPIDocumentInterface } from '@asyncapi/parser';
import { validateAsyncApi } from './validateEssential';
import { renderRustWsClientFromAsyncApi } from './render';
// import { getAsyncApiYamlFiles } from './fetchRemoteConfig';
interface TemplateParams {
// exchange name, required
exchange: string;
// to validate or not, default to true
validate: boolean;
// to render or not, default to true
render: boolean;
// websocket library to generate, currently only supports tokio-tungstenite
library?: 'tokio-tungstenite' | 'async-tungstenite';
}
interface TemplateProps {
asyncapi: AsyncAPIDocumentInterface;
params: TemplateParams;
}
export default async function ({ asyncapi, params }: TemplateProps) {
// validates a AsyncAPI file
if (params.validate) {
const missing_items = validateAsyncApi(asyncapi);
if (missing_items.length > 0) {
console.log('missing below');
for (const missing_item of missing_items) {
console.log(missing_item);
}
return [];
} else {
console.log('all files verified');
}
}
const exchangeName = params.exchange ? params.exchange : 'Exchange';
// renders websocket client
if (params.render) {
const files = await renderRustWsClientFromAsyncApi(asyncapi, exchangeName);
console.log(`render files: ${files.length}`);
const collection: React.ReactElement[] = [];
for (const file of files) {
collection.push(file.render());
}
return collection;
// return rendered;
} else {
return [];
}
}