|
1 | 1 | import * as vscode from 'vscode';
|
2 | 2 | import * as fs from 'fs';
|
3 | 3 | import * as path from 'path';
|
4 |
| -import { pathExists, getLineCount, getIconForLogLevel } from './helpers'; |
| 4 | +import { pathExists, getLineCount, getIconForLogLevel, getLogItems, parseReportTitle, getIconForReport } from './helpers'; |
5 | 5 |
|
6 | 6 | export class LogViewerProvider implements vscode.TreeDataProvider<LogItem>, vscode.Disposable {
|
7 | 7 | private _onDidChangeTreeData: vscode.EventEmitter<LogItem | undefined | void> = new vscode.EventEmitter<LogItem | undefined | void>();
|
@@ -235,69 +235,7 @@ export class ReportViewerProvider implements vscode.TreeDataProvider<LogItem>, v
|
235 | 235 | }
|
236 | 236 |
|
237 | 237 | private getLogItems(dir: string, label: string): LogItem[] {
|
238 |
| - if (!pathExists(dir)) { |
239 |
| - return []; |
240 |
| - } |
241 |
| - |
242 |
| - const items: LogItem[] = []; |
243 |
| - const files = fs.readdirSync(dir); |
244 |
| - |
245 |
| - files.forEach(file => { |
246 |
| - const filePath = path.join(dir, file); |
247 |
| - if (fs.lstatSync(filePath).isDirectory()) { |
248 |
| - const subItems = this.getLogItems(filePath, label); |
249 |
| - if (subItems.length > 0) { |
250 |
| - items.push(...subItems); |
251 |
| - } |
252 |
| - } else if (fs.lstatSync(filePath).isFile()) { |
253 |
| - const title = this.parseReportTitle(filePath); |
254 |
| - const logFile = new LogItem(title, vscode.TreeItemCollapsibleState.None, { |
255 |
| - command: 'magento-log-viewer.openFile', |
256 |
| - title: 'Open Log File', |
257 |
| - arguments: [filePath] |
258 |
| - }); |
259 |
| - logFile.iconPath = this.getIconForReport(filePath); |
260 |
| - items.push(logFile); |
261 |
| - } |
262 |
| - }); |
263 |
| - |
264 |
| - return items; |
265 |
| - } |
266 |
| - |
267 |
| - private parseReportTitle(filePath: string): string { |
268 |
| - try { |
269 |
| - const fileContent = fs.readFileSync(filePath, 'utf-8'); |
270 |
| - const report = JSON.parse(fileContent); |
271 |
| - |
272 |
| - if (filePath.includes('/api/')) { |
273 |
| - const folderName = path.basename(path.dirname(filePath)); |
274 |
| - const capitalizedFolderName = folderName.charAt(0).toUpperCase() + folderName.slice(1); |
275 |
| - return `${capitalizedFolderName}: ${report}`; |
276 |
| - } |
277 |
| - |
278 |
| - return report['0'] || path.basename(filePath); |
279 |
| - } catch (error) { |
280 |
| - return path.basename(filePath); |
281 |
| - } |
282 |
| - } |
283 |
| - |
284 |
| - private getIconForReport(filePath: string): vscode.ThemeIcon { |
285 |
| - try { |
286 |
| - const fileContent = fs.readFileSync(filePath, 'utf-8'); |
287 |
| - const report = JSON.parse(fileContent); |
288 |
| - |
289 |
| - if (filePath.includes('/api/')) { |
290 |
| - return new vscode.ThemeIcon('warning'); |
291 |
| - } |
292 |
| - |
293 |
| - if (report['0'] && report['0'].toLowerCase().includes('error')) { |
294 |
| - return new vscode.ThemeIcon('error'); |
295 |
| - } |
296 |
| - |
297 |
| - return new vscode.ThemeIcon('file'); |
298 |
| - } catch (error) { |
299 |
| - return new vscode.ThemeIcon('file'); |
300 |
| - } |
| 238 | + return getLogItems(dir, parseReportTitle, getIconForReport); |
301 | 239 | }
|
302 | 240 |
|
303 | 241 | getLogFilesWithoutUpdatingBadge(dir: string): LogItem[] {
|
|
0 commit comments