-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkamelet-catalog-auto-doc.js
executable file
·49 lines (42 loc) · 1.54 KB
/
kamelet-catalog-auto-doc.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const yaml = require("yaml");
const fs = require("fs");
const handlebars = require("handlebars");
const prettier = require("prettier");
const path = require("path");
function inlineRequired(items, required) {
Object.entries(items).forEach(function([itemName, itemDefinition]) {
itemDefinition.required = required.includes(itemName);
});
}
const main = async function() {
const kameletDirPath = "src/main/resources/kamelets";
const kamelets = fs.readdirSync(kameletDirPath).map(function(fileName) {
const kamelet = yaml.parse(fs.readFileSync(path.join(kameletDirPath, fileName), "utf8"));
const {
properties = {},
required: requiredProperties = []
} = kamelet.spec.definition;
inlineRequired(properties, requiredProperties);
if (kamelet.spec?.dataTypes?.in) {
const {
headers = {},
required: requiredHeaders = []
} = kamelet.spec.dataTypes.in;
inlineRequired(headers, requiredHeaders);
}
return kamelet;
});
handlebars.registerHelper("noSpaces", function(input) {
return input.toLowerCase().replaceAll(" ", "-");
});
const catalogTemplate = handlebars.compile(fs.readFileSync("kamelet-catalog.md.handlebars", "utf8"));
const catalog = catalogTemplate(kamelets);
fs.writeFile("kamelet-catalog.md", await prettier.format(catalog, {
parser: "markdown"
}), function(err) {
if (err) {
return console.log(err);
}
});
};
main();