@shko.online/componentframework-mock-cli
Version:
Command line interface for @shko.online/componentframework-mock
145 lines • 5.36 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const handlebars_1 = __importDefault(require("handlebars"));
const promises_1 = require("fs/promises");
class Renderer {
constructor() {
handlebars_1.default.registerHelper("GetPropertyMocks", this.GetPropertyMocks.bind(this));
handlebars_1.default.registerHelper("ControlToPropertyMock", this.ControlToPropertyMock.bind(this));
handlebars_1.default.registerHelper("ControlToType", this.ControlToType.bind(this));
handlebars_1.default.registerHelper("isVirtualComponent", this.isVirtualComponent.bind(this));
handlebars_1.default.registerHelper("GetOutputProperties", this.GetOutputProperties.bind(this));
}
GetPropertyMocks(inputs) {
const propertyMocks = [];
inputs.forEach((property) => {
var mock = this.ControlToPropertyMock(property);
if (!propertyMocks.includes(mock)) {
propertyMocks.push(mock);
}
});
return propertyMocks.join(", ");
}
isVirtualComponent(mockGenerator) {
return mockGenerator === "ComponentFrameworkMockGeneratorReact";
}
ControlToPropertyMock(control) {
switch (control.type) {
case "DateAndTime.DateOnly":
case "DateAndTime.DateAndTime":
return "DateTimePropertyMock";
case "Multiple":
case "SingleLine.Text":
case "SingleLine.Email":
case "SingleLine.Phone":
case "SingleLine.TextArea":
case "SingleLine.Ticker":
case "SingleLine.URL":
return "StringPropertyMock";
case "TwoOptions":
return "TwoOptionsPropertyMock";
case "Enum":
return "EnumPropertyMock";
case "Currency":
case "Decimal":
return "DecimalNumberPropertyMock";
case "Lookup.Simple":
return "LookupPropertyMock";
case "Whole.None":
return "WholeNumberPropertyMock";
case "OptionSet":
return "OptionSetPropertyMock";
case "MultiSelectOptionSet":
return "MultiSelectOptionSetPropertyMock";
case "FP":
return "DecimalNumberPropertyMock";
default:
return "ERROR!" + control["type"];
}
}
ControlToType(control) {
switch (control.type) {
case "DateAndTime.DateOnly":
case "DateAndTime.DateAndTime":
return "Date";
case "Multiple":
case "SingleLine.Text":
case "SingleLine.Email":
case "SingleLine.Phone":
case "SingleLine.TextArea":
case "SingleLine.Ticker":
case "SingleLine.URL":
return "string";
case "TwoOptions":
return "boolean";
case "Enum":
return control.enumValues.map((v) => '"' + v.value + '"').join(" | ");
case "Lookup.Simple":
return "ComponentFramework.LookupValue";
case "Currency":
case "Decimal":
case "FP":
case "Whole.None":
case "OptionSet":
return "number";
case "MultiSelectOptionSet":
return "number[]";
default:
return "ERROR" + control["type"];
}
}
ControlToOutputTypes(control) {
switch (control.type) {
case "DateAndTime.DateAndTime":
case "DateAndTime.DateOnly":
return "Date";
case "Currency":
case "Decimal":
case "Whole.None":
case "FP":
case "OptionSet":
return "number";
case "Lookup.Simple":
return "Lookup";
case "Multiple":
return "string";
case "Object":
return "any";
case "MultiSelectOptionSet":
return "number[]";
case "SingleLine.Email":
case "SingleLine.Phone":
case "SingleLine.Text":
case "SingleLine.TextArea":
case "SingleLine.Ticker":
case "SingleLine.URL":
return "string";
case "TwoOptions":
return "boolean";
default:
return "ERROR!" + control["type"];
}
}
GetOutputProperties(inputs) {
var t = inputs
.filter((property) => property.usage == "bound" || property.usage == "output")
.map((property) => {
return {
name: property.name,
type: this.ControlToOutputTypes(property),
};
});
return t;
}
async Render(data) {
const buffer = await (0, promises_1.readFile)(require.resolve("./renderGenerator.template.hbs"));
const template = handlebars_1.default.compile(buffer.toString());
const dts = template({ data });
return dts;
}
}
exports.default = Renderer;
//# sourceMappingURL=Renderer.js.map