Skip to content

Commit

Permalink
Merge pull request #9 from OpenForgeProject/update-trunk
Browse files Browse the repository at this point in the history
feat: Delete Reports, Github-Workflows, Release 1.7.0
  • Loading branch information
dermatz authored Dec 8, 2024
2 parents df15c28 + a273e47 commit d46bf61
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 12 deletions.
35 changes: 35 additions & 0 deletions .github/ workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install

- name: Compile the extension
run: npm run compile

- name: Run tests
run: npm test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ logs/

# VS Code
.vscode/
.vscode-test/
out/

# Build directories
dist/
Expand Down
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ vsc-extension-quickstart.md
**/*.map
**/*.ts
**/.vscode-test.*
.trunk/**
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## [Unreleased]

## [1.6.0] - 2023-10-07
## [1.7.0] - 2024-12-08

### Added

- Added a right click context menu to delete report files
- Added tests to check the extension features automaticly

### Changed

- Changed `README.md` with latest features
- Changed Extension Logo
- Changed Changelog Dates for 1.6.0 Release Date

## [1.6.0] - 2024-12-07

### Added

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The Magento Log Viewer extension for Visual Studio Code provides a convenient wa
- Status bar showing total log entries
- Real-time log file monitoring
- Badge in the tree view showing the total number of log entries
- Improved report file titles by parsing content for better readability

## Setup

Expand Down
20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magento-log-viewer",
"displayName": "Magento Log Viewer",
"description": "A Visual Studio Code extension to view and manage Magento log files.",
"version": "1.6.0",
"version": "1.7.0",
"publisher": "MathiasElle",
"icon": "resources/logo.png",
"repository": {
Expand Down Expand Up @@ -39,6 +39,11 @@
"command": "magento-log-viewer.refreshReportFiles",
"title": "Refresh Report Files",
"icon": "$(refresh)"
},
{
"command": "magento-log-viewer.deleteReportFile",
"title": "Delete Report File",
"icon": "$(trash)"
}
],
"configuration": {
Expand All @@ -47,7 +52,11 @@
"properties": {
"magentoLogViewer.isMagentoProject": {
"type": "string",
"enum": ["Yes", "No", "Please select"],
"enum": [
"Yes",
"No",
"Please select"
],
"default": "Please select",
"description": "This is a Magento project",
"scope": "resource"
Expand Down Expand Up @@ -113,6 +122,13 @@
"when": "view == reportFiles && magentoLogViewer.hasMagentoRoot",
"group": "navigation"
}
],
"view/item/context": [
{
"command": "magento-log-viewer.deleteReportFile",
"when": "view == reportFiles && viewItem == reportItem",
"group": "navigation"
}
]
}
},
Expand Down
Binary file modified resources/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import { promptMagentoProjectSelection, showErrorMessage, activateExtension, isValidPath } from './helpers';
import { promptMagentoProjectSelection, showErrorMessage, activateExtension, isValidPath, deleteReportFile } from './helpers';
import { LogItem, ReportViewerProvider } from './logViewer';

export function activate(context: vscode.ExtensionContext): void {
const config = vscode.workspace.getConfiguration();
Expand All @@ -13,7 +14,18 @@ export function activate(context: vscode.ExtensionContext): void {
showErrorMessage('Magento root path is not set or is not a directory.');
return;
}
activateExtension(context, magentoRoot);
const reportViewerProvider = new ReportViewerProvider(magentoRoot);
activateExtension(context, magentoRoot, reportViewerProvider);

vscode.commands.registerCommand('magento-log-viewer.deleteReportFile', (logItem: LogItem) => {
if (logItem && logItem.command && logItem.command.arguments && logItem.command.arguments[0]) {
const filePath = logItem.command.arguments[0];
deleteReportFile(filePath);
reportViewerProvider.refresh();
} else {
showErrorMessage('Failed to delete report file: Invalid file path.');
}
});
}
}

Expand Down
15 changes: 12 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function selectMagentoRootFolder(config: vscode.WorkspaceConfiguration, c
updateConfig(config, 'magentoLogViewer.magentoRoot', folderUri[0].fsPath).then(() => {
showInformationMessage('Magento root folder successfully saved!');
updateConfig(config, 'magentoLogViewer.isMagentoProject', 'Yes');
activateExtension(context, folderUri[0].fsPath);
activateExtension(context, folderUri[0].fsPath, new ReportViewerProvider(folderUri[0].fsPath));
});
}
});
Expand Down Expand Up @@ -57,9 +57,8 @@ export function showErrorMessage(message: string): void {
}

// Activates the extension by setting up the log viewer and file system watcher.
export function activateExtension(context: vscode.ExtensionContext, magentoRoot: string): void {
export function activateExtension(context: vscode.ExtensionContext, magentoRoot: string, reportViewerProvider: ReportViewerProvider): void {
const logViewerProvider = new LogViewerProvider(magentoRoot);
const reportViewerProvider = new ReportViewerProvider(magentoRoot);

const logTreeView = vscode.window.createTreeView('logFiles', { treeDataProvider: logViewerProvider });
const reportTreeView = vscode.window.createTreeView('reportFiles', { treeDataProvider: reportViewerProvider });
Expand Down Expand Up @@ -127,6 +126,16 @@ export function clearAllLogFiles(logViewerProvider: LogViewerProvider, magentoRo
});
}

// Deletes a report file.
export function deleteReportFile(filePath: string): void {
try {
fs.unlinkSync(filePath);
showInformationMessage(`Report file ${filePath} deleted successfully.`);
} catch (error) {
showErrorMessage(`Failed to delete report file ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
}
}

// Updates the badge count for the tree view based on the number of log entries.
export function updateBadge(treeView: vscode.TreeView<unknown>, logViewerProvider: LogViewerProvider, reportViewerProvider: ReportViewerProvider, magentoRoot: string): void {
const updateBadgeCount = () => {
Expand Down
5 changes: 4 additions & 1 deletion src/logViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ export class ReportViewerProvider implements vscode.TreeDataProvider<LogItem>, v
}

private getLogItems(dir: string, label: string): LogItem[] {
return getLogItems(dir, parseReportTitle, getIconForReport);
return getLogItems(dir, parseReportTitle, getIconForReport).map(item => {
item.contextValue = 'reportItem';
return item;
});
}

getLogFilesWithoutUpdatingBadge(dir: string): LogItem[] {
Expand Down
44 changes: 41 additions & 3 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,49 @@ import * as assert from 'assert';
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';

const extensionId = 'MathiasElle.magento-log-viewer';

suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');

test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
test('Extension should be present', () => {
const extension = vscode.extensions.getExtension(extensionId);
assert.ok(extension, "Extension is not installed");
});

test('Extension should activate', async () => {
const extension = vscode.extensions.getExtension(extensionId);
if (extension) {
await extension.activate();
assert.ok(extension.isActive, "Extension is not active");
}
});

test('Extension should start', async () => {
const extension = vscode.extensions.getExtension(extensionId);
if (extension) {
await extension.activate();
assert.ok(extension.isActive, "Extension did not start");
}
});

test('Extension should add settings section', () => {
const configuration = vscode.workspace.getConfiguration('magentoLogViewer');
const isMagentoProject = configuration.get('isMagentoProject');
assert.notStrictEqual(isMagentoProject, undefined, "Settings section 'magentoLogViewer' is not added");
});

test('Extension should prompt if it is a Magento project', async () => {
const configuration = vscode.workspace.getConfiguration('magentoLogViewer');
const isMagentoProject = configuration.get('isMagentoProject');
assert.strictEqual(isMagentoProject, 'Please select', "Extension did not prompt if it is a Magento project");
});

test('Extension should have logo in activity bar', async () => {
const activityBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
activityBarItem.text = '$(magento-logfile-viewer-logo)';
activityBarItem.show();
assert.strictEqual(activityBarItem.text, '$(magento-logfile-viewer-logo)', "Logo is not present in the activity bar");
});

});

0 comments on commit d46bf61

Please sign in to comment.