@mks2508/better-logger 5.0.0 → 5.0.2
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.
- package/dist/chunks/{Logger-Cbi1f10o.js → Logger-CKqzXDh3.js} +2 -2
- package/dist/chunks/{Logger-Cbi1f10o.js.map → Logger-CKqzXDh3.js.map} +1 -1
- package/dist/chunks/{Logger-BZ7B7OXE.js → Logger-D_vuKP4l.js} +2 -2
- package/dist/chunks/{Logger-BZ7B7OXE.js.map → Logger-D_vuKP4l.js.map} +1 -1
- package/dist/chunks/cli-module-B-njrTWb.js +2 -0
- package/dist/chunks/cli-module-B-njrTWb.js.map +1 -0
- package/dist/chunks/{cli-module-ClIJmaT8.js → cli-module-Cx7qotPY.js} +16 -9
- package/dist/chunks/cli-module-Cx7qotPY.js.map +1 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/exports.cjs +1 -1
- package/dist/exports.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/styling.cjs +1 -1
- package/dist/styling.js +2 -2
- package/dist/terminal/formatter.d.ts.map +1 -1
- package/package.json +5 -1
- package/.claude/settings.local.json +0 -48
- package/.github/workflows/ci-quality.yml +0 -357
- package/.github/workflows/docs-demo.yml +0 -119
- package/.github/workflows/releases-core.yml +0 -512
- package/.github/workflows/releases-full.yml +0 -582
- package/.github/workflows-backup/ci.yml +0 -221
- package/.github/workflows-backup/nightly.yml +0 -196
- package/.github/workflows-backup/release-optimized.yml +0 -373
- package/.github/workflows-backup/release.yml +0 -269
- package/.release-notes-0.2.0.md +0 -129
- package/.yamllint +0 -28
- package/CHANGELOG.json +0 -1076
- package/CHANGELOG.md +0 -209
- package/CLAUDE.md +0 -217
- package/bun.lock +0 -333
- package/demo.html +0 -847
- package/dist/chunks/cli-module-CadqgZ1Z.js +0 -2
- package/dist/chunks/cli-module-CadqgZ1Z.js.map +0 -1
- package/dist/chunks/cli-module-ClIJmaT8.js.map +0 -1
- package/docs/API.md +0 -918
- package/docs/CORE.md +0 -264
- package/docs/DEVELOPMENT.md +0 -731
- package/docs/EXPORTS.md +0 -467
- package/docs/PACKAGES.md +0 -244
- package/docs/STYLING.md +0 -405
- package/docs/_config.yml +0 -36
- package/docs/index.md +0 -179
- package/examples/README.md +0 -208
- package/examples/basic-logging.js +0 -75
- package/examples/data-export.js +0 -234
- package/examples/package.json +0 -16
- package/examples/performance-timing.js +0 -170
- package/examples/simplified-api.js +0 -124
- package/examples/styling-themes.js +0 -207
- package/index.html +0 -358
- package/packages/core/package.json +0 -57
- package/packages/exports/package.json +0 -41
- package/packages/nodejs-opentui/README.md +0 -232
- package/packages/nodejs-opentui/package.json +0 -72
- package/packages/nodejs-opentui/src/LogRenderer.ts +0 -171
- package/packages/nodejs-opentui/src/OpenTUILogHandler.ts +0 -178
- package/packages/nodejs-opentui/src/components/LogBadge.tsx +0 -131
- package/packages/nodejs-opentui/src/index.ts +0 -133
- package/packages/nodejs-opentui/src/types.ts +0 -158
- package/packages/nodejs-opentui/tsconfig.json +0 -20
- package/packages/styling/package.json +0 -41
- package/playground/demo-all.ts +0 -95
- package/playground/demo-box.ts +0 -85
- package/playground/demo-levels.ts +0 -56
- package/playground/demo-real-world.ts +0 -98
- package/playground/demo-spinner.ts +0 -77
- package/playground/demo-steps.ts +0 -72
- package/playground/demo-table.ts +0 -83
- package/project-utils/README.md +0 -172
- package/project-utils/auto-release-gemini.ts +0 -1193
- package/project-utils/auto-release-ui.ts +0 -1329
- package/project-utils/commit-generator.ts +0 -1385
- package/project-utils/commit-ui.ts +0 -264
- package/project-utils/git-utils.ts +0 -199
- package/project-utils/github-release-manager.ts +0 -466
- package/project-utils/project-config.ts +0 -260
- package/project-utils/prompt-templates.js +0 -345
- package/project-utils/prompt-templates.ts +0 -422
- package/project-utils/version-manager.ts +0 -1078
- package/public/vite.svg +0 -1
- package/src/Logger.ts +0 -1858
- package/src/ScopedLogger.ts +0 -256
- package/src/cli/CommandProcessor.ts +0 -248
- package/src/cli/commands/ConfigCommand.ts +0 -93
- package/src/cli/commands/ExportCommand.ts +0 -276
- package/src/cli/commands/HistoryCommand.ts +0 -117
- package/src/cli/commands/StatusCommand.ts +0 -112
- package/src/cli/commands/ThemeCommand.ts +0 -88
- package/src/cli/help.ts +0 -127
- package/src/cli/index.ts +0 -71
- package/src/cli-module.ts +0 -21
- package/src/cli-primitives/box.ts +0 -86
- package/src/cli-primitives/cli-table.ts +0 -62
- package/src/cli-primitives/divider.ts +0 -17
- package/src/cli-primitives/header.ts +0 -18
- package/src/cli-primitives/index.ts +0 -13
- package/src/cli-primitives/server-fallback.ts +0 -54
- package/src/cli-primitives/spinner.ts +0 -133
- package/src/cli-primitives/step.ts +0 -22
- package/src/constants.ts +0 -313
- package/src/core.ts +0 -397
- package/src/example.ts +0 -210
- package/src/exports-module.ts +0 -311
- package/src/handlers/AnalyticsLogHandler.ts +0 -22
- package/src/handlers/ExportLogHandler.ts +0 -610
- package/src/handlers/FileLogHandler.ts +0 -169
- package/src/handlers/RemoteLogHandler.ts +0 -42
- package/src/handlers/index.ts +0 -8
- package/src/hooks/HookManager.ts +0 -177
- package/src/hooks/index.ts +0 -1
- package/src/index.ts +0 -395
- package/src/main.ts +0 -196
- package/src/serializers/SerializerRegistry.ts +0 -173
- package/src/serializers/index.ts +0 -1
- package/src/style.css +0 -96
- package/src/styling/LogStyleBuilder.ts +0 -355
- package/src/styling/SemanticStyles.ts +0 -380
- package/src/styling/SmartPresets.ts +0 -288
- package/src/styling/StyleBuilder.ts +0 -319
- package/src/styling/StyleCache.ts +0 -131
- package/src/styling/banners.ts +0 -168
- package/src/styling/index.ts +0 -27
- package/src/styling/themes.ts +0 -235
- package/src/styling-module.ts +0 -244
- package/src/terminal/color-converter.ts +0 -315
- package/src/terminal/formatter.ts +0 -236
- package/src/terminal/terminal-renderer.ts +0 -342
- package/src/transports/ConsoleTransport.ts +0 -28
- package/src/transports/FileTransport.ts +0 -53
- package/src/transports/HttpTransport.ts +0 -56
- package/src/transports/TransportManager.ts +0 -130
- package/src/transports/index.ts +0 -4
- package/src/types/core.ts +0 -417
- package/src/types/handlers.ts +0 -95
- package/src/types/hooks.ts +0 -45
- package/src/types/index.ts +0 -83
- package/src/types/serializers.ts +0 -30
- package/src/types/transports.ts +0 -52
- package/src/typescript.svg +0 -1
- package/src/utils/adapter.ts +0 -291
- package/src/utils/ansi-colors.ts +0 -333
- package/src/utils/environment-detector.ts +0 -170
- package/src/utils/environment.ts +0 -94
- package/src/utils/formatting.ts +0 -332
- package/src/utils/index.ts +0 -33
- package/src/utils/opentui-detection.ts +0 -138
- package/src/utils/output.ts +0 -227
- package/src/utils/stackTrace.ts +0 -144
- package/src/utils/timestamps.ts +0 -80
- package/src/vite-env.d.ts +0 -1
- package/src/writers/BufferWriter.ts +0 -157
- package/src/writers/index.ts +0 -6
- package/test-core-browser.html +0 -237
- package/test-core-node.js +0 -63
- package/tests/test-conflict-resolution.ts +0 -391
- package/tests/validate-workflows.sh +0 -131
- package/tests/yaml-autofix.sh +0 -146
- package/tsconfig.json +0 -50
- package/vite.config.ts +0 -256
package/src/ScopedLogger.ts
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { Logger } from './Logger.js';
|
|
2
|
-
import type { TimerEntry, Bindings, ISpinnerHandle, IBoxOptions, ITableOptions, CLILogLevel } from './types/index.js';
|
|
3
|
-
|
|
4
|
-
export class ScopedLogger {
|
|
5
|
-
private readonly parent: Logger;
|
|
6
|
-
private readonly scopeName: string;
|
|
7
|
-
private badgeList: string[] = [];
|
|
8
|
-
private contextStack: string[] = [];
|
|
9
|
-
private _timers?: Map<string, TimerEntry>;
|
|
10
|
-
|
|
11
|
-
constructor(parent: Logger, scopeName: string) {
|
|
12
|
-
this.parent = parent;
|
|
13
|
-
this.scopeName = scopeName;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
private get timers(): Map<string, TimerEntry> {
|
|
17
|
-
if (!this._timers) this._timers = new Map();
|
|
18
|
-
return this._timers;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
private getBindings(): Bindings {
|
|
22
|
-
return {
|
|
23
|
-
scope: this.getScopePrefix(),
|
|
24
|
-
badges: this.badgeList.length > 0 ? [...this.badgeList] : undefined,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
private getScopePrefix(): string {
|
|
29
|
-
if (this.contextStack.length === 0) return this.scopeName;
|
|
30
|
-
return [this.scopeName, ...this.contextStack].join(':');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
badges(badges: string[]): this {
|
|
34
|
-
this.badgeList = [...badges];
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
badge(badge: string): this {
|
|
39
|
-
if (!this.badgeList.includes(badge)) {
|
|
40
|
-
this.badgeList.push(badge);
|
|
41
|
-
}
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
clearBadges(): this {
|
|
46
|
-
this.badgeList = [];
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
style(presetName: string): this {
|
|
51
|
-
this.parent.setTheme(presetName as any);
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
context(contextName: string): ContextLogger {
|
|
56
|
-
return new ContextLogger(this, contextName);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
time(label: string): void {
|
|
60
|
-
this.timers.set(label, {
|
|
61
|
-
label: `${this.scopeName}:${label}`,
|
|
62
|
-
startTime: performance.now(),
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
timeEnd(label: string): number | undefined {
|
|
67
|
-
const timer = this.timers.get(label);
|
|
68
|
-
if (!timer) {
|
|
69
|
-
this.warn(`Timer '${label}' not found`);
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
const elapsed = performance.now() - timer.startTime;
|
|
73
|
-
this.timers.delete(label);
|
|
74
|
-
this.success(`Timer: ${label} - ${elapsed.toFixed(2)}ms`);
|
|
75
|
-
return elapsed;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
debug(...args: any[]): void {
|
|
79
|
-
this.parent.logWithBindings(this.getBindings(), 'debug', ...args);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
info(...args: any[]): void {
|
|
83
|
-
this.parent.logWithBindings(this.getBindings(), 'info', ...args);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
warn(...args: any[]): void {
|
|
87
|
-
this.parent.logWithBindings(this.getBindings(), 'warn', ...args);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
error(...args: any[]): void {
|
|
91
|
-
this.parent.logWithBindings(this.getBindings(), 'error', ...args);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
success(...args: any[]): void {
|
|
95
|
-
const bindings = this.getBindings();
|
|
96
|
-
this.parent.logWithBindings(bindings, 'info', ...args);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
critical(...args: any[]): void {
|
|
100
|
-
this.parent.logWithBindings(this.getBindings(), 'critical', ...args);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
trace(...args: any[]): void {
|
|
104
|
-
this.parent.logWithBindings(this.getBindings(), 'debug', ...args);
|
|
105
|
-
console.trace(`[${this.scopeName}]`);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// ===== CLI PRIMITIVES (v5.0 delegation) =====
|
|
109
|
-
|
|
110
|
-
/** @see Logger.step */
|
|
111
|
-
step(current: number, total: number, message: string): void {
|
|
112
|
-
this.parent.step(current, total, message);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** @see Logger.header */
|
|
116
|
-
header(title: string, subtitle?: string): void {
|
|
117
|
-
this.parent.header(title, subtitle);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** @see Logger.divider */
|
|
121
|
-
divider(): void {
|
|
122
|
-
this.parent.divider();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** @see Logger.blank */
|
|
126
|
-
blank(): void {
|
|
127
|
-
this.parent.blank();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/** @see Logger.box */
|
|
131
|
-
box(content: string, options?: IBoxOptions): void {
|
|
132
|
-
this.parent.box(content, options);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** @see Logger.cliTable */
|
|
136
|
-
cliTable(rows: Record<string, unknown>[], options?: ITableOptions): void {
|
|
137
|
-
this.parent.cliTable(rows, options);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/** @see Logger.spinner */
|
|
141
|
-
spinner(message: string): ISpinnerHandle {
|
|
142
|
-
return this.parent.spinner(message);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/** @see Logger.setCLILevel */
|
|
146
|
-
setCLILevel(level: CLILogLevel): void {
|
|
147
|
-
this.parent.setCLILevel(level);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
_pushContext(context: string): void {
|
|
151
|
-
this.contextStack.push(context);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
_popContext(): void {
|
|
155
|
-
this.contextStack.pop();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export class APILogger extends ScopedLogger {
|
|
160
|
-
constructor(parent: Logger, apiName: string) {
|
|
161
|
-
super(parent, `API:${apiName}`);
|
|
162
|
-
this.badge('API');
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
slow(message: string, duration?: number): void {
|
|
166
|
-
this.badge('SLOW');
|
|
167
|
-
const msg = duration ? `${message} (${duration}ms)` : message;
|
|
168
|
-
this.warn(msg);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
rateLimit(message: string): void {
|
|
172
|
-
this.badge('RATE_LIMIT');
|
|
173
|
-
this.warn(message);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
auth(message: string): void {
|
|
177
|
-
this.badge('AUTH');
|
|
178
|
-
this.error(message);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
deprecated(message: string): void {
|
|
182
|
-
this.badge('DEPRECATED');
|
|
183
|
-
this.warn(message);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export class ComponentLogger extends ScopedLogger {
|
|
188
|
-
constructor(parent: Logger, componentName: string) {
|
|
189
|
-
super(parent, componentName);
|
|
190
|
-
this.badge('COMPONENT');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
lifecycle(event: string, message?: string): void {
|
|
194
|
-
this.badge('LIFECYCLE');
|
|
195
|
-
const msg = message ? `${event}: ${message}` : event;
|
|
196
|
-
this.info(msg);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
stateChange(from: string, to: string, data?: any): void {
|
|
200
|
-
this.badge('STATE');
|
|
201
|
-
const msg = `${from} → ${to}`;
|
|
202
|
-
if (data) {
|
|
203
|
-
this.info(msg, data);
|
|
204
|
-
} else {
|
|
205
|
-
this.info(msg);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
propsChange(changes: Record<string, any>): void {
|
|
210
|
-
this.badge('PROPS');
|
|
211
|
-
this.debug('Props changed:', changes);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
export class ContextLogger {
|
|
216
|
-
private parentLogger: ScopedLogger;
|
|
217
|
-
private contextName: string;
|
|
218
|
-
|
|
219
|
-
constructor(parentLogger: ScopedLogger, contextName: string) {
|
|
220
|
-
this.parentLogger = parentLogger;
|
|
221
|
-
this.contextName = contextName;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
run<T>(fn: () => T): T {
|
|
225
|
-
this.parentLogger._pushContext(this.contextName);
|
|
226
|
-
try {
|
|
227
|
-
return fn();
|
|
228
|
-
} finally {
|
|
229
|
-
this.parentLogger._popContext();
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async runAsync<T>(fn: () => Promise<T>): Promise<T> {
|
|
234
|
-
this.parentLogger._pushContext(this.contextName);
|
|
235
|
-
try {
|
|
236
|
-
return await fn();
|
|
237
|
-
} finally {
|
|
238
|
-
this.parentLogger._popContext();
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
start(): void {
|
|
243
|
-
this.parentLogger._pushContext(this.contextName);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
end(): void {
|
|
247
|
-
this.parentLogger._popContext();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
debug(...args: any[]): void { this.parentLogger.debug(...args); }
|
|
251
|
-
info(...args: any[]): void { this.parentLogger.info(...args); }
|
|
252
|
-
warn(...args: any[]): void { this.parentLogger.warn(...args); }
|
|
253
|
-
error(...args: any[]): void { this.parentLogger.error(...args); }
|
|
254
|
-
success(...args: any[]): void { this.parentLogger.success(...args); }
|
|
255
|
-
critical(...args: any[]): void { this.parentLogger.critical(...args); }
|
|
256
|
-
}
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview CLI Command processor for Advanced Logger
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { Logger } from '../Logger.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Base interface for CLI commands
|
|
9
|
-
*/
|
|
10
|
-
export interface ICommand {
|
|
11
|
-
name: string;
|
|
12
|
-
description: string;
|
|
13
|
-
usage: string;
|
|
14
|
-
category?: string;
|
|
15
|
-
aliases?: string[];
|
|
16
|
-
execute(args: string, logger: Logger): void | Promise<void>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Plugin interface for extending CLI functionality
|
|
21
|
-
*/
|
|
22
|
-
export interface ICLIPlugin {
|
|
23
|
-
name: string;
|
|
24
|
-
version: string;
|
|
25
|
-
description: string;
|
|
26
|
-
commands: ICommand[];
|
|
27
|
-
initialize?(processor: CommandProcessor, logger: Logger): void;
|
|
28
|
-
cleanup?(): void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Command history entry
|
|
33
|
-
*/
|
|
34
|
-
interface HistoryEntry {
|
|
35
|
-
command: string;
|
|
36
|
-
timestamp: Date;
|
|
37
|
-
success: boolean;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* CLI command processor
|
|
42
|
-
*/
|
|
43
|
-
export class CommandProcessor {
|
|
44
|
-
private commands: Map<string, ICommand> = new Map();
|
|
45
|
-
private aliases: Map<string, string> = new Map();
|
|
46
|
-
private plugins: Map<string, ICLIPlugin> = new Map();
|
|
47
|
-
private history: HistoryEntry[] = [];
|
|
48
|
-
private maxHistorySize: number = 100;
|
|
49
|
-
private isInteractiveMode: boolean = false;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Register a command
|
|
53
|
-
*/
|
|
54
|
-
registerCommand(command: ICommand): void {
|
|
55
|
-
this.commands.set(command.name, command);
|
|
56
|
-
|
|
57
|
-
// Register aliases
|
|
58
|
-
if (command.aliases) {
|
|
59
|
-
for (const alias of command.aliases) {
|
|
60
|
-
this.aliases.set(alias, command.name);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Register a plugin
|
|
67
|
-
*/
|
|
68
|
-
registerPlugin(plugin: ICLIPlugin, logger?: Logger): void {
|
|
69
|
-
if (this.plugins.has(plugin.name)) {
|
|
70
|
-
throw new Error(`Plugin ${plugin.name} is already registered`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this.plugins.set(plugin.name, plugin);
|
|
74
|
-
|
|
75
|
-
// Register plugin commands
|
|
76
|
-
for (const command of plugin.commands) {
|
|
77
|
-
this.registerCommand(command);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Initialize plugin
|
|
81
|
-
if (plugin.initialize && logger) {
|
|
82
|
-
plugin.initialize(this, logger);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Unregister a plugin
|
|
88
|
-
*/
|
|
89
|
-
unregisterPlugin(pluginName: string): void {
|
|
90
|
-
const plugin = this.plugins.get(pluginName);
|
|
91
|
-
if (!plugin) return;
|
|
92
|
-
|
|
93
|
-
// Remove plugin commands
|
|
94
|
-
for (const command of plugin.commands) {
|
|
95
|
-
this.commands.delete(command.name);
|
|
96
|
-
if (command.aliases) {
|
|
97
|
-
for (const alias of command.aliases) {
|
|
98
|
-
this.aliases.delete(alias);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Cleanup plugin
|
|
104
|
-
if (plugin.cleanup) {
|
|
105
|
-
plugin.cleanup();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
this.plugins.delete(pluginName);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Get all registered commands
|
|
113
|
-
*/
|
|
114
|
-
getCommands(): ICommand[] {
|
|
115
|
-
return Array.from(this.commands.values());
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Get a specific command
|
|
120
|
-
*/
|
|
121
|
-
getCommand(name: string): ICommand | undefined {
|
|
122
|
-
// Check direct command name
|
|
123
|
-
let command = this.commands.get(name);
|
|
124
|
-
if (command) return command;
|
|
125
|
-
|
|
126
|
-
// Check aliases
|
|
127
|
-
const aliasTarget = this.aliases.get(name);
|
|
128
|
-
if (aliasTarget) {
|
|
129
|
-
return this.commands.get(aliasTarget);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return undefined;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Get command history
|
|
137
|
-
*/
|
|
138
|
-
getHistory(): HistoryEntry[] {
|
|
139
|
-
return [...this.history];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Clear command history
|
|
144
|
-
*/
|
|
145
|
-
clearHistory(): void {
|
|
146
|
-
this.history = [];
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Get registered plugins
|
|
151
|
-
*/
|
|
152
|
-
getPlugins(): ICLIPlugin[] {
|
|
153
|
-
return Array.from(this.plugins.values());
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Enter interactive mode
|
|
158
|
-
*/
|
|
159
|
-
enterInteractiveMode(logger: Logger): void {
|
|
160
|
-
this.isInteractiveMode = true;
|
|
161
|
-
logger.info('🔧 Interactive CLI mode activated. Type /exit to quit, /help for commands.');
|
|
162
|
-
|
|
163
|
-
// Set up browser console listener for interactive commands
|
|
164
|
-
if (typeof window !== 'undefined') {
|
|
165
|
-
this.setupBrowserInteractiveMode(logger);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Exit interactive mode
|
|
171
|
-
*/
|
|
172
|
-
exitInteractiveMode(): void {
|
|
173
|
-
this.isInteractiveMode = false;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Setup browser interactive mode
|
|
178
|
-
*/
|
|
179
|
-
private setupBrowserInteractiveMode(logger: Logger): void {
|
|
180
|
-
// Add global CLI function for browser usage
|
|
181
|
-
(window as any).cli = (commandString: string) => {
|
|
182
|
-
return this.processCommand(`/${commandString}`, logger);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
logger.info('💡 Use cli("command") to execute CLI commands in browser console.');
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Process a CLI command
|
|
190
|
-
*/
|
|
191
|
-
async processCommand(commandString: string, logger: Logger): Promise<void> {
|
|
192
|
-
if (!commandString.startsWith('/')) {
|
|
193
|
-
logger.error('Invalid command. Commands must start with /');
|
|
194
|
-
this.addToHistory(commandString, false);
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const parts = commandString.slice(1).split(' ');
|
|
199
|
-
const commandName = parts[0] || '';
|
|
200
|
-
const args = parts.slice(1).join(' ');
|
|
201
|
-
|
|
202
|
-
const command = this.getCommand(commandName);
|
|
203
|
-
if (!command) {
|
|
204
|
-
logger.error(`Unknown command: ${commandName}. Type /help for available commands.`);
|
|
205
|
-
|
|
206
|
-
// Suggest similar commands
|
|
207
|
-
const suggestions = this.getSuggestions(commandName);
|
|
208
|
-
if (suggestions.length > 0) {
|
|
209
|
-
logger.info(`📋 Did you mean: ${suggestions.slice(0, 3).join(', ')}?`);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
this.addToHistory(commandString, false);
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
try {
|
|
217
|
-
await command.execute(args || '', logger);
|
|
218
|
-
this.addToHistory(commandString, true);
|
|
219
|
-
} catch (error) {
|
|
220
|
-
logger.error(`Command '${commandName}' failed:`, error);
|
|
221
|
-
this.addToHistory(commandString, false);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Add command to history
|
|
227
|
-
*/
|
|
228
|
-
private addToHistory(command: string, success: boolean): void {
|
|
229
|
-
this.history.unshift({
|
|
230
|
-
command,
|
|
231
|
-
timestamp: new Date(),
|
|
232
|
-
success
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
// Limit history size
|
|
236
|
-
if (this.history.length > this.maxHistorySize) {
|
|
237
|
-
this.history = this.history.slice(0, this.maxHistorySize);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Get command suggestions for partial matches
|
|
243
|
-
*/
|
|
244
|
-
getSuggestions(partial: string): string[] {
|
|
245
|
-
const commandNames = Array.from(this.commands.keys());
|
|
246
|
-
return commandNames.filter(name => name.startsWith(partial));
|
|
247
|
-
}
|
|
248
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Configuration commands for Advanced Logger CLI
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { ICommand } from '../CommandProcessor.js';
|
|
6
|
-
import type { Logger } from '../../Logger.js';
|
|
7
|
-
import type { ThemeVariant, BannerType, Verbosity } from '../../types/index.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Configuration command handler
|
|
11
|
-
*/
|
|
12
|
-
export class ConfigCommand implements ICommand {
|
|
13
|
-
name = 'config';
|
|
14
|
-
description = 'Show or update logger configuration';
|
|
15
|
-
usage = '/config [json|key=value,...]';
|
|
16
|
-
|
|
17
|
-
execute(args: string, logger: Logger): void {
|
|
18
|
-
if (!args) {
|
|
19
|
-
this.showStatus(logger);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
// Try to parse as JSON first
|
|
25
|
-
if (args.startsWith('{')) {
|
|
26
|
-
const config = JSON.parse(args);
|
|
27
|
-
this.applyConfig(config, logger);
|
|
28
|
-
} else {
|
|
29
|
-
// Parse key=value pairs
|
|
30
|
-
const pairs = args.split(',').map(pair => pair.trim().split('='));
|
|
31
|
-
const config: any = {};
|
|
32
|
-
pairs.forEach(([key, value]) => {
|
|
33
|
-
if (key && value) {
|
|
34
|
-
config[key.trim()] = value.trim().replace(/["']/g, '');
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
this.applyConfig(config, logger);
|
|
38
|
-
}
|
|
39
|
-
} catch (error) {
|
|
40
|
-
logger.error('Invalid config format. Use JSON or key=value pairs:', error);
|
|
41
|
-
logger.info('Examples: /config {"theme":"dark"} or /config theme=neon,verbosity=debug');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private showStatus(logger: Logger): void {
|
|
46
|
-
const statusData = {
|
|
47
|
-
theme: logger.getConfig().theme || 'default',
|
|
48
|
-
verbosity: logger.getConfig().verbosity,
|
|
49
|
-
colors: logger.getConfig().enableColors,
|
|
50
|
-
timestamps: logger.getConfig().enableTimestamps,
|
|
51
|
-
stackTrace: logger.getConfig().enableStackTrace,
|
|
52
|
-
globalPrefix: logger.getConfig().globalPrefix || 'none',
|
|
53
|
-
bannerType: logger.getConfig().bannerType || 'simple',
|
|
54
|
-
handlers: logger.getHandlers().length
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
logger.group('⚙️ Logger Configuration');
|
|
58
|
-
logger.table(statusData);
|
|
59
|
-
logger.groupEnd();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private applyConfig(config: any, logger: Logger): void {
|
|
63
|
-
const validKeys = ['theme', 'verbosity', 'enableColors', 'enableTimestamps', 'enableStackTrace', 'globalPrefix', 'bannerType'];
|
|
64
|
-
const applied: string[] = [];
|
|
65
|
-
|
|
66
|
-
Object.entries(config).forEach(([key, value]) => {
|
|
67
|
-
if (validKeys.includes(key)) {
|
|
68
|
-
if (key === 'theme' && typeof value === 'string') {
|
|
69
|
-
logger.setTheme(value as ThemeVariant);
|
|
70
|
-
applied.push(`${key}=${value}`);
|
|
71
|
-
} else if (key === 'bannerType' && typeof value === 'string') {
|
|
72
|
-
logger.setBannerType(value as BannerType);
|
|
73
|
-
applied.push(`${key}=${value}`);
|
|
74
|
-
} else if (key === 'verbosity') {
|
|
75
|
-
logger.setVerbosity(value as Verbosity);
|
|
76
|
-
applied.push(`${key}=${value}`);
|
|
77
|
-
} else if (key === 'globalPrefix') {
|
|
78
|
-
logger.setGlobalPrefix(value as string);
|
|
79
|
-
applied.push(`${key}=${value}`);
|
|
80
|
-
} else {
|
|
81
|
-
logger.updateConfig({ [key]: value });
|
|
82
|
-
applied.push(`${key}=${value}`);
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
logger.warn(`Invalid config key: ${key}`);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
if (applied.length > 0) {
|
|
90
|
-
logger.success(`Configuration updated: ${applied.join(', ')}`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|