Skip to content

Commit

Permalink
end
Browse files Browse the repository at this point in the history
  • Loading branch information
israelpoli committed Nov 14, 2024
1 parent 8fdc2a8 commit 9701567
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 48 deletions.
23 changes: 1 addition & 22 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Logger } from './logger';
import { setupIntegrationEnv, installDevEnv as installDevEnv, configureDemistoVars, developDemistoSDK } from './devEnvs';
import JSON5 from 'json5'
import * as runAndDebug from './runAndDebug'
import { findDir, getLastRNFile } from './tools';
import { openLastRN } from './openLastRN';

// this function returns the directory path of the file
export function getDirPath(file: vscode.Uri | undefined): string {
Expand Down Expand Up @@ -175,27 +175,6 @@ export function activate(context: vscode.ExtensionContext): void {
export function deactivate(): void { Logger.info('deactivated') }


function openLastRN(dirPath: string) {
findDir(dirPath, 'ReleaseNotes').then(
ReleaseNotesDir => {
if (ReleaseNotesDir === undefined) {
vscode.window.showErrorMessage('The current file is not under the "Packs" directory.');
return;
}
if (!ReleaseNotesDir) {
vscode.window.showErrorMessage('No ReleaseNotes directory found.');
return;
}
getLastRNFile(ReleaseNotesDir).then(
lastReleaseNotesFile => {
const relativeFilePath = path.join(ReleaseNotesDir, lastReleaseNotesFile);
vscode.workspace.openTextDocument(vscode.Uri.file(relativeFilePath))
.then(doc => vscode.window.showTextDocument(doc));
});
}
)
}

function autoGetProblems(
workspaces: readonly vscode.WorkspaceFolder[],
diagnosticCollection: vscode.DiagnosticCollection
Expand Down
50 changes: 50 additions & 0 deletions src/openLastRN.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as vscode from 'vscode';
import * as path from "path";
import { findDir } from './tools';
import { promises as fsp } from 'fs';
import * as semver from 'semver';


export function openLastRN(dirPath: string): void {
findDir(dirPath, 'ReleaseNotes').then(
ReleaseNotesDir => {
if (ReleaseNotesDir === undefined) {
vscode.window.showErrorMessage('The current file is not under the "Packs" directory.');
return;
}
if (!ReleaseNotesDir) {
vscode.window.showErrorMessage('No ReleaseNotes directory found.');
return;
}
getLastRNFile(ReleaseNotesDir).then(
lastReleaseNotesFile => {
const relativeFilePath = path.join(ReleaseNotesDir, lastReleaseNotesFile);
vscode.workspace.openTextDocument(vscode.Uri.file(relativeFilePath))
.then(doc => vscode.window.showTextDocument(doc));
});
}
)
}

async function getLastRNFile(directoryPath: string): Promise<string> {
try {
const entries = await fsp.readdir(directoryPath, { withFileTypes: true });
let maxSum = "0.0.0";
let latestFile = "";

entries.forEach(entry => {
if (entry.isFile()) {
const version = path.parse(entry.name).name.replace(/_/g, '.')
if (semver.gt(version, maxSum)) {
maxSum = version;
latestFile = entry.name;
}
}
});

return latestFile;
} catch (error) {
console.error('Error reading directory:', error);
throw error;
}
}
26 changes: 0 additions & 26 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { AutomationI, IntegrationI } from './contentObject';
import * as fs from "fs-extra";
import { Logger } from './logger';
import { TerminalManager } from './terminalManager';
import { promises as fsp } from 'fs';
import * as semver from 'semver';


export function sendCommandExtraArgsWithUserInput(command: string[]): void {
Expand Down Expand Up @@ -357,27 +355,3 @@ export async function findDir(basePath: string, dirName: string): Promise<string

return null;
}

export async function getLastRNFile(directoryPath: string): Promise<string> {
try {
const entries = await fsp.readdir(directoryPath, { withFileTypes: true });
let maxSum = "0.0.0";
let latestFile = "";

entries.forEach(entry => {
if (entry.isFile()) {
const version = path.parse(entry.name).name.replace(/_/g, '.')
if (semver.gt(version, maxSum)) {
maxSum = version;
latestFile = entry.name;
}
}
});

return latestFile;
} catch (error) {
console.error('Error reading directory:', error);
throw error;
}
}

0 comments on commit 9701567

Please sign in to comment.