UNPKG

pcf-scripts

Version:

This package contains a module for building PowerApps Component Framework (PCF) controls. See project homepage how to install.

70 lines (68 loc) 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DiagnosticManager = void 0; const constants = require("./constants"); const featureManager_1 = require("./featureManager"); const locale_1 = require("./generated/locale"); class DiagnosticManager { constructor() { this._diagnostics = []; this._featureManager = new featureManager_1.FeatureManager(); } length() { return this._diagnostics.length; } push(diag) { this._diagnostics.push({ diag: diag, args: undefined }); } pushA(diag, args) { this._diagnostics.push({ diag: diag, args: args }); } pop() { return this._diagnostics.pop(); } // if no index provided return last element peek(index) { if (index && index >= this.length()) { return undefined; } return index ? this._diagnostics[index] : this._diagnostics[this.length() - 1]; } clear() { this._diagnostics = []; } hasErrors() { let hasError = false; if (this._diagnostics.length > 0) { for (const diagnostic of this._diagnostics) { if (diagnostic.diag.category === "Error") { hasError = true; break; } } } return hasError; } flush(colorize) { this._diagnostics.forEach((entry) => { let message = entry.diag.message; if (entry.diag.key && entry.args) { message = (0, locale_1.translateA)(entry.diag.key, entry.args); } else if (entry.diag.key) { message = (0, locale_1.translate)(entry.diag.key); } if (colorize && entry.diag.category === "Error") { console.log(constants.COLOR_RED_RESET, `[pcf-${entry.diag.code}] [${entry.diag.category}] ${message}`); } else if (colorize && entry.diag.category === "Warning") { console.log(constants.COLOR_YELLOW_RESET, `[pcf-${entry.diag.code}] [${entry.diag.category}] ${message}`); } else { console.log(`[pcf-${entry.diag.code}] [${entry.diag.category}] ${message}`); } }); } } exports.DiagnosticManager = DiagnosticManager; //# sourceMappingURL=diagnostic.js.map