-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fdc2a8
commit 9701567
Showing
3 changed files
with
51 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters