@mks2508/better-logger 0.14.0-alpha.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/dist/chunks/{Logger-Crw1woqR.js → Logger-CTAaDeZi.js} +49 -16
  2. package/dist/chunks/{Logger-Crw1woqR.js.map → Logger-CTAaDeZi.js.map} +1 -1
  3. package/dist/chunks/{Logger-D_p3xnbq.js → Logger-D8pK7XXt.js} +2 -2
  4. package/dist/chunks/{Logger-D_p3xnbq.js.map → Logger-D8pK7XXt.js.map} +1 -1
  5. package/dist/chunks/ScopedLogger-D-7q8uVP.js +2 -0
  6. package/dist/chunks/ScopedLogger-D-7q8uVP.js.map +1 -0
  7. package/dist/chunks/ScopedLogger-hS0qSkZD.js +361 -0
  8. package/dist/chunks/ScopedLogger-hS0qSkZD.js.map +1 -0
  9. package/dist/core.js +280 -307
  10. package/dist/exports.cjs +1 -1
  11. package/dist/exports.js +1 -1
  12. package/dist/index.cjs +1 -1
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.js +226 -159
  15. package/dist/index.js.map +1 -1
  16. package/dist/styling.cjs +1 -1
  17. package/dist/styling.js +2 -2
  18. package/dist/types/Logger.d.ts +11 -7
  19. package/dist/types/Logger.d.ts.map +1 -1
  20. package/dist/types/core.d.ts +122 -216
  21. package/dist/types/core.d.ts.map +1 -1
  22. package/dist/types/index.d.ts +119 -4
  23. package/dist/types/index.d.ts.map +1 -1
  24. package/package.json +2 -1
  25. package/src/Logger.ts +99 -58
  26. package/src/index.ts +32 -25
  27. package/dist/.tsbuildinfo +0 -1
  28. package/dist/Logger.d.ts +0 -708
  29. package/dist/Logger.d.ts.map +0 -1
  30. package/dist/Logger.js +0 -1124
  31. package/dist/ScopedLogger.d.ts +0 -318
  32. package/dist/ScopedLogger.d.ts.map +0 -1
  33. package/dist/ScopedLogger.js +0 -426
  34. package/dist/cli/CommandProcessor.d.ts +0 -103
  35. package/dist/cli/CommandProcessor.d.ts.map +0 -1
  36. package/dist/cli/CommandProcessor.js +0 -184
  37. package/dist/cli/commands/ConfigCommand.d.ts +0 -17
  38. package/dist/cli/commands/ConfigCommand.d.ts.map +0 -1
  39. package/dist/cli/commands/ConfigCommand.js +0 -88
  40. package/dist/cli/commands/ExportCommand.d.ts +0 -51
  41. package/dist/cli/commands/ExportCommand.d.ts.map +0 -1
  42. package/dist/cli/commands/ExportCommand.js +0 -243
  43. package/dist/cli/commands/HistoryCommand.d.ts +0 -50
  44. package/dist/cli/commands/HistoryCommand.d.ts.map +0 -1
  45. package/dist/cli/commands/HistoryCommand.js +0 -96
  46. package/dist/cli/commands/StatusCommand.d.ts +0 -33
  47. package/dist/cli/commands/StatusCommand.d.ts.map +0 -1
  48. package/dist/cli/commands/StatusCommand.js +0 -93
  49. package/dist/cli/commands/ThemeCommand.d.ts +0 -33
  50. package/dist/cli/commands/ThemeCommand.d.ts.map +0 -1
  51. package/dist/cli/commands/ThemeCommand.js +0 -79
  52. package/dist/cli/help.d.ts +0 -15
  53. package/dist/cli/help.d.ts.map +0 -1
  54. package/dist/cli/help.js +0 -118
  55. package/dist/cli/index.d.ts +0 -15
  56. package/dist/cli/index.d.ts.map +0 -1
  57. package/dist/cli/index.js +0 -46
  58. package/dist/constants.d.ts +0 -122
  59. package/dist/constants.d.ts.map +0 -1
  60. package/dist/constants.js +0 -159
  61. package/dist/core.d.ts +0 -134
  62. package/dist/core.d.ts.map +0 -1
  63. package/dist/example.d.ts +0 -18
  64. package/dist/example.d.ts.map +0 -1
  65. package/dist/example.js +0 -154
  66. package/dist/exports-module.d.ts +0 -203
  67. package/dist/exports-module.d.ts.map +0 -1
  68. package/dist/exports-module.js +0 -260
  69. package/dist/handlers/AnalyticsLogHandler.d.ts +0 -11
  70. package/dist/handlers/AnalyticsLogHandler.d.ts.map +0 -1
  71. package/dist/handlers/AnalyticsLogHandler.js +0 -19
  72. package/dist/handlers/ExportLogHandler.d.ts +0 -103
  73. package/dist/handlers/ExportLogHandler.d.ts.map +0 -1
  74. package/dist/handlers/ExportLogHandler.js +0 -516
  75. package/dist/handlers/FileLogHandler.d.ts +0 -36
  76. package/dist/handlers/FileLogHandler.d.ts.map +0 -1
  77. package/dist/handlers/FileLogHandler.js +0 -156
  78. package/dist/handlers/RemoteLogHandler.d.ts +0 -14
  79. package/dist/handlers/RemoteLogHandler.d.ts.map +0 -1
  80. package/dist/handlers/RemoteLogHandler.js +0 -37
  81. package/dist/handlers/index.d.ts +0 -8
  82. package/dist/handlers/index.d.ts.map +0 -1
  83. package/dist/handlers/index.js +0 -7
  84. package/dist/index.d.ts +0 -157
  85. package/dist/index.d.ts.map +0 -1
  86. package/dist/main.d.ts +0 -2
  87. package/dist/main.d.ts.map +0 -1
  88. package/dist/main.js +0 -139
  89. package/dist/styling/LogStyleBuilder.d.ts +0 -149
  90. package/dist/styling/LogStyleBuilder.d.ts.map +0 -1
  91. package/dist/styling/LogStyleBuilder.js +0 -289
  92. package/dist/styling/SemanticStyles.d.ts +0 -181
  93. package/dist/styling/SemanticStyles.d.ts.map +0 -1
  94. package/dist/styling/SemanticStyles.js +0 -339
  95. package/dist/styling/SmartPresets.d.ts +0 -25
  96. package/dist/styling/SmartPresets.d.ts.map +0 -1
  97. package/dist/styling/SmartPresets.js +0 -276
  98. package/dist/styling/StyleBuilder.d.ts +0 -140
  99. package/dist/styling/StyleBuilder.d.ts.map +0 -1
  100. package/dist/styling/StyleBuilder.js +0 -280
  101. package/dist/styling/banners.d.ts +0 -45
  102. package/dist/styling/banners.d.ts.map +0 -1
  103. package/dist/styling/banners.js +0 -155
  104. package/dist/styling/index.d.ts +0 -10
  105. package/dist/styling/index.d.ts.map +0 -1
  106. package/dist/styling/index.js +0 -9
  107. package/dist/styling/themes.d.ts +0 -10
  108. package/dist/styling/themes.d.ts.map +0 -1
  109. package/dist/styling/themes.js +0 -231
  110. package/dist/styling-module.d.ts +0 -185
  111. package/dist/styling-module.d.ts.map +0 -1
  112. package/dist/styling-module.js +0 -199
  113. package/dist/types/core.js +0 -28
  114. package/dist/types/handlers.d.ts +0 -88
  115. package/dist/types/handlers.d.ts.map +0 -1
  116. package/dist/types/handlers.js +0 -4
  117. package/dist/types/index.js +0 -4
  118. package/dist/utils/environment.d.ts +0 -47
  119. package/dist/utils/environment.d.ts.map +0 -1
  120. package/dist/utils/environment.js +0 -85
  121. package/dist/utils/formatting.d.ts +0 -40
  122. package/dist/utils/formatting.d.ts.map +0 -1
  123. package/dist/utils/formatting.js +0 -117
  124. package/dist/utils/index.d.ts +0 -7
  125. package/dist/utils/index.d.ts.map +0 -1
  126. package/dist/utils/index.js +0 -6
  127. package/dist/utils/opentui-detection.d.ts +0 -34
  128. package/dist/utils/opentui-detection.d.ts.map +0 -1
  129. package/dist/utils/opentui-detection.js +0 -116
  130. package/dist/utils/output.d.ts +0 -44
  131. package/dist/utils/output.d.ts.map +0 -1
  132. package/dist/utils/output.js +0 -150
  133. package/dist/utils/stackTrace.d.ts +0 -9
  134. package/dist/utils/stackTrace.d.ts.map +0 -1
  135. package/dist/utils/stackTrace.js +0 -81
  136. package/dist/utils/timestamps.d.ts +0 -20
  137. package/dist/utils/timestamps.d.ts.map +0 -1
  138. package/dist/utils/timestamps.js +0 -71
