UNPKG

@agility/cli

Version:

Agility CLI for working with your content. (Public Beta)

812 lines 49.3 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Logs = void 0; var ansi_colors_1 = __importDefault(require("ansi-colors")); var state_1 = require("./state"); var fs = __importStar(require("fs")); var path = __importStar(require("path")); var shared_1 = require("../lib/shared"); var Logs = /** @class */ (function () { function Logs(operationType, entityType, guid) { var _this = this; this.logs = []; this.guidColorMap = new Map(); this.availableColors = [ "magenta", "cyan", "yellow", "blue", "green", "gray", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", ]; /** * Structured entity logging - each entity type has its own methods */ // Asset logging methods this.asset = { downloaded: function (entity, details) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.fileName) || (entity === null || entity === void 0 ? void 0 : entity.name) || "Asset ".concat((entity === null || entity === void 0 ? void 0 : entity.mediaID) || "Unknown"); _this.logDataElement("asset", "downloaded", "success", itemName, _this.guid, details); }, uploaded: function (entity, details, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.fileName) || (entity === null || entity === void 0 ? void 0 : entity.name) || "Asset ".concat((entity === null || entity === void 0 ? void 0 : entity.mediaID) || "Unknown"); _this.logDataElement("asset", "uploaded", "success", itemName, targetGuid, details); }, skipped: function (entity, details, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.fileName) || (entity === null || entity === void 0 ? void 0 : entity.name) || "Asset ".concat((entity === null || entity === void 0 ? void 0 : entity.mediaID) || "Unknown"); _this.logDataElement("asset", "skipped", "skipped", itemName, targetGuid || _this.guid, details); }, error: function (payload, apiError, targetGuid) { var itemName = (payload === null || payload === void 0 ? void 0 : payload.fileName) || (payload === null || payload === void 0 ? void 0 : payload.name) || "Asset ".concat((payload === null || payload === void 0 ? void 0 : payload.mediaID) || "Unknown"); var errorDetails = (apiError === null || apiError === void 0 ? void 0 : apiError.message) || apiError || "Unknown error"; // we need a better error logger for data elements _this.logDataElement("asset", "failed", "failed", itemName, targetGuid || _this.guid, errorDetails); var asset = (payload === null || payload === void 0 ? void 0 : payload.asset) || payload; console.log("error", asset); }, }; // Model logging methods this.model = { downloaded: function (entity, details) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.referenceName) || (entity === null || entity === void 0 ? void 0 : entity.displayName) || "Model ".concat((entity === null || entity === void 0 ? void 0 : entity.id) || "Unknown"); _this.logDataElement("model", "downloaded", "success", itemName, _this.guid, details); }, created: function (entity, details, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.referenceName) || (entity === null || entity === void 0 ? void 0 : entity.displayName) || "Model ".concat((entity === null || entity === void 0 ? void 0 : entity.id) || "Unknown"); _this.logDataElement("model", "created", "success", itemName, targetGuid, details); }, updated: function (entity, details, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.referenceName) || (entity === null || entity === void 0 ? void 0 : entity.displayName) || "Model ".concat((entity === null || entity === void 0 ? void 0 : entity.id) || "Unknown"); _this.logDataElement("model", "updated", "success", itemName, targetGuid, details); }, uploaded: function (entity, details) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.referenceName) || (entity === null || entity === void 0 ? void 0 : entity.displayName) || "Model ".concat((entity === null || entity === void 0 ? void 0 : entity.id) || "Unknown"); _this.logDataElement("model", "uploaded", "success", itemName, _this.guid, details); }, skipped: function (entity, details, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.referenceName) || (entity === null || entity === void 0 ? void 0 : entity.displayName) || "Model ".concat((entity === null || entity === void 0 ? void 0 : entity.id) || "Unknown"); _this.logDataElement("model", "skipped", "skipped", itemName, targetGuid || _this.guid, details); }, error: function (payload, apiError, targetGuid) { var itemName = (payload === null || payload === void 0 ? void 0 : payload.referenceName) || (payload === null || payload === void 0 ? void 0 : payload.displayName) || "Model ".concat((payload === null || payload === void 0 ? void 0 : payload.id) || "Unknown"); var errorDetails = (apiError === null || apiError === void 0 ? void 0 : apiError.message) || apiError || "Unknown error"; // we need a better error logger for data elements _this.logDataElement("model", "error", "failed", itemName, targetGuid || _this.guid, errorDetails); }, }; // Container logging methods this.container = { downloaded: function (entity, details) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.referenceName) || (entity === null || entity === void 0 ? void 0 : entity.name) || "Container ".concat((entity === null || entity === void 0 ? void 0 : entity.contentViewID) || "Unknown"); _this.logDataElement("container", "downloaded", "success", itemName, _this.guid, details); }, created: function (entity, details, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.referenceName) || (entity === null || entity === void 0 ? void 0 : entity.name) || "Container ".concat((entity === null || entity === void 0 ? void 0 : entity.contentViewID) || "Unknown"); _this.logDataElement("container", "created", "success", itemName, targetGuid, details); }, updated: function (entity, details, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.referenceName) || (entity === null || entity === void 0 ? void 0 : entity.name) || "Container ".concat((entity === null || entity === void 0 ? void 0 : entity.contentViewID) || "Unknown"); _this.logDataElement("container", "updated", "success", itemName, targetGuid, details); }, uploaded: function (entity, details) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.referenceName) || (entity === null || entity === void 0 ? void 0 : entity.name) || "Container ".concat((entity === null || entity === void 0 ? void 0 : entity.contentViewID) || "Unknown"); _this.logDataElement("container", "uploaded", "success", itemName, _this.guid, details); }, skipped: function (entity, details, targetGuid) { // console.log(ansiColors.yellow('skipped'), entity) var itemName = (entity === null || entity === void 0 ? void 0 : entity.referenceName) || (entity === null || entity === void 0 ? void 0 : entity.name) || "Container ".concat((entity === null || entity === void 0 ? void 0 : entity.contentViewID) || "Unknown"); _this.logDataElement("container", "skipped", "skipped", itemName, targetGuid || _this.guid, details); }, error: function (payload, apiError, targetGuid) { var itemName = (payload === null || payload === void 0 ? void 0 : payload.referenceName) || (payload === null || payload === void 0 ? void 0 : payload.name) || "Container ".concat((payload === null || payload === void 0 ? void 0 : payload.contentViewID) || "Unknown"); var errorDetails = (apiError === null || apiError === void 0 ? void 0 : apiError.message) || apiError || "Unknown error"; // we need a better error logger for data elements _this.logDataElement("container", "error", "failed", itemName, targetGuid || _this.guid, errorDetails); }, }; // Content Item logging methods this.content = { downloaded: function (entity, details, locale) { var _a; var itemName = ((_a = entity === null || entity === void 0 ? void 0 : entity.properties) === null || _a === void 0 ? void 0 : _a.referenceName) || "".concat((entity === null || entity === void 0 ? void 0 : entity.contentID) || "Unknown"); _this.logDataElement("content", "downloaded", "success", itemName, _this.guid, details, locale); }, uploaded: function (entity, details, locale, targetGuid) { var _a, _b, _c; var itemName = ((_a = entity === null || entity === void 0 ? void 0 : entity.properties) === null || _a === void 0 ? void 0 : _a.referenceName) || ((_b = entity === null || entity === void 0 ? void 0 : entity.fields) === null || _b === void 0 ? void 0 : _b.title) || ((_c = entity === null || entity === void 0 ? void 0 : entity.fields) === null || _c === void 0 ? void 0 : _c.name) || "Content ".concat((entity === null || entity === void 0 ? void 0 : entity.contentID) || "Unknown"); _this.logDataElement("content", "uploaded", "success", itemName, targetGuid || _this.guid, details, locale); }, created: function (entity, details, locale, targetGuid) { var _a, _b, _c; var itemName = ((_a = entity === null || entity === void 0 ? void 0 : entity.properties) === null || _a === void 0 ? void 0 : _a.referenceName) || ((_b = entity === null || entity === void 0 ? void 0 : entity.fields) === null || _b === void 0 ? void 0 : _b.title) || ((_c = entity === null || entity === void 0 ? void 0 : entity.fields) === null || _c === void 0 ? void 0 : _c.name) || "Content ".concat((entity === null || entity === void 0 ? void 0 : entity.contentID) || "Unknown"); _this.logDataElement("content", "created", "success", itemName, targetGuid || _this.guid, details, locale); }, updated: function (entity, details, locale, targetGuid) { var _a, _b, _c; var itemName = ((_a = entity === null || entity === void 0 ? void 0 : entity.properties) === null || _a === void 0 ? void 0 : _a.referenceName) || ((_b = entity === null || entity === void 0 ? void 0 : entity.fields) === null || _b === void 0 ? void 0 : _b.title) || ((_c = entity === null || entity === void 0 ? void 0 : entity.fields) === null || _c === void 0 ? void 0 : _c.name) || "Content ".concat((entity === null || entity === void 0 ? void 0 : entity.contentID) || "Unknown"); _this.logDataElement("content", "updated", "success", itemName, targetGuid || _this.guid, details, locale); }, skipped: function (entity, details, locale, targetGuid) { var _a, _b, _c; var itemName = ((_a = entity === null || entity === void 0 ? void 0 : entity.properties) === null || _a === void 0 ? void 0 : _a.referenceName) || ((_b = entity === null || entity === void 0 ? void 0 : entity.fields) === null || _b === void 0 ? void 0 : _b.title) || ((_c = entity === null || entity === void 0 ? void 0 : entity.fields) === null || _c === void 0 ? void 0 : _c.name) || "Content ".concat((entity === null || entity === void 0 ? void 0 : entity.contentID) || "Unknown"); _this.logDataElement("content", "skipped", "skipped", itemName, targetGuid || _this.guid, details, locale); }, error: function (payload, apiError, locale, targetGuid) { var _a, _b, _c; var itemName = ((_a = payload === null || payload === void 0 ? void 0 : payload.properties) === null || _a === void 0 ? void 0 : _a.referenceName) || ((_b = payload === null || payload === void 0 ? void 0 : payload.fields) === null || _b === void 0 ? void 0 : _b.title) || ((_c = payload === null || payload === void 0 ? void 0 : payload.fields) === null || _c === void 0 ? void 0 : _c.name) || "Content ".concat((payload === null || payload === void 0 ? void 0 : payload.contentID) || "Unknown"); var errorDetails = (apiError === null || apiError === void 0 ? void 0 : apiError.message) || apiError || "Unknown error"; // we need a better error logger for data elements _this.logDataElement("content", "error", "failed", itemName, targetGuid || _this.guid, errorDetails, locale); }, }; // Template logging methods this.template = { downloaded: function (entity, details) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.pageTemplateName) || (entity === null || entity === void 0 ? void 0 : entity.name) || "Template ".concat((entity === null || entity === void 0 ? void 0 : entity.pageTemplateID) || "Unknown"); _this.logDataElement("template", "downloaded", "success", itemName, _this.guid, details); }, uploaded: function (entity, details) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.pageTemplateName) || (entity === null || entity === void 0 ? void 0 : entity.name) || "Template ".concat((entity === null || entity === void 0 ? void 0 : entity.pageTemplateID) || "Unknown"); _this.logDataElement("template", "uploaded", "success", itemName, _this.guid, details); }, created: function (entity, details, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.pageTemplateName) || (entity === null || entity === void 0 ? void 0 : entity.name) || "Template ".concat((entity === null || entity === void 0 ? void 0 : entity.pageTemplateID) || "Unknown"); _this.logDataElement("template", "created", "success", itemName, targetGuid, details); }, updated: function (entity, details, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.pageTemplateName) || (entity === null || entity === void 0 ? void 0 : entity.name) || "Template ".concat((entity === null || entity === void 0 ? void 0 : entity.pageTemplateID) || "Unknown"); _this.logDataElement("template", "updated", "success", itemName, targetGuid, details); }, skipped: function (entity, details, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.pageTemplateName) || (entity === null || entity === void 0 ? void 0 : entity.name) || "Template ".concat((entity === null || entity === void 0 ? void 0 : entity.pageTemplateID) || "Unknown"); _this.logDataElement("template", "skipped", "skipped", itemName, targetGuid || _this.guid, details); }, error: function (payload, apiError, targetGuid) { var itemName = (payload === null || payload === void 0 ? void 0 : payload.pageTemplateName) || (payload === null || payload === void 0 ? void 0 : payload.name) || "Template ".concat((payload === null || payload === void 0 ? void 0 : payload.pageTemplateID) || "Unknown"); var errorDetails = (apiError === null || apiError === void 0 ? void 0 : apiError.message) || apiError || "Unknown error"; // we need a better error logger for data elements _this.logDataElement("template", "failed", "failed", itemName, targetGuid || _this.guid, errorDetails); }, }; // Page logging methods this.page = { downloaded: function (entity, details, locale) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.name) || (entity === null || entity === void 0 ? void 0 : entity.menuText) || "Page ".concat((entity === null || entity === void 0 ? void 0 : entity.pageID) || "Unknown"); _this.logDataElement("page", "downloaded", "success", itemName, _this.guid, details, locale); }, uploaded: function (entity, details, locale, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.name) || (entity === null || entity === void 0 ? void 0 : entity.menuText) || "Page ".concat((entity === null || entity === void 0 ? void 0 : entity.pageID) || "Unknown"); _this.logDataElement("page", "uploaded", "success", itemName, targetGuid || _this.guid, details, locale); }, updated: function (entity, details, locale, channel, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.name) || (entity === null || entity === void 0 ? void 0 : entity.menuText) || "Page ".concat((entity === null || entity === void 0 ? void 0 : entity.pageID) || "Unknown"); _this.logDataElement("page", "updated", "success", itemName, targetGuid || _this.guid, details, locale, channel); }, created: function (entity, details, locale, channel, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.name) || (entity === null || entity === void 0 ? void 0 : entity.menuText) || "Page ".concat((entity === null || entity === void 0 ? void 0 : entity.pageID) || "Unknown"); _this.logDataElement("page", "created", "success", itemName, targetGuid || _this.guid, details, locale, channel); }, skipped: function (entity, details, locale, channel, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.name) || (entity === null || entity === void 0 ? void 0 : entity.menuText) || "Page ".concat((entity === null || entity === void 0 ? void 0 : entity.pageID) || "Unknown"); _this.logDataElement("page", "skipped", "skipped", itemName, targetGuid || _this.guid, details, locale, channel); }, error: function (payload, apiError, locale, channel, targetGuid) { var itemName = (payload === null || payload === void 0 ? void 0 : payload.name) || (payload === null || payload === void 0 ? void 0 : payload.menuText) || "Page ".concat((payload === null || payload === void 0 ? void 0 : payload.pageID) || "Unknown"); var errorDetails = (apiError === null || apiError === void 0 ? void 0 : apiError.message) || apiError || "Unknown error"; // we need a better error logger for data elements _this.logDataElement("page", "error", "failed", itemName, targetGuid || _this.guid, errorDetails, locale, channel); }, }; // Gallery logging methods this.gallery = { downloaded: function (entity, details) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.name) || "Gallery ".concat((entity === null || entity === void 0 ? void 0 : entity.id) || "Unknown"); _this.logDataElement("gallery", "downloaded", "success", itemName, _this.guid, details); }, created: function (entity, details, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.name) || "Gallery ".concat((entity === null || entity === void 0 ? void 0 : entity.id) || "Unknown"); _this.logDataElement("gallery", "created", "success", itemName, targetGuid, details); }, updated: function (entity, details, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.name) || "Gallery ".concat((entity === null || entity === void 0 ? void 0 : entity.id) || "Unknown"); _this.logDataElement("gallery", "updated", "success", itemName, targetGuid, details); }, skipped: function (entity, details, targetGuid) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.name) || "Gallery"; _this.logDataElement("gallery", "skipped", "skipped", itemName, targetGuid || _this.guid, details); }, exists: function (entity, details) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.name) || "Gallery"; _this.logDataElement("gallery", "up-to-date", "skipped", itemName, _this.guid, details); }, error: function (gallery, apiError, payload, targetGuid) { var itemName = (gallery === null || gallery === void 0 ? void 0 : gallery.name) || "Gallery ".concat((gallery === null || gallery === void 0 ? void 0 : gallery.id) || "Unknown"); var errorDetails = (apiError === null || apiError === void 0 ? void 0 : apiError.message) || apiError || "Unknown error"; // we need a better error logger for data elements _this.logDataElement("gallery", "failed", "failed", itemName, targetGuid || _this.guid, errorDetails); console.log(gallery.mediaGroupingID, gallery.name); console.log(ansi_colors_1.default.red(JSON.stringify(apiError, null, 2))); console.log(ansi_colors_1.default.red(JSON.stringify(payload, null, 2))); }, }; // Sitemap logging methods this.sitemap = { downloaded: function (entity, details) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.name) || "sitemap.json"; _this.logDataElement("sitemap", "downloaded", "success", itemName, _this.guid, details); }, uploaded: function (entity, details) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.name) || "sitemap.json"; _this.logDataElement("sitemap", "uploaded", "success", itemName, _this.guid, details); }, skipped: function (entity, details) { var itemName = (entity === null || entity === void 0 ? void 0 : entity.name) || "sitemap.json"; _this.logDataElement("sitemap", "skipped", "skipped", itemName, _this.guid, details); }, error: function (payload, apiError) { var itemName = (payload === null || payload === void 0 ? void 0 : payload.name) || "sitemap.json"; var errorDetails = (apiError === null || apiError === void 0 ? void 0 : apiError.message) || apiError || "Unknown error"; // we need a better error logger for data elements // this.logDataElement("failed", "failed", itemName, this.guid, errorDetails); }, }; this.operationType = operationType; this.entityType = entityType; this.guid = guid; this.startTime = new Date(); // Default configuration this.config = { logToConsole: true, logToFile: true, showColors: true, useStructuredFormat: true, }; this.initializeGuidColors(); } /** * Set the GUID for this logger instance (for cases where it's set after construction) */ Logs.prototype.setGuid = function (guid) { this.guid = guid; }; /** * Get the GUID for this logger instance */ Logs.prototype.getGuid = function () { return this.guid; }; /** * Configure logging behavior */ Logs.prototype.configure = function (config) { this.config = __assign(__assign({}, this.config), config); }; /** * Single logging function - handles everything based on configuration */ Logs.prototype.log = function (logLevel, message, entity) { // Check if we should log this level var logEntry = { logLevel: logLevel, message: message, timestamp: new Date().toISOString(), entity: entity, }; // Store the log this.logs.push(logEntry); // Output to console if configured if (this.config.logToConsole) { this.outputToConsole(logEntry); } }; /** * Log a summary of the operation, including counts and proper formatting. * Handles empty results, pluralization, and avoids type errors. */ Logs.prototype.changeDetectionSummary = function (entityType, successful, skipped) { var parts = []; var successFormat = successful > 0 ? "".concat(ansi_colors_1.default.green(successful.toString())) : "".concat(ansi_colors_1.default.gray(successful.toString())); var skippedFormat = skipped > 0 ? "".concat(ansi_colors_1.default.yellow(skipped.toString())) : "".concat(ansi_colors_1.default.gray(skipped.toString())); var circle = this.config.showColors ? ansi_colors_1.default.yellow("○ ") : "○ "; var halfCircle = this.config.showColors ? ansi_colors_1.default.green("◐ ") : "◐ "; var icon = successful > 0 ? halfCircle : circle; // const fullCircle = this.config.showColors ? ansiColors.yellow("") : "◑ "; // Pluralize and always show zero counts for clarity parts.push(successFormat + ansi_colors_1.default.gray(" to download")); parts.push(skippedFormat + ansi_colors_1.default.gray(" unchanged")); var capitalizedEntityType = entityType.charAt(0).toUpperCase() + entityType.slice(1); var message = ansi_colors_1.default.gray("".concat(icon).concat(capitalizedEntityType, " change detection summary:")) + " " + parts.join(" "); this.info(message); }; Logs.prototype.syncOperationsSummary = function (entityType, successful, skipped) { var parts = []; var successFormat = successful > 0 ? "".concat(ansi_colors_1.default.green(successful.toString())) : "".concat(ansi_colors_1.default.gray(successful.toString())); var skippedFormat = skipped > 0 ? "".concat(ansi_colors_1.default.yellow(skipped.toString())) : "".concat(ansi_colors_1.default.gray(skipped.toString())); var circle = this.config.showColors ? ansi_colors_1.default.yellow("○ ") : "○ "; var halfCircle = this.config.showColors ? ansi_colors_1.default.green("◐ ") : "◐ "; var icon = successful > 0 ? halfCircle : circle; var capitalizedEntityType = entityType.charAt(0).toUpperCase() + entityType.slice(1); var message = ansi_colors_1.default.gray("".concat(icon).concat(capitalizedEntityType, " sync operations summary:")) + " " + parts.join(" "); this.info(message); }; /** * Simple info logging method */ Logs.prototype.info = function (message) { var logEntry = { logLevel: "INFO", message: message, timestamp: new Date().toISOString(), }; this.logs.push(logEntry); if (this.config.logToConsole) { this.outputToConsole(logEntry); } }; /** * Log to file only (no console output) */ Logs.prototype.fileOnly = function (message) { var logEntry = { logLevel: "INFO", message: message, timestamp: new Date().toISOString(), }; this.logs.push(logEntry); // Intentionally skip outputToConsole - file only }; /** * Quick convenience methods for common patterns */ Logs.prototype.success = function (message, entity) { this.info(message); }; Logs.prototype.error = function (message, entity) { this.log("ERROR", message); }; Logs.prototype.warning = function (message, entity) { this.log("WARN", message); }; Logs.prototype.debug = function (message, entity) { this.log("DEBUG", message); }; /** * Log a structured data element with consistent formatting */ Logs.prototype.logDataElement = function (entityType, action, status, itemName, guid, details, locale, channel) { // const entityType = this.entityType || ""; var message; var symbol = ""; // Set symbols based on status switch (status) { case "success": symbol = this.config.showColors ? ansi_colors_1.default.green("● ") : "● "; break; case "failed": symbol = this.config.showColors ? ansi_colors_1.default.red("✗ ") : "✗ "; break; case "skipped": symbol = this.config.showColors ? ansi_colors_1.default.yellow("○ ") : "○ "; break; case "conflict": symbol = this.config.showColors ? ansi_colors_1.default.magenta("⚠ ") : "⚠ "; break; case "pending": symbol = this.config.showColors ? ansi_colors_1.default.gray("◐ ") : "◐ "; break; case "in_progress": symbol = this.config.showColors ? ansi_colors_1.default.blue("◑ ") : "◑ "; break; default: symbol = this.config.showColors ? ansi_colors_1.default.blue("ℹ ") : "ℹ "; break; } if (this.config.useStructuredFormat) { var guidDisplay = guid ? status === "success" ? ansi_colors_1.default.green(this.formatGuidWithColor(guid)) : status === "failed" ? ansi_colors_1.default.red("[".concat(guid, "]")) : this.formatGuidWithColor(guid) : ""; var styledItemName = itemName && this.config.showColors ? status === "success" ? ansi_colors_1.default.cyan.underline(itemName) : status === "failed" ? ansi_colors_1.default.red.underline(itemName) : ansi_colors_1.default.cyan.underline(itemName) : itemName; var styledDetails = details && this.config.showColors ? ansi_colors_1.default.gray("".concat(details)) : details; var detailsDisplay = styledDetails ? "".concat(styledDetails) : ""; var actionDisplay = this.config.showColors ? status === "success" ? ansi_colors_1.default.gray(action) : status === "failed" ? ansi_colors_1.default.red(action) : ansi_colors_1.default.gray(action) : action; var localeDisplay = locale && this.config.showColors ? ansi_colors_1.default.gray("[".concat(locale, "]")) : locale ? "[".concat(locale, "]") : ""; var channelDisplay = channel && this.config.showColors ? ansi_colors_1.default.gray("[".concat(channel, "]")) : channel ? "[".concat(channel, "]") : ""; var styledEntityType = entityType && this.config.showColors ? status === "success" ? ansi_colors_1.default.white(entityType) : status === "failed" ? ansi_colors_1.default.red(entityType) : ansi_colors_1.default.white(entityType) : entityType; var entityTypeDisplay = (message = "".concat(symbol).concat(guidDisplay).concat(localeDisplay ? "".concat(localeDisplay) : "").concat(channelDisplay ? "".concat(channelDisplay) : "", " ").concat(styledEntityType, " ").concat(styledItemName, " ").concat(detailsDisplay ? "".concat(detailsDisplay) : "".concat(actionDisplay))); } else { var localeDisplay = locale ? " [".concat(locale, "]") : ""; message = "".concat(status, ": ").concat(entityType).concat(localeDisplay, " ").concat(itemName).concat(details ? " ".concat(details) : "", " ").concat(action ? ",".concat(action) : ""); } this.log("INFO", message); }; /** * Single summary function - takes entity type and counts */ /** * Logs a summary of the operation, including counts and proper formatting. * Handles empty results, pluralization, and avoids type errors. */ Logs.prototype.summary = function (operationType, successful, failed, skipped) { var total = successful + failed + skipped; var parts = []; // Pluralize and always show zero counts for clarity parts.push("".concat(successful, " successful")); parts.push("".concat(failed, " failed")); parts.push("".concat(skipped, " skipped")); // Capitalize operationType for display var opLabel = operationType.charAt(0).toUpperCase() + operationType.slice(1); var message = "".concat(opLabel, " Summary: ").concat(parts.join(", "), " (Total: ").concat(total, ")"); if (this.config.useStructuredFormat && this.config.showColors) { message = ansi_colors_1.default.cyan(message); } // Always use a valid EntityType for the log function, not OperationType // Use "logs" as a generic entity type for summary logs // this.log("INFO", "push", "summary", "success", message, { successful, failed, skipped, total, operationType }); }; /** * Save logs to file and return the file path (don't log it immediately) */ Logs.prototype.saveLogs = function () { var _this = this; var _a, _b; if (!this.config.logToFile || this.logs.length === 0) { this.logs = []; return null; } try { // Create logs directory var logsDir = path.join(process.cwd(), "agility-files", "logs"); if (!fs.existsSync(logsDir)) { fs.mkdirSync(logsDir, { recursive: true }); } // Generate filename based on operation type and GUIDs var timestamp = this.generateTimestamp(); var filename = void 0; // For per-GUID loggers, we need to determine which GUID this logger is for // We can do this by checking which GUID appears most in the logs var state = (0, state_1.getState)(); var guidForFilename_1 = ""; if (this.logs.length > 0) { // Count GUID occurrences in log messages to identify which GUID this logger belongs to var guidCounts_1 = new Map(); var allGuids_1 = __spreadArray(__spreadArray([], (state.sourceGuid || []), true), (state.targetGuid || []), true); this.logs.forEach(function (log) { allGuids_1.forEach(function (guid) { if (log.message.includes("[".concat(guid, "]"))) { guidCounts_1.set(guid, (guidCounts_1.get(guid) || 0) + 1); } }); }); // Find the GUID with the most occurrences (this logger's GUID) var maxCount_1 = 0; guidCounts_1.forEach(function (count, guid) { if (count > maxCount_1) { maxCount_1 = count; guidForFilename_1 = guid; } }); } // Build filename with GUID if (this.operationType === "push" || this.operationType === "sync") { var sourceGuid = ((_a = state.sourceGuid) === null || _a === void 0 ? void 0 : _a[0]) || "unknown"; var targetGuid = ((_b = state.targetGuid) === null || _b === void 0 ? void 0 : _b[0]) || "unknown"; filename = "".concat(sourceGuid, "-").concat(targetGuid, "-").concat(this.operationType, "-").concat(timestamp, ".txt"); } else { // For pull operations, use the specific GUID this logger is for var guidPrefix = guidForFilename_1 ? "".concat(guidForFilename_1, "-") : ""; filename = "".concat(guidPrefix).concat(this.operationType, "-").concat(timestamp, ".txt"); } var filePath = path.join(logsDir, filename); // Format all logs for file output (with ANSI stripping) var logContent = this.logs.map(function (log) { return _this.stripAnsiCodes(_this.formatLogForFile(log)); }).join(""); // Write to file fs.writeFileSync(filePath, logContent); // Clear logs var logCount = this.logs.length; this.clearLogs(); return filePath; } catch (error) { console.error("Error saving logs:", error); this.clearLogs(); return null; } }; /** * Clear logs without saving */ Logs.prototype.clearLogs = function () { this.logs = []; (0, state_1.setState)({ logs: this.logs }); }; /** * Get current log count */ Logs.prototype.getLogCount = function () { return this.logs.length; }; /** * Get logs by level (for debugging) */ // getLogsByLevel(level: LogLevel): LogEntry[] { // return this.logs.filter((log) => log.logLevel === level); // } // Private helper methods // private shouldLog(level: LogLevel): boolean { // const levels = ["DEBUG", "INFO", "WARN", "ERROR"]; // const currentLevelIndex = levels.indexOf(this.config.minLevel); // const logLevelIndex = levels.indexOf(level); // return logLevelIndex >= currentLevelIndex; // } Logs.prototype.outputToConsole = function (log) { var output = log.message; // Only apply color formatting if the message doesn't already contain ANSI codes // This preserves custom styling from logDataElement var hasAnsiCodes = /\x1b\[[0-9;]*m/.test(log.message); if (this.config.showColors && !hasAnsiCodes) { switch (log.logLevel) { case "ERROR": output = ansi_colors_1.default.red(log.message); break; case "WARN": output = ansi_colors_1.default.yellow(log.message); break; case "INFO": output = log.logLevel === "INFO" ? ansi_colors_1.default.green(log.message) : log.message; break; case "DEBUG": output = ansi_colors_1.default.gray(log.message); break; } } console.log(output); }; Logs.prototype.formatLogForFile = function (log) { return "[".concat(this.operationType, "][").concat(log.timestamp, "] [").concat(log.logLevel, "] ").concat(log.message, "\n"); }; Logs.prototype.generateTimestamp = function () { var now = new Date(); var year = now.getFullYear(); var month = String(now.getMonth() + 1).padStart(2, "0"); var day = String(now.getDate()).padStart(2, "0"); var hour = String(now.getHours()).padStart(2, "0"); var minute = String(now.getMinutes()).padStart(2, "0"); var second = String(now.getSeconds()).padStart(2, "0"); return "".concat(year, "-").concat(month, "-").concat(day, "-").concat(hour, "-").concat(minute, "-").concat(second); }; Logs.prototype.stripAnsiCodes = function (text) { // eslint-disable-next-line no-control-regex return text.replace(/\x1b\[[0-9;]*m/g, ""); }; /** * Initialize color mapping for all GUIDs from state */ Logs.prototype.initializeGuidColors = function () { var _this = this; var state = (0, state_1.getState)(); var allGuids = __spreadArray(__spreadArray([], (state.sourceGuid || []), true), (state.targetGuid || []), true); // Assign unique colors to each GUID allGuids.forEach(function (guid, index) { if (guid && !_this.guidColorMap.has(guid)) { var colorIndex = index % _this.availableColors.length; _this.guidColorMap.set(guid, _this.availableColors[colorIndex]); } }); }; /** * Format GUID with its assigned color */ Logs.prototype.formatGuidWithColor = function (guid) { if (!this.config.showColors) { return "[".concat(guid, "]"); } var colorName = this.guidColorMap.get(guid) || "gray"; var colorFunction = ansi_colors_1.default[colorName]; if (colorFunction) { return colorFunction("[".concat(guid, "]")); } return "[".concat(guid, "]"); }; // Legacy methods for compatibility Logs.prototype.initializeLogsInState = function (logs) { (0, state_1.setState)({ logs: logs }); }; Logs.prototype.displayLogs = function () { var _this = this; var formattedLogs = this.logs.map(function (log) { return _this.formatLogForFile(log); }); console.log(ansi_colors_1.default.green(formattedLogs.join(""))); }; Logs.prototype.displayLog = function (log) { var formatted = this.formatLogForFile(log); console.log(ansi_colors_1.default.green(formatted)); }; Logs.prototype.startTimer = function () { this.startTime = new Date(); // this.info(`\nStart time: ${this.startTime.toISOString().toLocaleString()}`); }; Logs.prototype.endTimer = function () { this.endTime = new Date(); // this.info(`\nEnd time: ${this.endTime.toISOString().toLocaleString()}`); var duration = this.endTime.getTime() - this.startTime.getTime(); // this.info(`Duration: ${duration > 60000 ? `${Math.floor(duration/1000/60)}m ${Math.floor(duration/1000)%60}s` : `${Math.floor(duration/1000)}s`}\n`); }; /** * Log operation header with state information */ Logs.prototype.logOperationHeader = function () { var _a, _b, _c, _d; // Get current state information var state = require("./state").getState(); var additionalInfo = { GUID: this.guid || "Not specified", "Operation Type": this.operationType, "Entity Type": this.entityType || "All entities", "Source GUIDs": ((_a = state.sourceGuid) === null || _a === void 0 ? void 0 : _a.join(", ")) || "None", "Target GUIDs": ((_b = state.targetGuid) === null || _b === void 0 ? void 0 : _b.join(", ")) || "None", Locales: this.guid ? ((_d = (_c = state.guidLocaleMap) === null || _c === void 0 ? void 0 : _c.get(this.guid)) === null || _d === void 0 ? void 0 : _d.join(", ")) || "Not specified" : "Multiple", Channel: state.channel || "Not specified", Elements: state.elements || "All", "Reset Mode": state.reset ? "Full reset" : "Incremental", Verbose: state.verbose ? "Enabled" : "Disabled", "Preview Mode": state.isPreview ? "Preview" : "Live", }; var header = (0, shared_1.generateLogHeader)(this.operationType, additionalInfo); this.fileOnly(header); }; /** * Log orchestrator summary with timing, counts, and completion status */ Logs.prototype.orchestratorSummary = function (results, elapsedTime, success, logFilePaths) { var ansiColors = require("ansi-colors"); // Calculate time display var totalElapsedSeconds = Math.floor(elapsedTime / 1000); var minutes = Math.floor(totalElapsedSeconds / 60); var seconds = totalElapsedSeconds % 60; var timeDisplay = minutes > 0 ? "".concat(minutes, "m ").concat(seconds, "s") : "".concat(seconds, "s"); // Calculate success/failure counts var totalSuccessful = 0; var totalFailed = 0; results.forEach(function (res) { var _a; if (((_a = res.failed) === null || _a === void 0 ? void 0 : _a.length) > 0) { totalFailed++; } else { totalSuccessful++; } }); // Log to file using logger summary this.summary(this.operationType, totalSuccessful, totalFailed, 0); // Console output console.log(ansiColors.cyan("\nSummary:")); console.log("Processed ".concat(results.length, " GUID/locale combinations")); console.log("".concat(totalSuccessful, " successful, ").concat(totalFailed, " failed")); console.log("Total time: ".concat(timeDisplay)); // Success/failure message if (success) { console.log(ansiColors.green("\n\u2713 ".concat(this.operationType.charAt(0).toUpperCase() + this.operationType.slice(1), " completed successfully"))); // Display log file paths if provided if (logFilePaths && logFilePaths.length > 0) { console.log(ansiColors.cyan("\nLog Files:")); logFilePaths.forEach(function (path) { console.log("".concat(path)); }); } } else { console.log(ansiColors.red("\n\u2717 ".concat(this.operationType.charAt(0).toUpperCase() + this.operationType.slice(1), " completed with errors"))); // Display log file paths even on errors if (logFilePaths && logFilePaths.length > 0) { console.log(ansiColors.cyan("\nLog Files:")); logFilePaths.forEach(function (path) { console.log(" ".concat(path)); }); } } }; return Logs; }()); exports.Logs = Logs; //# sourceMappingURL=logs.js.map