UNPKG

bitwig-types-generator

Version:
96 lines 3.6 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BitwigApiContainer = void 0; const Utils_1 = require("./Utils"); const BitwigApiClass_1 = require("./BitwigApiClass"); const BitwigApiInterface_1 = require("./BitwigApiInterface"); const BitwigApiEnum_1 = require("./BitwigApiEnum"); const Global = __importStar(require("./BitwigApiGlobal")); class BitwigApiContainer { fetcher; entities = new Map(); constructor(fetcher) { this.fetcher = fetcher; } toTypes() { const entities = [...this.entities.values()] .sort((a, b) => a.sort - b.sort) .map((entity) => entity.toType()); const module = [ Global.Header, "declare global {", "namespace Bitwig {", Global.JavaPolyfills, ...entities, "}", Global.Exports, "}", "export {}", ]; return module.filter((type) => !!type).join("\n\n"); } async fetch() { const $ = await this.fetcher.loadClasses(); const classes = new Set($(".classindex .el") .toArray() .map((el) => $(el).attr("href")?.trim() ?? "") .filter((d) => d !== "")); for (const href of classes) { await this.fetchEntity(href); } } async fetchEntity(href) { let entity = this.entities.get(href); if (!entity) { const $ = await this.fetcher.load(href); const [sourceHref, lineId] = $(".definition a.el:first-of-type") .attr("href") .split("#"); const $$ = await this.fetcher.load(sourceHref); const lineContainer = $$(`[name="${lineId}"]`).parent(); lineContainer.find(".lineno").remove(); const decl = lineContainer.text().trim(); const declaration = Utils_1.Utils.parseDeclaration(decl); const props = { declaration, href, container: this, }; switch (declaration.type) { case "class": entity = new BitwigApiClass_1.BitwigApiClass(props); break; case "interface": entity = new BitwigApiInterface_1.BitwigApiInterface(props); break; case "enum": entity = new BitwigApiEnum_1.BitwigApiEnum(props); break; } this.entities.set(href, entity); entity.parse($); } return entity; } } exports.BitwigApiContainer = BitwigApiContainer; //# sourceMappingURL=BitwigApiContainer.js.map