UNPKG

bitwig-types-generator

Version:
57 lines 2.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BitwigApiFetcher = void 0; const os_1 = __importDefault(require("os")); const path_1 = __importDefault(require("path")); const which_1 = __importDefault(require("which")); const promises_1 = __importDefault(require("fs/promises")); const cheerio_1 = __importDefault(require("cheerio")); const prettier_1 = __importDefault(require("prettier")); const platform = os_1.default.platform(); const homedir = os_1.default.homedir(); const RESOURCES = "resources/doc/control-surface/api/"; const CONTROLLER_SCRIPTS = platform === "linux" ? "Bitwig Studio/Controller Scripts" : "Documents/Bitwig Studio/Controller Scripts"; class BitwigApiFetcher { api; constructor(beta = false) { const cmd = beta ? "bitwig-studio-beta" : "bitwig-studio"; this.api = new Promise(async (resolve, reject) => { try { const binPath = await (0, which_1.default)(cmd); const binRealPath = await promises_1.default.realpath(binPath); const dirPath = path_1.default.dirname(binRealPath); const apiPath = path_1.default.resolve(dirPath, RESOURCES); resolve(apiPath); } catch (e) { reject(e); } }); } async loadClasses() { return this.load("classes.html"); } async load(html) { const api = await this.api; const classesPath = path_1.default.resolve(api, html); const body = await promises_1.default.readFile(classesPath, "utf-8"); return cheerio_1.default.load(body); } async save(ts) { const file = `bitwig.d.ts`; const filepath = path_1.default.resolve(homedir, CONTROLLER_SCRIPTS, file); ts = await prettier_1.default.format(ts, { filepath, parser: "babel-ts", }); await promises_1.default.writeFile(filepath, ts); return filepath; } } exports.BitwigApiFetcher = BitwigApiFetcher; //# sourceMappingURL=BitwigApiFetcher.js.map