UNPKG

@mendix/pluggable-widgets-tools

Version:
69 lines (68 loc) 3.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateForWidget = generateForWidget; const generateClientTypes_1 = require("./generateClientTypes"); const generateImports_1 = require("./generateImports"); const generatePreviewTypes_1 = require("./generatePreviewTypes"); const helpers_1 = require("./helpers"); const importableModules = [ new generateImports_1.ImportableModule("mendix", [ "ActionValue", "AssociationMetaData", "AttributeMetaData", "DynamicValue", "EditableFileValue", "EditableImageValue", "EditableListValue", "EditableValue", "FileValue", "ListActionValue", "ListAttributeListValue", "ListAttributeValue", "ListExpressionValue", "ListReferenceSetValue", "ListReferenceValue", "ListValue", "ListWidgetValue", "NativeIcon", "NativeImage", "ObjectItem", "Option", "ReferenceSetValue", "ReferenceValue", "SelectionMultiValue", "SelectionSingleValue", "WebIcon", "WebImage" ]), new generateImports_1.ImportableModule("react", ["ComponentType", "CSSProperties", "ReactNode"]), new generateImports_1.ImportableModule("big.js", ["Big"]) ]; function generateForWidget(widgetXml, widgetName) { var _a, _b; if (!((_a = widgetXml === null || widgetXml === void 0 ? void 0 : widgetXml.widget) === null || _a === void 0 ? void 0 : _a.properties)) { throw new Error("[XML] XML doesn't contains <properties> element"); } if (widgetXml.widget.$.pluginWidget !== "true") { throw new Error("[XML] Attribute pluginWidget=true not found. Please review your XML"); } const isNative = widgetXml.widget.$.supportedPlatform === "Native"; const propElements = (_b = widgetXml.widget.properties[0]) !== null && _b !== void 0 ? _b : []; const properties = (0, helpers_1.extractProperties)(propElements).filter(prop => { var _a; return (_a = prop === null || prop === void 0 ? void 0 : prop.$) === null || _a === void 0 ? void 0 : _a.key; }); const systemProperties = (0, helpers_1.extractSystemProperties)(propElements).filter(prop => { var _a; return (_a = prop === null || prop === void 0 ? void 0 : prop.$) === null || _a === void 0 ? void 0 : _a.key; }); const clientTypes = (0, generateClientTypes_1.generateClientTypes)(widgetName, properties, systemProperties, isNative); const modelerTypes = (0, generatePreviewTypes_1.generatePreviewTypes)(widgetName, properties, systemProperties); const generatedTypesCode = clientTypes .slice(0, clientTypes.length - 1) // all client auxiliary types .concat(modelerTypes.slice(0, modelerTypes.length - 1)) // all preview auxiliary types .concat([clientTypes[clientTypes.length - 1], modelerTypes[modelerTypes.length - 1]]) .join("\n\n"); const imports = (0, generateImports_1.generateImports)(importableModules, generatedTypesCode); return `/** * This file was generated from ${widgetName}.xml * WARNING: All changes made to this file will be overwritten * @author Mendix Widgets Framework Team */ ${imports.length ? imports.join("\n") + "\n\n" : ""}${generatedTypesCode} `; }