UNPKG

@shko.online/componentframework-mock-cli

Version:

Command line interface for @shko.online/componentframework-mock

60 lines 2.69 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ManifestParser = void 0; const libxmljs_1 = __importDefault(require("libxmljs")); class ManifestParser { constructor(VERBOSE) { this.VERBOSE = VERBOSE; } async Parse(manifest) { var _a, _b, _c; const xmlDoc = await libxmljs_1.default.parseXmlAsync(manifest); const control = xmlDoc.find("/manifest/control")[0]; const result = { Component: (_a = control.getAttribute("constructor")) === null || _a === void 0 ? void 0 : _a.value(), ComponentIndex: (_b = xmlDoc.find("/manifest/control/resources/code[@order='1']")[0] .getAttribute("path")) === null || _b === void 0 ? void 0 : _b.value(), MockGenerator: ((_c = control.getAttribute("control-type")) === null || _c === void 0 ? void 0 : _c.value()) === "virtual" ? "ComponentFrameworkMockGeneratorReact" : "ComponentFrameworkMockGenerator", Inputs: xmlDoc.find("/manifest/control/property").map((p) => { var _a, _b, _c; const type = (_a = p .getAttribute("of-type")) === null || _a === void 0 ? void 0 : _a.value(); const name = (_b = p.getAttribute("name")) === null || _b === void 0 ? void 0 : _b.value(); const usage = (_c = p .getAttribute("usage")) === null || _c === void 0 ? void 0 : _c.value(); if (type === "Enum") { const enumValues = p.find("value").map((v) => { var _a; return ({ name: (_a = v.getAttribute("name")) === null || _a === void 0 ? void 0 : _a.value(), value: v.text(), }); }); return { type, name, usage, enumValues, }; } return { type, name, usage, }; }), Styles: xmlDoc.find("/manifest/control/resources/css").map((p) => { var _a; return (_a = p.getAttribute("path")) === null || _a === void 0 ? void 0 : _a.value(); }), }; return result; } } exports.ManifestParser = ManifestParser; //# sourceMappingURL=ManifestParser.js.map