-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
26 lines (22 loc) · 842 Bytes
/
bundle.js
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
const { readFileSync, writeFileSync } = require('fs');
const bundle = require('@asyncapi/bundler');
const { DiagnosticSeverity, Parser } = require('@asyncapi/parser');
async function main() {
// bundle
const bundledDocument = await bundle('main.yml')
writeFileSync('bundled.yaml', bundledDocument.yml());
// validate the document
const asyncApiDocument = readFileSync('bundled.yaml', 'utf-8')
const parser = new Parser();
const parse = await parser.parse(asyncApiDocument);
const parseErrors = parse.diagnostics.filter((el) => {
return el.severity == DiagnosticSeverity.Error;
});
if (parseErrors.length > 0) {
const msg = parseErrors.map((err) => {
return `${err.code}: ${err.message} [${err.path.join(' > ')}]`;
});
throw new Error(msg.join('\n'));
}
}
main().catch((e) => console.error(e));