-
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.
Merge pull request #63 from demisto/open_last_rn
Add `Open Last RN` command
- Loading branch information
Showing
6 changed files
with
131 additions
and
2 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 { findDirUnderPacks } from './tools'; | ||
import { promises as fsp } from 'fs'; | ||
import * as semver from 'semver'; | ||
|
||
|
||
export function openLastRN(dirPath: string): void { | ||
findDirUnderPacks(dirPath, 'ReleaseNotes').then( | ||
ReleaseNotesDir => { | ||
if (ReleaseNotesDir === undefined) { | ||
vscode.window.showErrorMessage('Cortex "Open last release note" only works on files under the Packs directory.'); | ||
return; | ||
} | ||
if (!ReleaseNotesDir) { | ||
vscode.window.showErrorMessage('Unable to find a ReleaseNotes directory.'); | ||
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 finding last release note in', directoryPath, 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