diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2022-01-18 21:42:49 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-01-27 10:39:37 +0100 |
| commit | 90ae963575524bda543a32aedcfd644dd7e2b495 (patch) | |
| tree | 8ad13be4a92926c9bfa59a403ce5581dfb3ee355 /gui/src | |
| parent | 69b1fa941931849d484e88e1676b057001a6cc10 (diff) | |
| download | mullvadvpn-90ae963575524bda543a32aedcfd644dd7e2b495.tar.xz mullvadvpn-90ae963575524bda543a32aedcfd644dd7e2b495.zip | |
Add changelog and parsing of it
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/changelog.ts | 65 | ||||
| -rw-r--r-- | gui/src/shared/ipc-types.ts | 2 |
2 files changed, 67 insertions, 0 deletions
diff --git a/gui/src/main/changelog.ts b/gui/src/main/changelog.ts new file mode 100644 index 0000000000..4c169b055b --- /dev/null +++ b/gui/src/main/changelog.ts @@ -0,0 +1,65 @@ +import fs from 'fs'; +import path from 'path'; +import { IChangelog } from '../shared/ipc-types'; +import log from '../shared/logging'; + +// Reads and parses the changelog file. +export function readChangelog(): IChangelog { + try { + const changelogPath = path.join(__dirname, '..', '..', '..', 'changelog.txt'); + const contents = fs.readFileSync(changelogPath).toString(); + return parseChangelog(contents); + } catch (e) { + const error = e as Error; + log.error('Failed to read changelog.txt', error.message); + return []; + } +} + +// Parses the contents of the changelog file and returns all relevant items. +export function parseChangelog(changelog: string): IChangelog { + const items = changelog + .split('\n') + .map((item) => item.trim()) + .filter((item) => item !== ''); + return filterForPlatform(items); +} + +// Filters the changelog items based on platform +function filterForPlatform(items: Array<string>): IChangelog { + return items + .map((item) => { + // Extracts the platforms from from the string if there are any specified. Platforms are + // specified within brackets with separated with a comma. + const platforms = item + .match(/^\[.*?\]/) + ?.flatMap((match) => match.slice(1, -1).split(',')) + .map((platform) => platform.trim()); + if (!platforms || isPlatform(platforms)) { + // If there are no platforms specified or if the current platform matches one of the + // specified, then the item is included. + return item.replace(/^\[.*?\]/, '').trim(); + } else { + return undefined; + } + }) + .filter((item): item is string => item !== undefined); +} + +// Checks if an OS name corresponds to the current platform. +function isPlatform(platformNames: Array<string>): boolean { + const platforms = platformNames.map((platformName) => { + switch (platformName.toLowerCase()) { + case 'windows': + return 'win32'; + case 'macos': + return 'darwin'; + case 'linux': + return 'linux'; + default: + return platformName; + } + }); + + return platforms.includes(process.platform); +} diff --git a/gui/src/shared/ipc-types.ts b/gui/src/shared/ipc-types.ts index 691d54b61b..0624ac95cd 100644 --- a/gui/src/shared/ipc-types.ts +++ b/gui/src/shared/ipc-types.ts @@ -8,3 +8,5 @@ export interface ICurrentAppVersionInfo { export interface IWindowShapeParameters { arrowPosition?: number; } + +export type IChangelog = Array<string>; |
