UNPKG

@agility/cli

Version:

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

247 lines 8.96 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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConsoleManager = void 0; var fileOperations_1 = require("../../../core/fileOperations"); var state_1 = require("../../../core/state"); var ansi_colors_1 = __importDefault(require("ansi-colors")); var ConsoleManager = /** @class */ (function () { function ConsoleManager() { this.state = { mode: 'plain', originalLog: console.log, originalError: console.error, isRedirected: false }; } /** * Setup console mode and redirection */ ConsoleManager.prototype.setupMode = function (mode, fileOps, handlers) { this.state.mode = mode; this.fileOps = fileOps; this.redirectionHandlers = handlers; switch (mode) { case 'headless': this.setupHeadlessMode(); break; case 'verbose': this.setupVerboseMode(); break; // Remove blessed case - no longer supported case 'plain': this.setupPlainMode(); break; } }; /** * Setup headless mode (file logging only, no console output) */ ConsoleManager.prototype.setupHeadlessMode = function () { var _this = this; if (this.state.isRedirected) return; console.log = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var message = _this.formatMessage(args); _this.logToFile(message); }; console.error = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var message = _this.formatMessage(args); _this.logToFile(message, true); }; this.state.isRedirected = true; }; /** * Setup verbose mode (console + file logging) */ ConsoleManager.prototype.setupVerboseMode = function () { var _this = this; if (this.state.isRedirected) return; console.log = function () { var _a; var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var message = _this.formatMessage(args); (_a = _this.state).originalLog.apply(_a, args); // Show on console _this.logToFile(message); // Also log to file }; console.error = function () { var _a; var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var message = _this.formatMessage(args); (_a = _this.state).originalError.apply(_a, args); // Show on console _this.logToFile(message, true); // Also log to file }; this.state.isRedirected = true; }; // Remove setupBlessedMode - no longer supported /** * Setup plain mode (console + file logging, like verbose but less verbose) */ ConsoleManager.prototype.setupPlainMode = function () { var _this = this; if (this.state.isRedirected) return; console.log = function () { var _a; var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var message = _this.formatMessage(args); (_a = _this.state).originalLog.apply(_a, args); // Show on console _this.logToFile(message); // Also log to file }; console.error = function () { var _a; var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var message = _this.formatMessage(args); (_a = _this.state).originalError.apply(_a, args); // Show on console _this.logToFile(message, true); // Also log to file }; this.state.isRedirected = true; }; /** * Format console arguments into a single message string */ ConsoleManager.prototype.formatMessage = function (args) { return args.map(function (arg) { return String(arg); }).join(" "); }; /** * Log message to file using existing fileOperations infrastructure */ ConsoleManager.prototype.logToFile = function (message, isError) { if (isError === void 0) { isError = false; } if (!this.fileOps) return; var timestamp = new Date().toISOString(); var level = isError ? "ERROR" : "INFO"; // fileOperations.appendLogFile handles ANSI stripping automatically this.fileOps.appendLogFile("[".concat(timestamp, "] [").concat(level, "] ").concat(message, "\n")); }; /** * Restore original console methods */ ConsoleManager.prototype.restoreConsole = function () { if (!this.state.isRedirected) return; console.log = this.state.originalLog; console.error = this.state.originalError; this.state.isRedirected = false; }; /** * Check if console is currently redirected */ ConsoleManager.prototype.isRedirected = function () { return this.state.isRedirected; }; /** * Get current console mode */ ConsoleManager.prototype.getMode = function () { return this.state.mode; }; /** * Conditional logging - only log if conditions are met */ ConsoleManager.prototype.conditionalLog = function (message, condition) { if (condition) { console.log(message); } }; /** * Log with specific color formatting (maintains existing ansiColors patterns) */ ConsoleManager.prototype.logSuccess = function (message) { console.log(ansi_colors_1.default.green(message)); }; ConsoleManager.prototype.logError = function (message) { console.error(ansi_colors_1.default.red(message)); }; ConsoleManager.prototype.logWarning = function (message) { console.log(ansi_colors_1.default.yellow(message)); }; ConsoleManager.prototype.logInfo = function (message) { console.log(ansi_colors_1.default.cyan(message)); }; /** * Log step-related messages (consistent with existing pusher patterns) */ ConsoleManager.prototype.logStepStart = function (stepName) { console.log("Starting ".concat(stepName, "...")); }; ConsoleManager.prototype.logStepSuccess = function (stepName, details) { var message = details ? "\u2713 ".concat(stepName, " - ").concat(details) : "\u2713 ".concat(stepName, " completed"); console.log(ansi_colors_1.default.green(message)); }; ConsoleManager.prototype.logStepError = function (stepName, error) { console.error(ansi_colors_1.default.red("\u2717 ".concat(stepName, " failed: ").concat(error))); }; /** * Log separator (consistent with existing patterns) */ ConsoleManager.prototype.logSeparator = function () { console.log("----------------------------------------------------------------------"); }; /** * Create a file operations instance for the current state */ ConsoleManager.createFileOps = function (guid) { var state = (0, state_1.getState)(); var targetGuid = guid || state.sourceGuid; return new fileOperations_1.fileOperations(targetGuid[0], state.locale[0]); }; /** * Finalize log file and return path */ ConsoleManager.prototype.finalizeLogFile = function (operationType) { if (!this.fileOps) return null; return this.fileOps.finalizeLogFile(operationType); }; /** * Update redirection handlers (useful for dynamic handler changes) */ ConsoleManager.prototype.updateRedirectionHandlers = function (handlers) { this.redirectionHandlers = handlers; }; /** * Get console state for debugging */ ConsoleManager.prototype.getConsoleState = function () { return __assign({}, this.state); }; return ConsoleManager; }()); exports.ConsoleManager = ConsoleManager; //# sourceMappingURL=console-manager.js.map