@archznn/xavva 3.1.2 → 3.2.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.
- package/README.md +221 -12
- package/package.json +3 -2
- package/src/commands/AuditCommand.ts +12 -10
- package/src/commands/BuildCommand.ts +9 -7
- package/src/commands/ChangelogCommand.ts +5 -5
- package/src/commands/CleanCommand.ts +242 -0
- package/src/commands/CompletionCommand.ts +7 -7
- package/src/commands/DbCommand.ts +43 -14
- package/src/commands/DeployCommand.ts +252 -229
- package/src/commands/DepsCommand.ts +174 -174
- package/src/commands/DockerCommand.ts +35 -4
- package/src/commands/DoctorCommand.ts +252 -239
- package/src/commands/EncodingCommand.ts +26 -19
- package/src/commands/HealthCommand.ts +7 -7
- package/src/commands/HelpCommand.ts +34 -14
- package/src/commands/HistoryCommand.ts +5 -5
- package/src/commands/HttpCommand.ts +27 -1
- package/src/commands/IdeCommand.ts +313 -0
- package/src/commands/InitCommand.ts +26 -25
- package/src/commands/LogsCommand.ts +8 -6
- package/src/commands/ProfilesCommand.ts +6 -6
- package/src/commands/RedoCommand.ts +2 -2
- package/src/commands/RunCommand.ts +64 -24
- package/src/commands/StartCommand.ts +9 -7
- package/src/commands/TestCommand.ts +25 -1
- package/src/commands/TomcatCommand.ts +232 -88
- package/src/config/versions.ts +111 -9
- package/src/di/container.ts +239 -105
- package/src/errors/ErrorHandler.ts +23 -19
- package/src/errors/errorMessages.ts +235 -0
- package/src/index.ts +20 -6
- package/src/logging/FileLogger.ts +235 -0
- package/src/logging/Logger.ts +545 -0
- package/src/logging/OperationLogger.ts +296 -0
- package/src/logging/ProgressLogger.ts +187 -0
- package/src/logging/TableLogger.ts +246 -0
- package/src/logging/colors.ts +167 -0
- package/src/logging/constants.ts +176 -0
- package/src/logging/formatters.ts +337 -0
- package/src/logging/index.ts +93 -0
- package/src/logging/types.ts +64 -0
- package/src/plugins/PluginManager.ts +325 -0
- package/src/plugins/types.ts +82 -0
- package/src/services/AuditService.ts +5 -3
- package/src/services/BuildService.ts +15 -17
- package/src/services/DashboardService.ts +14 -3
- package/src/services/DbService.ts +35 -34
- package/src/services/DependencyAnalyzerService.ts +18 -18
- package/src/services/DependencyCacheService.ts +303 -0
- package/src/services/DeployWatcher.ts +127 -23
- package/src/services/DockerService.ts +3 -3
- package/src/services/EmbeddedTomcatService.ts +13 -12
- package/src/services/FileWatcher.ts +15 -7
- package/src/services/HttpService.ts +5 -5
- package/src/services/LogAnalyzer.ts +26 -22
- package/src/services/PerformanceProfiler.ts +267 -0
- package/src/services/ProjectService.ts +3 -0
- package/src/services/TestService.ts +3 -3
- package/src/services/TomcatService.ts +46 -25
- package/src/services/tomcat/TomcatBackupManager.ts +330 -0
- package/src/services/tomcat/TomcatChecksumVerifier.ts +211 -0
- package/src/services/tomcat/TomcatCompatibilityChecker.ts +298 -0
- package/src/services/tomcat/TomcatDownloadCache.ts +250 -0
- package/src/services/tomcat/TomcatDownloadService.ts +335 -0
- package/src/services/tomcat/TomcatInstallerService.ts +474 -0
- package/src/services/tomcat/TomcatMirrorManager.ts +181 -0
- package/src/services/tomcat/index.ts +36 -0
- package/src/services/tomcat/types.ts +120 -0
- package/src/types/args.ts +68 -1
- package/src/types/configSchema.ts +174 -0
- package/src/utils/ChangelogGenerator.ts +11 -11
- package/src/utils/LoggerLevel.ts +44 -20
- package/src/utils/ProgressBar.ts +87 -46
- package/src/utils/argsParser.ts +260 -0
- package/src/utils/config.ts +340 -189
- package/src/utils/constants.ts +87 -9
- package/src/utils/dryRun.ts +192 -0
- package/src/utils/processManager.ts +23 -7
- package/src/utils/security.ts +293 -0
- package/src/utils/ui.ts +299 -428
package/src/di/container.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Container de Injeção de Dependência (DI)
|
|
3
|
-
*
|
|
2
|
+
* Container de Injeção de Dependência (DI) com Lazy Loading
|
|
3
|
+
*
|
|
4
|
+
* Características:
|
|
5
|
+
* - Serviços são criados apenas quando necessários
|
|
6
|
+
* - Cache de instâncias para reuso
|
|
7
|
+
* - Inicialização rápida (só cria o essencial)
|
|
4
8
|
*/
|
|
5
9
|
|
|
6
10
|
import type { AppConfig } from "../types/config";
|
|
@@ -36,7 +40,8 @@ import { TestCommand } from "../commands/TestCommand";
|
|
|
36
40
|
import { DbCommand } from "../commands/DbCommand";
|
|
37
41
|
import { HttpCommand } from "../commands/HttpCommand";
|
|
38
42
|
import { DockerCommand } from "../commands/DockerCommand";
|
|
39
|
-
import {
|
|
43
|
+
import { CleanCommand } from "../commands/CleanCommand";
|
|
44
|
+
import { IdeCommand } from "../commands/IdeCommand";
|
|
40
45
|
import type { Command } from "../commands/Command";
|
|
41
46
|
import { Logger } from "../utils/ui";
|
|
42
47
|
|
|
@@ -78,20 +83,150 @@ export interface Commands {
|
|
|
78
83
|
db: DbCommand;
|
|
79
84
|
http: HttpCommand;
|
|
80
85
|
docker: DockerCommand;
|
|
86
|
+
clean: CleanCommand;
|
|
87
|
+
ide: IdeCommand;
|
|
81
88
|
}
|
|
82
89
|
|
|
90
|
+
// Tipo para factory functions
|
|
91
|
+
type ServiceFactory<T> = () => T;
|
|
92
|
+
type CommandFactory<T> = (services: Services) => T;
|
|
93
|
+
|
|
83
94
|
export class DIContainer {
|
|
84
95
|
private config: AppConfig;
|
|
85
|
-
|
|
86
|
-
|
|
96
|
+
|
|
97
|
+
// Cache de instâncias criadas
|
|
98
|
+
private serviceCache: Partial<Services> = {};
|
|
99
|
+
private commandCache: Partial<Commands> = {};
|
|
100
|
+
|
|
101
|
+
// Factories para lazy loading
|
|
102
|
+
private serviceFactories: Map<keyof Services, ServiceFactory<any>> = new Map();
|
|
103
|
+
private commandFactories: Map<keyof Commands, CommandFactory<any>> = new Map();
|
|
104
|
+
|
|
87
105
|
private isInitialized = false;
|
|
106
|
+
private initTime: number = 0;
|
|
88
107
|
|
|
89
108
|
constructor(config: AppConfig) {
|
|
90
109
|
this.config = config;
|
|
110
|
+
this.registerServiceFactories();
|
|
111
|
+
this.registerCommandFactories();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Registra todas as factories de serviços
|
|
116
|
+
*/
|
|
117
|
+
private registerServiceFactories(): void {
|
|
118
|
+
// Serviços base (sem dependências)
|
|
119
|
+
this.serviceFactories.set("projectService", () =>
|
|
120
|
+
new ProjectService(this.config.project)
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
this.serviceFactories.set("buildCacheService", () =>
|
|
124
|
+
new BuildCacheService()
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
this.serviceFactories.set("historyService", () =>
|
|
128
|
+
new HistoryService()
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
// Serviços com dependências
|
|
132
|
+
this.serviceFactories.set("dashboardService", () => {
|
|
133
|
+
const service = new DashboardService(this.config);
|
|
134
|
+
// Configura Logger com dashboard
|
|
135
|
+
Logger.setDashboard(service);
|
|
136
|
+
return service;
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
this.serviceFactories.set("logAnalyzer", () =>
|
|
140
|
+
new LogAnalyzer(this.config.project)
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
this.serviceFactories.set("tomcatService", () => {
|
|
144
|
+
const service = new TomcatService(this.config.tomcat);
|
|
145
|
+
// Lazy injeção de projectService
|
|
146
|
+
const projectService = this.getService("projectService");
|
|
147
|
+
service.setProjectService(projectService);
|
|
148
|
+
return service;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
this.serviceFactories.set("buildService", () => {
|
|
152
|
+
const projectService = this.getService("projectService");
|
|
153
|
+
const buildCacheService = this.getService("buildCacheService");
|
|
154
|
+
return new BuildService(
|
|
155
|
+
this.config.project,
|
|
156
|
+
this.config.tomcat,
|
|
157
|
+
projectService,
|
|
158
|
+
buildCacheService
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
this.serviceFactories.set("auditService", () =>
|
|
163
|
+
new AuditService(this.config.tomcat)
|
|
164
|
+
);
|
|
91
165
|
}
|
|
92
166
|
|
|
93
167
|
/**
|
|
94
|
-
*
|
|
168
|
+
* Registra todas as factories de comandos
|
|
169
|
+
*/
|
|
170
|
+
private registerCommandFactories(): void {
|
|
171
|
+
this.commandFactories.set("deploy", (s) =>
|
|
172
|
+
new DeployCommand(s.tomcatService, s.buildService)
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
this.commandFactories.set("dev", (s) =>
|
|
176
|
+
new DeployCommand(s.tomcatService, s.buildService)
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
this.commandFactories.set("build", (s) =>
|
|
180
|
+
new BuildCommand(s.buildService)
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
this.commandFactories.set("start", (s) =>
|
|
184
|
+
new StartCommand(s.tomcatService)
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
this.commandFactories.set("logs", (s) =>
|
|
188
|
+
new LogsCommand(s.dashboardService, s.logAnalyzer)
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
this.commandFactories.set("audit", (s) =>
|
|
192
|
+
new AuditCommand(s.auditService)
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
this.commandFactories.set("profiles", (s) =>
|
|
196
|
+
new ProfilesCommand(s.projectService)
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
this.commandFactories.set("run", (s) =>
|
|
200
|
+
new RunCommand(s.buildService)
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
this.commandFactories.set("debug", (s) =>
|
|
204
|
+
new RunCommand(s.buildService)
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
this.commandFactories.set("help", () => new HelpCommand());
|
|
208
|
+
this.commandFactories.set("doctor", () => new DoctorCommand());
|
|
209
|
+
this.commandFactories.set("deps", () => new DepsCommand());
|
|
210
|
+
this.commandFactories.set("tomcat", () => new TomcatCommand());
|
|
211
|
+
this.commandFactories.set("encoding", () => new EncodingCommand());
|
|
212
|
+
this.commandFactories.set("docs", () => new DocsCommand());
|
|
213
|
+
this.commandFactories.set("init", () => new InitCommand());
|
|
214
|
+
this.commandFactories.set("config", () => new ConfigCommand());
|
|
215
|
+
this.commandFactories.set("history", () => new HistoryCommand());
|
|
216
|
+
this.commandFactories.set("redo", () => new RedoCommand());
|
|
217
|
+
this.commandFactories.set("health", () => new HealthCommand());
|
|
218
|
+
this.commandFactories.set("completion", () => new CompletionCommand());
|
|
219
|
+
this.commandFactories.set("changelog", () => new ChangelogCommand());
|
|
220
|
+
this.commandFactories.set("test", () => new TestCommand());
|
|
221
|
+
this.commandFactories.set("db", () => new DbCommand());
|
|
222
|
+
this.commandFactories.set("http", () => new HttpCommand());
|
|
223
|
+
this.commandFactories.set("docker", () => new DockerCommand());
|
|
224
|
+
this.commandFactories.set("clean", () => new CleanCommand());
|
|
225
|
+
this.commandFactories.set("ide", () => new IdeCommand());
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Inicialização rápida - só cria serviços essenciais
|
|
95
230
|
*/
|
|
96
231
|
initialize(): void {
|
|
97
232
|
if (this.isInitialized) {
|
|
@@ -99,148 +234,147 @@ export class DIContainer {
|
|
|
99
234
|
return;
|
|
100
235
|
}
|
|
101
236
|
|
|
102
|
-
|
|
103
|
-
|
|
237
|
+
const startTime = performance.now();
|
|
238
|
+
|
|
239
|
+
// Só inicializa serviços essenciais
|
|
240
|
+
this.initEssentialServices();
|
|
241
|
+
|
|
242
|
+
this.initTime = performance.now() - startTime;
|
|
104
243
|
this.isInitialized = true;
|
|
244
|
+
|
|
245
|
+
Logger.debug(`DI Container inicializado em ${this.initTime.toFixed(2)}ms`);
|
|
105
246
|
}
|
|
106
247
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
// Configura Logger com dashboard
|
|
115
|
-
Logger.setDashboard(dashboardService);
|
|
116
|
-
|
|
117
|
-
// Serviços com dependências
|
|
118
|
-
const buildService = new BuildService(
|
|
119
|
-
this.config.project,
|
|
120
|
-
this.config.tomcat,
|
|
121
|
-
projectService,
|
|
122
|
-
buildCacheService
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
const tomcatService = new TomcatService(this.config.tomcat);
|
|
126
|
-
tomcatService.setProjectService(projectService);
|
|
127
|
-
|
|
128
|
-
const auditService = new AuditService(this.config.tomcat);
|
|
129
|
-
const historyService = new HistoryService();
|
|
130
|
-
|
|
131
|
-
this.services = {
|
|
132
|
-
projectService,
|
|
133
|
-
buildCacheService,
|
|
134
|
-
buildService,
|
|
135
|
-
tomcatService,
|
|
136
|
-
auditService,
|
|
137
|
-
dashboardService,
|
|
138
|
-
logAnalyzer,
|
|
139
|
-
historyService,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
private initializeCommands(): void {
|
|
144
|
-
const { tomcatService, buildService, auditService, dashboardService, logAnalyzer } = this.services;
|
|
145
|
-
|
|
146
|
-
if (!tomcatService || !buildService || !auditService || !dashboardService || !logAnalyzer) {
|
|
147
|
-
throw new Error("Serviços não inicializados corretamente");
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Comandos que compartilham instâncias
|
|
151
|
-
const deployCmd = new DeployCommand(tomcatService, buildService);
|
|
152
|
-
const logsCmd = new LogsCommand(dashboardService, logAnalyzer);
|
|
153
|
-
|
|
154
|
-
this.commands = {
|
|
155
|
-
deploy: deployCmd,
|
|
156
|
-
dev: deployCmd, // dev reusa deploy
|
|
157
|
-
build: new BuildCommand(buildService),
|
|
158
|
-
start: new StartCommand(tomcatService),
|
|
159
|
-
logs: logsCmd,
|
|
160
|
-
audit: new AuditCommand(auditService),
|
|
161
|
-
profiles: new ProfilesCommand(this.services.projectService!),
|
|
162
|
-
run: new RunCommand(),
|
|
163
|
-
debug: new RunCommand(),
|
|
164
|
-
help: new HelpCommand(),
|
|
165
|
-
doctor: new DoctorCommand(),
|
|
166
|
-
deps: new DepsCommand(),
|
|
167
|
-
tomcat: new TomcatCommand(),
|
|
168
|
-
encoding: new EncodingCommand(),
|
|
169
|
-
docs: new DocsCommand(),
|
|
170
|
-
init: new InitCommand(),
|
|
171
|
-
config: new ConfigCommand(),
|
|
172
|
-
history: new HistoryCommand(),
|
|
173
|
-
redo: new RedoCommand(),
|
|
174
|
-
health: new HealthCommand(),
|
|
175
|
-
completion: new CompletionCommand(),
|
|
176
|
-
changelog: new ChangelogCommand(),
|
|
177
|
-
test: new TestCommand(),
|
|
178
|
-
db: new DbCommand(),
|
|
179
|
-
http: new HttpCommand(),
|
|
180
|
-
docker: new DockerCommand(),
|
|
181
|
-
};
|
|
248
|
+
/**
|
|
249
|
+
* Inicializa apenas serviços essenciais
|
|
250
|
+
*/
|
|
251
|
+
private initEssentialServices(): void {
|
|
252
|
+
// ProjectService é essencial (usado por muitos outros serviços)
|
|
253
|
+
this.getService("projectService");
|
|
182
254
|
}
|
|
183
255
|
|
|
184
256
|
/**
|
|
185
|
-
* Obtém um serviço
|
|
257
|
+
* Obtém um serviço (lazy load com cache)
|
|
186
258
|
*/
|
|
187
259
|
getService<K extends keyof Services>(name: K): Services[K] {
|
|
188
|
-
|
|
189
|
-
|
|
260
|
+
// Retorna do cache se já existe
|
|
261
|
+
if (this.serviceCache[name]) {
|
|
262
|
+
return this.serviceCache[name]!;
|
|
190
263
|
}
|
|
191
|
-
|
|
192
|
-
|
|
264
|
+
|
|
265
|
+
// Cria via factory
|
|
266
|
+
const factory = this.serviceFactories.get(name);
|
|
267
|
+
if (!factory) {
|
|
193
268
|
throw new Error(`Serviço '${name}' não encontrado no container`);
|
|
194
269
|
}
|
|
195
|
-
|
|
270
|
+
|
|
271
|
+
const instance = factory();
|
|
272
|
+
this.serviceCache[name] = instance;
|
|
273
|
+
return instance;
|
|
196
274
|
}
|
|
197
275
|
|
|
198
276
|
/**
|
|
199
|
-
* Obtém um comando
|
|
277
|
+
* Obtém um comando (lazy load com cache)
|
|
200
278
|
*/
|
|
201
279
|
getCommand<K extends keyof Commands>(name: K): Commands[K] {
|
|
202
|
-
|
|
203
|
-
|
|
280
|
+
// Retorna do cache se já existe
|
|
281
|
+
if (this.commandCache[name]) {
|
|
282
|
+
return this.commandCache[name]!;
|
|
204
283
|
}
|
|
205
|
-
|
|
206
|
-
|
|
284
|
+
|
|
285
|
+
// Cria via factory
|
|
286
|
+
const factory = this.commandFactories.get(name);
|
|
287
|
+
if (!factory) {
|
|
207
288
|
throw new Error(`Comando '${name}' não encontrado no container`);
|
|
208
289
|
}
|
|
209
|
-
|
|
290
|
+
|
|
291
|
+
// Garante que serviços necessários estão disponíveis
|
|
292
|
+
const services = this.getAllServices();
|
|
293
|
+
const instance = factory(services);
|
|
294
|
+
this.commandCache[name] = instance;
|
|
295
|
+
return instance;
|
|
210
296
|
}
|
|
211
297
|
|
|
212
298
|
/**
|
|
213
|
-
* Obtém todos os serviços
|
|
299
|
+
* Obtém todos os serviços (cria todos)
|
|
214
300
|
*/
|
|
215
301
|
getAllServices(): Services {
|
|
216
|
-
|
|
217
|
-
|
|
302
|
+
// Força criação de todos os serviços
|
|
303
|
+
const serviceNames = Array.from(this.serviceFactories.keys()) as Array<keyof Services>;
|
|
304
|
+
for (const name of serviceNames) {
|
|
305
|
+
this.getService(name);
|
|
218
306
|
}
|
|
219
|
-
return this.
|
|
307
|
+
return this.serviceCache as Services;
|
|
220
308
|
}
|
|
221
309
|
|
|
222
310
|
/**
|
|
223
|
-
* Obtém todos os comandos
|
|
311
|
+
* Obtém todos os comandos (cria todos)
|
|
224
312
|
*/
|
|
225
313
|
getAllCommands(): Commands {
|
|
226
|
-
|
|
227
|
-
|
|
314
|
+
// Força criação de todos os comandos
|
|
315
|
+
const commandNames = Array.from(this.commandFactories.keys()) as Array<keyof Commands>;
|
|
316
|
+
for (const name of commandNames) {
|
|
317
|
+
this.getCommand(name);
|
|
228
318
|
}
|
|
229
|
-
return this.
|
|
319
|
+
return this.commandCache as Commands;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Verifica se um serviço está carregado
|
|
324
|
+
*/
|
|
325
|
+
isServiceLoaded<K extends keyof Services>(name: K): boolean {
|
|
326
|
+
return name in this.serviceCache;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Lista serviços carregados
|
|
331
|
+
*/
|
|
332
|
+
getLoadedServices(): Array<keyof Services> {
|
|
333
|
+
return Object.keys(this.serviceCache) as Array<keyof Services>;
|
|
230
334
|
}
|
|
231
335
|
|
|
232
336
|
/**
|
|
233
337
|
* Registra um serviço customizado (útil para testes)
|
|
234
338
|
*/
|
|
235
339
|
registerService<K extends keyof Services>(name: K, service: Services[K]): void {
|
|
236
|
-
this.
|
|
340
|
+
this.serviceCache[name] = service;
|
|
237
341
|
}
|
|
238
342
|
|
|
239
343
|
/**
|
|
240
344
|
* Registra um comando customizado (útil para testes)
|
|
241
345
|
*/
|
|
242
346
|
registerCommand<K extends keyof Commands>(name: K, command: Commands[K]): void {
|
|
243
|
-
this.
|
|
347
|
+
this.commandCache[name] = command;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Limpa todos os caches (útil para testes)
|
|
352
|
+
*/
|
|
353
|
+
reset(): void {
|
|
354
|
+
this.serviceCache = {};
|
|
355
|
+
this.commandCache = {};
|
|
356
|
+
this.isInitialized = false;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Obtém estatísticas do container
|
|
361
|
+
*/
|
|
362
|
+
getStats(): {
|
|
363
|
+
initialized: boolean;
|
|
364
|
+
initTime: number;
|
|
365
|
+
loadedServices: number;
|
|
366
|
+
loadedCommands: number;
|
|
367
|
+
totalServices: number;
|
|
368
|
+
totalCommands: number;
|
|
369
|
+
} {
|
|
370
|
+
return {
|
|
371
|
+
initialized: this.isInitialized,
|
|
372
|
+
initTime: this.initTime,
|
|
373
|
+
loadedServices: Object.keys(this.serviceCache).length,
|
|
374
|
+
loadedCommands: Object.keys(this.commandCache).length,
|
|
375
|
+
totalServices: this.serviceFactories.size,
|
|
376
|
+
totalCommands: this.commandFactories.size,
|
|
377
|
+
};
|
|
244
378
|
}
|
|
245
379
|
}
|
|
246
380
|
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
TomcatError,
|
|
14
14
|
ConfigError
|
|
15
15
|
} from "./XavvaError";
|
|
16
|
-
import { Logger } from "../
|
|
16
|
+
import { Logger } from "../logging";
|
|
17
17
|
import { ProcessManager } from "../utils/processManager";
|
|
18
18
|
|
|
19
19
|
export interface ErrorReport {
|
|
@@ -30,6 +30,7 @@ export class ErrorHandler {
|
|
|
30
30
|
private errorHistory: ErrorReport[] = [];
|
|
31
31
|
private maxHistorySize = 10;
|
|
32
32
|
private isShuttingDown = false;
|
|
33
|
+
private logger = Logger.getInstance();
|
|
33
34
|
|
|
34
35
|
private constructor() {}
|
|
35
36
|
|
|
@@ -61,8 +62,8 @@ export class ErrorHandler {
|
|
|
61
62
|
|
|
62
63
|
// Se não for erro operacional, mostra stack trace em verbose
|
|
63
64
|
if (!report.isOperational) {
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
this.logger.debug("Stack trace:");
|
|
66
|
+
this.logger.debug(normalizedError.stack || "N/A");
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
// Shutdown com código apropriado
|
|
@@ -82,7 +83,7 @@ export class ErrorHandler {
|
|
|
82
83
|
if (normalizedError instanceof XavvaError) {
|
|
83
84
|
this.logXavvaError(normalizedError, false);
|
|
84
85
|
} else {
|
|
85
|
-
|
|
86
|
+
this.logger.warn(`Erro inesperado: ${normalizedError.message}`);
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
return report;
|
|
@@ -142,42 +143,45 @@ export class ErrorHandler {
|
|
|
142
143
|
* Loga erro Xavva com formatação adequada
|
|
143
144
|
*/
|
|
144
145
|
private logXavvaError(error: XavvaError, isFatal: boolean): void {
|
|
145
|
-
const logMethod = isFatal ?
|
|
146
|
+
const logMethod = isFatal ? this.logger.error.bind(this.logger) : this.logger.warn.bind(this.logger);
|
|
146
147
|
|
|
147
148
|
// Cabeçalho do erro
|
|
148
|
-
logMethod
|
|
149
|
+
logMethod(error.message);
|
|
149
150
|
|
|
150
151
|
// Detalhes adicionais se houver
|
|
151
152
|
if (error instanceof NetworkError) {
|
|
152
|
-
|
|
153
|
+
this.logger.info("Dica: Verifique sua conexão de internet e tente novamente");
|
|
153
154
|
} else if (error instanceof FileSystemError) {
|
|
154
|
-
|
|
155
|
+
this.logger.info("Dica: Verifique as permissões do arquivo/diretório");
|
|
155
156
|
} else if (error instanceof BuildError) {
|
|
156
|
-
|
|
157
|
+
this.logger.info("Dica: Use --verbose para ver detalhes completos do build");
|
|
157
158
|
} else if (error instanceof TomcatError) {
|
|
158
|
-
|
|
159
|
+
this.logger.info("Dica: Verifique se o Tomcat está configurado corretamente");
|
|
159
160
|
} else if (error instanceof ConfigError) {
|
|
160
|
-
|
|
161
|
+
this.logger.info("Dica: Verifique seu arquivo xavva.json");
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
// Código do erro em debug
|
|
164
|
-
|
|
165
|
+
this.logger.debug(`Código do erro: ${error.code} (exit ${error.exitCode})`);
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
/**
|
|
168
169
|
* Trata erros inesperados (bugs)
|
|
169
170
|
*/
|
|
170
171
|
private handleUnexpectedError(error: Error): void {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
this.logger.error("Erro inesperado:");
|
|
173
|
+
this.logger.error(error.message);
|
|
174
|
+
this.logger.newline();
|
|
175
|
+
this.logger.info("Isso parece ser um bug", "Por favor, reporte em github.com/leorsousa05/Xavva/issues");
|
|
175
176
|
|
|
176
177
|
// Sempre mostra stack trace para erros inesperados
|
|
177
178
|
if (error.stack) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
this.logger.newline();
|
|
180
|
+
this.logger.debug("Stack trace:");
|
|
181
|
+
const lines = error.stack.split("\n").slice(1, 5);
|
|
182
|
+
for (const line of lines) {
|
|
183
|
+
this.logger.debug(line.trim());
|
|
184
|
+
}
|
|
181
185
|
}
|
|
182
186
|
}
|
|
183
187
|
|