pcf-scripts
Version:
This package contains a module for building PowerApps Component Framework (PCF) controls. See project homepage how to install.
71 lines (69 loc) • 2.5 kB
JavaScript
// Copyright (C) Microsoft Corporation. All rights reserved.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ControlContext = void 0;
const fs_extra_1 = require("fs-extra");
const lodash_1 = require("lodash");
const path = require("node:path");
const xml2js_1 = require("xml2js");
const constants = require("./constants");
const controlManifest_1 = require("./controlManifest");
const diagnosticMessages_generated_1 = require("./diagnosticMessages.generated");
class ControlContext {
constructor(diag, controlPath) {
this.controlPath = controlPath;
this.loadControlManifest(diag);
}
getControlManifest() {
return this.manifest;
}
getControlName() {
return this.manifest.getConstructor();
}
getControlFolderName() {
return path.basename(this.controlPath);
}
getControlPath() {
return this.controlPath;
}
getControlNamespace() {
return this.manifest.getNamespace();
}
getCodeRelativePath() {
return this.manifest.getCodePath();
}
getParsedManifest() {
return this.parsedResult;
}
reloadManifest(diag) {
this.loadControlManifest(diag);
}
// Load control manifest input file
loadControlManifest(diag) {
const manifestPath = path.join(this.controlPath, constants.MANIFEST_INPUT_FILE_NAME);
const rawXml = (0, fs_extra_1.readFileSync)(manifestPath, { encoding: "utf8" });
const data = {};
(0, xml2js_1.parseString)(rawXml, (err, result) => {
if (err) {
diag.pushA(diagnosticMessages_generated_1.strings.manifest_parsing_error, [err.message]);
}
else {
this.parsedResult = (0, lodash_1.cloneDeep)(result);
// flatten all explicit arrays
if (Array.isArray(result?.manifest?.control)) {
const controlNode = result.manifest.control[0];
data.manifest = {
control: {
...controlNode,
resources: controlNode.resources?.[0],
"feature-usage": controlNode["feature-usage"]?.[0],
},
};
}
}
});
this.manifest = new controlManifest_1.ControlManifest(data);
}
}
exports.ControlContext = ControlContext;
//# sourceMappingURL=controlContext.js.map
;