bitwig-types-generator
Version:
Generated Types for Bitwig scripting API
113 lines • 4.46 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BitwigApiEntity = void 0;
const cheerio_1 = __importDefault(require("cheerio"));
const Utils_1 = require("./Utils");
class BitwigApiEntity {
props;
description = "";
constructor(props) {
this.props = props;
}
get href() {
return this.props.href;
}
get declaration() {
return this.props.declaration;
}
notImplemented(method) {
const name = Object.getPrototypeOf(this).constructor.name;
throw new Error(`not implemented: ${name}.${method}`);
}
setPublicMemberFunctions(item) {
this.notImplemented("setPublicMemberFunctions");
}
setPublicAttributes(item) {
this.notImplemented("setPublicAttributes");
}
setClasses(item) {
this.notImplemented("setClasses");
}
setStaticPublicAttributes(item) {
this.notImplemented("setStaticPublicAttributes");
}
setStaticPublicMemberFunctions(item) {
this.notImplemented("setStaticPublicMemberFunctions");
}
setMemberFunctionDocumentation(id, desc) {
this.notImplemented("setMemberFunctionDocumentation");
}
mapItems(el) {
const parent = (0, cheerio_1.default)(el).parentsUntil(".contents").last();
const items = parent
.find('[class*="memitem:"]')
.toArray()
.filter((el) => !el.attribs.class.includes("inherit"))
.map((el) => {
const id = Utils_1.Utils.parseMemitem(el.attribs.class);
const type = (0, cheerio_1.default)(".memItemLeft", el).text().trim();
const def = (0, cheerio_1.default)(".memItemRight", el).text().trim();
return { id, type, def };
});
return items;
}
parse($$) {
$$(".groupheader").each((_i, el) => {
const group = $$(el).text().trim();
switch (group) {
case "Public Member Functions":
this.mapItems(el).forEach((item) => this.setPublicMemberFunctions(item));
break;
case "Public Attributes":
this.mapItems(el).forEach((item) => this.setPublicAttributes(item));
break;
case "Classes":
this.mapItems(el).forEach((item) => this.setClasses(item));
break;
case "Static Public Attributes":
this.mapItems(el).forEach((item) => this.setStaticPublicAttributes(item));
break;
case "Static Public Member Functions":
this.mapItems(el).forEach((item) => this.setStaticPublicMemberFunctions(item));
break;
case "Detailed Description":
$$(".definition").remove();
this.description = Utils_1.Utils.parseDescription($$(el).next(".textblock"), this.declaration.name);
break;
/**
* @Documenation
*/
case "Constructor & Destructor Documentation":
break;
case "Member Function Documentation":
for (const element of $$(el)
.nextUntil(".groupheader,hr")
.filter("a[id]")) {
const memitem = $$(element).nextAll().filter(".memitem").first();
const desc = Utils_1.Utils.parseDescription(memitem.find(".memdoc"), this.declaration.name);
this.setMemberFunctionDocumentation(element.attribs.id, desc);
}
break;
case "Member Data Documentation":
/**
* @Todo
* enum type Documentation
*/
break;
/**
* @Ignored
*/
case "Additional Inherited Members":
case "Protected Member Functions":
break;
default:
throw new Error(`Unknown groupheader ${group}`);
}
});
}
}
exports.BitwigApiEntity = BitwigApiEntity;
//# sourceMappingURL=BitwigApiEntity.js.map