@@ -1,426 +0,0 @@
1
- /**
2
- * @fileoverview ScopedLogger con badges y logging contextual
3
- * @version 0.3.0
4
- * @since 2024
5
- *
6
- * Proporciona loggers especializados con contexto, badges automáticos
7
- * y características avanzadas para componentes y APIs.
8
- */
9
- import { Logger } from './Logger.js';
10
- /**
11
- * Logger con scope mejorado con badges y API simplificada
12
- *
13
- * @class ScopedLogger
14
- * @extends Logger
15
- * @description Logger contextual que añade prefijos y badges automáticamente
16
- *
17
- * @example
18
- * const dbLogger = logger.scope('Database');
19
- * dbLogger.info('Conectando...'); // [Database] Conectando...
20
- *
21
- * // Con badges personalizados
22
- * dbLogger.badge('SLOW').warn('Query lenta detectada');
23
- * // [SLOW] [Database] Query lenta detectada
24
- *
25
- * @since 0.3.0
26
- */
27
- export class ScopedLogger extends Logger {
28
- parentLogger;
29
- scopeName;
30
- badgeList = [];
31
- contextStack = [];
32
- constructor(parentLogger, scopeName, config) {
33
- // Initialize with parent's config plus any overrides
34
- super({ ...parentLogger.getConfig(), ...config });
35
- this.parentLogger = parentLogger;
36
- this.scopeName = scopeName;
37
- // Inherit parent's handlers
38
- const parentHandlers = parentLogger.getHandlers();
39
- parentHandlers.forEach(handler => this.addHandler(handler));
40
- }
41
- /**
42
- * Añade múltiples badges a este logger con scope
43
- *
44
- * @param {string[]} badges - Array de badges a añadir
45
- * @returns {ScopedLogger} Esta instancia para encadenamiento
46
- *
47
- * @example
48
- * const api = logger.scope('API');
49
- * api.badges(['v2', 'beta', 'cached'])
50
- * .info('Respuesta desde caché');
51
- * // [v2] [beta] [cached] [API] Respuesta desde caché
52
- *
53
- * @since 0.3.0
54
- */
55
- badges(badges) {
56
- this.badgeList = [...badges];
57
- return this;
58
- }
59
- /**
60
- * Añade un badge individual
61
- *
62
- * @param {string} badge - Badge a añadir
63
- * @returns {ScopedLogger} Esta instancia para encadenamiento
64
- *
65
- * @example
66
- * dbLogger.badge('SLOW').warn('Query tardó 3s');
67
- * // [SLOW] [Database] Query tardó 3s
68
- *
69
- * @since 0.3.0
70
- */
71
- badge(badge) {
72
- if (!this.badgeList.includes(badge)) {
73
- this.badgeList.push(badge);
74
- }
75
- return this;
76
- }
77
- /**
78
- * Elimina todos los badges
79
- *
80
- * @returns {ScopedLogger} Esta instancia para encadenamiento
81
- *
82
- * @example
83
- * api.clearBadges().info('Sin badges');
84
- * // [API] Sin badges
85
- *
86
- * @since 0.3.0
87
- */
88
- clearBadges() {
89
- this.badgeList = [];
90
- return this;
91
- }
92
- /**
93
- * Establece un preset de estilo para este logger con scope
94
- *
95
- * @param {string} presetName - Nombre del preset a aplicar
96
- * @returns {ScopedLogger} Esta instancia para encadenamiento
97
- *
98
- * @example
99
- * const errorLogger = logger.scope('ErrorHandler')
100
- * .style('cyberpunk');
101
- *
102
- * @since 0.3.0
103
- */
104
- style(presetName) {
105
- this.setTheme(presetName); // Will be updated when we implement presets
106
- return this;
107
- }
108
- /**
109
- * Crea un contexto temporal que se limpia automáticamente
110
- *
111
- * @param {string} contextName - Nombre del contexto
112
- * @returns {ContextLogger} Logger con contexto temporal
113
- *
114
- * @example
115
- * const db = logger.scope('Database');
116
- *
117
- * // Contexto temporal para una operación
118
- * db.context('Migration').run(() => {
119
- * db.info('Iniciando migración');
120
- * db.success('Tablas creadas');
121
- * });
122
- * // Contexto automáticamente limpiado
123
- *
124
- * @since 0.3.0
125
- */
126
- context(contextName) {
127
- return new ContextLogger(this, contextName);
128
- }
129
- /**
130
- * Sobrescribe el logging principal para incluir badges
131
- * @protected
132
- * @param {LogLevel} level - Nivel del log
133
- * @param {...any} args - Argumentos del log
134
- */
135
- log(level, ...args) {
136
- // Build the enhanced message with badges
137
- const badges = this.getBadgeString();
138
- const scopePrefix = this.getScopePrefix();
139
- let enhancedMessage = '';
140
- if (badges)
141
- enhancedMessage += badges + ' ';
142
- if (scopePrefix)
143
- enhancedMessage += `[${scopePrefix}] `;
144
- if (args.length > 0) {
145
- enhancedMessage += String(args[0]);
146
- // Replace the first argument with our enhanced message
147
- args[0] = enhancedMessage;
148
- }
149
- // Call parent's log method
150
- super.log(level, ...args);
151
- }
152
- /**
153
- * Obtiene la cadena de badges formateada
154
- * @private
155
- * @returns {string} Badges formateados como [BADGE1][BADGE2]
156
- */
157
- getBadgeString() {
158
- if (this.badgeList.length === 0)
159
- return '';
160
- return this.badgeList.map(badge => `[${badge}]`).join('');
161
- }
162
- /**
163
- * Obtiene el prefijo del scope (incluye stack de contexto)
164
- * @private
165
- * @returns {string} Prefijo completo con contextos
166
- */
167
- getScopePrefix() {
168
- const parts = [this.scopeName, ...this.contextStack].filter(Boolean);
169
- return parts.join(':');
170
- }
171
- /**
172
- * Método interno para añadir contexto
173
- * @internal
174
- */
175
- _pushContext(context) {
176
- this.contextStack.push(context);
177
- }
178
- /**
179
- * Método interno para eliminar contexto
180
- * @internal
181
- */
182
- _popContext() {
183
- this.contextStack.pop();
184
- }
185
- }
186
- /**
187
- * Logger específico para APIs con badges comunes de API
188
- *
189
- * @class APILogger
190
- * @extends ScopedLogger
191
- * @description Logger especializado para endpoints y servicios API
192
- *
193
- * @example
194
- * const api = logger.api('REST');
195
- * api.info('GET /users');
196
- * // [API] [REST] GET /users
197
- *
198
- * api.slow('Query lenta', 3500);
199
- * // [API] [SLOW] [REST] Query lenta (3500ms)
200
- *
201
- * @since 0.3.0
202
- */
203
- export class APILogger extends ScopedLogger {
204
- constructor(parentLogger, apiName, config) {
205
- super(parentLogger, `API:${apiName}`, config);
206
- this.badge('API');
207
- }
208
- /**
209
- * Registra operaciones lentas
210
- *
211
- * @param {string} message - Mensaje sobre la operación lenta
212
- * @param {number} duration - Duración en milisegundos (opcional)
213
- *
214
- * @example
215
- * api.slow('Query compleja', 5000);
216
- * api.slow('Procesamiento pesado');
217
- *
218
- * @since 0.3.0
219
- */
220
- slow(message, duration) {
221
- this.badge('SLOW');
222
- const msg = duration ? `${message} (${duration}ms)` : message;
223
- this.warn(msg);
224
- }
225
- /**
226
- * Registra límites de tasa alcanzados
227
- *
228
- * @param {string} message - Mensaje sobre el límite
229
- *
230
- * @example
231
- * api.rateLimit('Límite excedido: 100 req/min');
232
- *
233
- * @since 0.3.0
234
- */
235
- rateLimit(message) {
236
- this.badge('RATE_LIMIT');
237
- this.warn(message);
238
- }
239
- /**
240
- * Registra problemas de autenticación
241
- *
242
- * @param {string} message - Mensaje de autenticación
243
- *
244
- * @example
245
- * api.auth('Token inválido o expirado');
246
- * api.auth('Credenciales incorrectas');
247
- *
248
- * @since 0.3.0
249
- */
250
- auth(message) {
251
- this.badge('AUTH');
252
- this.error(message);
253
- }
254
- /**
255
- * Registra advertencias de deprecación
256
- *
257
- * @param {string} message - Mensaje de deprecación
258
- *
259
- * @example
260
- * api.deprecated('Este endpoint será eliminado en v2.0');
261
- * api.deprecated('Usar /v2/users en lugar de /users');
262
- *
263
- * @since 0.3.0
264
- */
265
- deprecated(message) {
266
- this.badge('DEPRECATED');
267
- this.warn(message);
268
- }
269
- }
270
- /**
271
- * Logger específico para componentes de UI
272
- *
273
- * @class ComponentLogger
274
- * @extends ScopedLogger
275
- * @description Logger especializado para componentes con eventos de ciclo de vida
276
- *
277
- * @example
278
- * const authForm = logger.component('AuthForm');
279
- * authForm.lifecycle('mounted');
280
- * authForm.stateChange('idle', 'loading');
281
- *
282
- * @since 0.3.0
283
- */
284
- export class ComponentLogger extends ScopedLogger {
285
- constructor(parentLogger, componentName, config) {
286
- super(parentLogger, componentName, config);
287
- this.badge('COMPONENT');
288
- }
289
- /**
290
- * Registra eventos del ciclo de vida del componente
291
- *
292
- * @param {string} event - Nombre del evento (mounted, unmounted, updated, etc)
293
- * @param {string} message - Mensaje adicional (opcional)
294
- *
295
- * @example
296
- * component.lifecycle('mounted', 'Componente listo');
297
- * component.lifecycle('beforeDestroy');
298
- *
299
- * @since 0.3.0
300
- */
301
- lifecycle(event, message) {
302
- this.badge('LIFECYCLE');
303
- const msg = message ? `${event}: ${message}` : event;
304
- this.info(msg);
305
- }
306
- /**
307
- * Registra cambios de estado
308
- *
309
- * @param {string} from - Estado anterior
310
- * @param {string} to - Estado nuevo
311
- * @param {any} data - Datos adicionales (opcional)
312
- *
313
- * @example
314
- * component.stateChange('idle', 'loading');
315
- * component.stateChange('loading', 'error', { code: 404 });
316
- *
317
- * @since 0.3.0
318
- */
319
- stateChange(from, to, data) {
320
- this.badge('STATE');
321
- const msg = `${from} → ${to}`;
322
- if (data) {
323
- this.info(msg, data);
324
- }
325
- else {
326
- this.info(msg);
327
- }
328
- }
329
- /**
330
- * Registra cambios en las propiedades
331
- *
332
- * @param {Record<string, any>} changes - Objeto con los cambios
333
- *
334
- * @example
335
- * component.propsChange({
336
- * user: newUser,
337
- * isActive: true
338
- * });
339
- *
340
- * @since 0.3.0
341
- */
342
- propsChange(changes) {
343
- this.badge('PROPS');
344
- this.debug('Props changed:', changes);
345
- }
346
- }
347
- /**
348
- * Logger de contexto temporal que se limpia automáticamente
349
- *
350
- * @class ContextLogger
351
- * @description Proporciona un contexto temporal para operaciones agrupadas
352
- *
353
- * @example
354
- * const db = logger.scope('Database');
355
- *
356
- * // El contexto se limpia automáticamente al finalizar
357
- * db.context('Transaction').run(() => {
358
- * db.info('Iniciando transacción');
359
- * db.success('Transacción completada');
360
- * });
361
- *
362
- * @since 0.3.0
363
- */
364
- export class ContextLogger {
365
- parentLogger;
366
- contextName;
367
- constructor(parentLogger, contextName) {
368
- this.parentLogger = parentLogger;
369
- this.contextName = contextName;
370
- }
371
- /**
372
- * Ejecuta una función con este contexto activo
373
- *
374
- * @template T - Tipo de retorno de la función
375
- * @param {Function} fn - Función a ejecutar
376
- * @returns {T} Resultado de la función
377
- *
378
- * @example
379
- * const result = logger.context('Process').run(() => {
380
- * logger.info('Procesando...');
381
- * return processData();
382
- * });
383
- *
384
- * @since 0.3.0
385
- */
386
- run(fn) {
387
- this.parentLogger._pushContext(this.contextName);
388
- try {
389
- return fn();
390
- }
391
- finally {
392
- this.parentLogger._popContext();
393
- }
394
- }
395
- /**
396
- * Run an async function with this context active
397
- */
398
- async runAsync(fn) {
399
- this.parentLogger._pushContext(this.contextName);
400
- try {
401
- return await fn();
402
- }
403
- finally {
404
- this.parentLogger._popContext();
405
- }
406
- }
407
- /**
408
- * Start the context (manual mode)
409
- */
410
- start() {
411
- this.parentLogger._pushContext(this.contextName);
412
- }
413
- /**
414
- * End the context (manual mode)
415
- */
416
- end() {
417
- this.parentLogger._popContext();
418
- }
419
- // Delegate logging methods to parent with context
420
- debug(...args) { this.parentLogger.debug(...args); }
421
- info(...args) { this.parentLogger.info(...args); }
422
- warn(...args) { this.parentLogger.warn(...args); }
423
- error(...args) { this.parentLogger.error(...args); }
424
- success(...args) { this.parentLogger.success(...args); }
425
- critical(...args) { this.parentLogger.critical(...args); }
426
- }
@@ -1,103 +0,0 @@
1
- /**
2
- * @fileoverview CLI Command processor for Advanced Logger
3
- */
4
- import type { Logger } from '../Logger.js';
5
- /**
6
- * Base interface for CLI commands
7
- */
8
- export interface ICommand {
9
- name: string;
10
- description: string;
11
- usage: string;
12
- category?: string;
13
- aliases?: string[];
14
- execute(args: string, logger: Logger): void | Promise<void>;
15
- }
16
- /**
17
- * Plugin interface for extending CLI functionality
18
- */
19
- export interface ICLIPlugin {
20
- name: string;
21
- version: string;
22
- description: string;
23
- commands: ICommand[];
24
- initialize?(processor: CommandProcessor, logger: Logger): void;
25
- cleanup?(): void;
26
- }
27
- /**
28
- * Command history entry
29
- */
30
- interface HistoryEntry {
31
- command: string;
32
- timestamp: Date;
33
- success: boolean;
34
- }
35
- /**
36
- * CLI command processor
37
- */
38
- export declare class CommandProcessor {
39
- private commands;
40
- private aliases;
41
- private plugins;
42
- private history;
43
- private maxHistorySize;
44
- private isInteractiveMode;
45
- /**
46
- * Register a command
47
- */
48
- registerCommand(command: ICommand): void;
49
- /**
50
- * Register a plugin
51
- */
52
- registerPlugin(plugin: ICLIPlugin, logger?: Logger): void;
53
- /**
54
- * Unregister a plugin
55
- */
56
- unregisterPlugin(pluginName: string): void;
57
- /**
58
- * Get all registered commands
59
- */
60
- getCommands(): ICommand[];
61
- /**
62
- * Get a specific command
63
- */
64
- getCommand(name: string): ICommand | undefined;
65
- /**
66
- * Get command history
67
- */
68
- getHistory(): HistoryEntry[];
69
- /**
70
- * Clear command history
71
- */
72
- clearHistory(): void;
73
- /**
74
- * Get registered plugins
75
- */
76
- getPlugins(): ICLIPlugin[];
77
- /**
78
- * Enter interactive mode
79
- */
80
- enterInteractiveMode(logger: Logger): void;
81
- /**
82
- * Exit interactive mode
83
- */
84
- exitInteractiveMode(): void;
85
- /**
86
- * Setup browser interactive mode
87
- */
88
- private setupBrowserInteractiveMode;
89
- /**
90
- * Process a CLI command
91
- */
92
- processCommand(commandString: string, logger: Logger): Promise<void>;
93
- /**
94
- * Add command to history
95
- */
96
- private addToHistory;
97
- /**
98
- * Get command suggestions for partial matches
99
- */
100
- getSuggestions(partial: string): string[];
101
- }
102
- export {};
103
- //# sourceMappingURL=CommandProcessor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CommandProcessor.d.ts","sourceRoot":"","sources":["../../src/cli/CommandProcessor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/D;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACrB,UAAU,CAAC,CAAC,SAAS,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/D,OAAO,CAAC,IAAI,IAAI,CAAC;CACpB;AAED;;GAEG;AACH,UAAU,YAAY;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,QAAQ,CAAoC;IACpD,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,OAAO,CAAsC;IACrD,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,cAAc,CAAe;IACrC,OAAO,CAAC,iBAAiB,CAAkB;IAE3C;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI;IAWxC;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAkBzD;;OAEG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAsB1C;;OAEG;IACH,WAAW,IAAI,QAAQ,EAAE;IAIzB;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAc9C;;OAEG;IACH,UAAU,IAAI,YAAY,EAAE;IAI5B;;OAEG;IACH,YAAY,IAAI,IAAI;IAIpB;;OAEG;IACH,UAAU,IAAI,UAAU,EAAE;IAI1B;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAU1C;;OAEG;IACH,mBAAmB,IAAI,IAAI;IAI3B;;OAEG;IACH,OAAO,CAAC,2BAA2B;IASnC;;OAEG;IACG,cAAc,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkC1E;;OAEG;IACH,OAAO,CAAC,YAAY;IAapB;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;CAI5C"}
@@ -1,184 +0,0 @@
1
- /**
2
- * @fileoverview CLI Command processor for Advanced Logger
3
- */
4
- /**
5
- * CLI command processor
6
- */
7
- export class CommandProcessor {
8
- commands = new Map();
9
- aliases = new Map();
10
- plugins = new Map();
11
- history = [];
12
- maxHistorySize = 100;
13
- isInteractiveMode = false;
14
- /**
15
- * Register a command
16
- */
17
- registerCommand(command) {
18
- this.commands.set(command.name, command);
19
- // Register aliases
20
- if (command.aliases) {
21
- for (const alias of command.aliases) {
22
- this.aliases.set(alias, command.name);
23
- }
24
- }
25
- }
26
- /**
27
- * Register a plugin
28
- */
29
- registerPlugin(plugin, logger) {
30
- if (this.plugins.has(plugin.name)) {
31
- throw new Error(`Plugin ${plugin.name} is already registered`);
32
- }
33
- this.plugins.set(plugin.name, plugin);
34
- // Register plugin commands
35
- for (const command of plugin.commands) {
36
- this.registerCommand(command);
37
- }
38
- // Initialize plugin
39
- if (plugin.initialize && logger) {
40
- plugin.initialize(this, logger);
41
- }
42
- }
43
- /**
44
- * Unregister a plugin
45
- */
46
- unregisterPlugin(pluginName) {
47
- const plugin = this.plugins.get(pluginName);
48
- if (!plugin)
49
- return;
50
- // Remove plugin commands
51
- for (const command of plugin.commands) {
52
- this.commands.delete(command.name);
53
- if (command.aliases) {
54
- for (const alias of command.aliases) {
55
- this.aliases.delete(alias);
56
- }
57
- }
58
- }
59
- // Cleanup plugin
60
- if (plugin.cleanup) {
61
- plugin.cleanup();
62
- }
63
- this.plugins.delete(pluginName);
64
- }
65
- /**
66
- * Get all registered commands
67
- */
68
- getCommands() {
69
- return Array.from(this.commands.values());
70
- }
71
- /**
72
- * Get a specific command
73
- */
74
- getCommand(name) {
75
- // Check direct command name
76
- let command = this.commands.get(name);
77
- if (command)
78
- return command;
79
- // Check aliases
80
- const aliasTarget = this.aliases.get(name);
81
- if (aliasTarget) {
82
- return this.commands.get(aliasTarget);
83
- }
84
- return undefined;
85
- }
86
- /**
87
- * Get command history
88
- */
89
- getHistory() {
90
- return [...this.history];
91
- }
92
- /**
93
- * Clear command history
94
- */
95
- clearHistory() {
96
- this.history = [];
97
- }
98
- /**
99
- * Get registered plugins
100
- */
101
- getPlugins() {
102
- return Array.from(this.plugins.values());
103
- }
104
- /**
105
- * Enter interactive mode
106
- */
107
- enterInteractiveMode(logger) {
108
- this.isInteractiveMode = true;
109
- logger.info('🔧 Interactive CLI mode activated. Type /exit to quit, /help for commands.');
110
- // Set up browser console listener for interactive commands
111
- if (typeof window !== 'undefined') {
112
- this.setupBrowserInteractiveMode(logger);
113
- }
114
- }
115
- /**
116
- * Exit interactive mode
117
- */
118
- exitInteractiveMode() {
119
- this.isInteractiveMode = false;
120
- }
121
- /**
122
- * Setup browser interactive mode
123
- */
124
- setupBrowserInteractiveMode(logger) {
125
- // Add global CLI function for browser usage
126
- window.cli = (commandString) => {
127
- return this.processCommand(`/${commandString}`, logger);
128
- };
129
- logger.info('💡 Use cli("command") to execute CLI commands in browser console.');
130
- }
131
- /**
132
- * Process a CLI command
133
- */
134
- async processCommand(commandString, logger) {
135
- if (!commandString.startsWith('/')) {
136
- logger.error('Invalid command. Commands must start with /');
137
- this.addToHistory(commandString, false);
138
- return;
139
- }
140
- const parts = commandString.slice(1).split(' ');
141
- const commandName = parts[0] || '';
142
- const args = parts.slice(1).join(' ');
143
- const command = this.getCommand(commandName);
144
- if (!command) {
145
- logger.error(`Unknown command: ${commandName}. Type /help for available commands.`);
146
- // Suggest similar commands
147
- const suggestions = this.getSuggestions(commandName);
148
- if (suggestions.length > 0) {
149
- logger.info(`📋 Did you mean: ${suggestions.slice(0, 3).join(', ')}?`);
150
- }
151
- this.addToHistory(commandString, false);
152
- return;
153
- }
154
- try {
155
- await command.execute(args || '', logger);
156
- this.addToHistory(commandString, true);
157
- }
158
- catch (error) {
159
- logger.error(`Command '${commandName}' failed:`, error);
160
- this.addToHistory(commandString, false);
161
- }
162
- }
163
- /**
164
- * Add command to history
165
- */
166
- addToHistory(command, success) {
167
- this.history.unshift({
168
- command,
169
- timestamp: new Date(),
170
- success
171
- });
172
- // Limit history size
173
- if (this.history.length > this.maxHistorySize) {
174
- this.history = this.history.slice(0, this.maxHistorySize);
175
- }
176
- }
177
- /**
178
- * Get command suggestions for partial matches
179
- */
180
- getSuggestions(partial) {
181
- const commandNames = Array.from(this.commands.keys());
182
- return commandNames.filter(name => name.startsWith(partial));
183
- }
184
- }