Skip to content

Commit

Permalink
Allow settings updater to read semver suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
noatpad committed Sep 15, 2023
1 parent 1334720 commit aa4536a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "obsidian-banners-2",
"name": "Banners 2",
"description": "Add banner images to your notes!",
"version": "2.0.0",
"version": "2.0.0-beta",
"minAppVersion": "0.14.0",
"author": "Noatpad",
"authorUrl": "https://github.com/noatpad",
Expand Down
9 changes: 6 additions & 3 deletions src/settings/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type SettingsData = Record<string, unknown> & {
type KeyChanges = Record<string, string>;
type ValueChanges = Record<string, Record<string, string>>;
type Removals = string[];

interface BreakingChanges {
version: string;
changes: {
Expand All @@ -17,6 +18,8 @@ interface BreakingChanges {
};
}

const SEMVER_REGEX = /^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)/;

const breakingChanges: BreakingChanges[] = [
{
version: '2.0.0',
Expand Down Expand Up @@ -47,9 +50,9 @@ const breakingChanges: BreakingChanges[] = [

const isVersionBelow = (a: string | null, b: string): boolean => {
if (!a) return true; // Edge case for 1.X versions
const [aMax, aMin, aPatch] = a.split('.');
const [bMax, bMin, bPatch] = b.split('.');
return (+aMax < +bMax) || (+aMin < +bMin) || (+aPatch < +bPatch);
const { major: aMajor, minor: aMinor, patch: aPatch } = a.match(SEMVER_REGEX)!.groups!;
const { major: bMajor, minor: bMinor, patch: bPatch } = b.match(SEMVER_REGEX)!.groups!;
return (+aMajor < +bMajor) || (+aMinor < +bMinor) || (+aPatch < +bPatch);
};

const updateKeys = (data: SettingsData, keys: KeyChanges) => {
Expand Down

0 comments on commit aa4536a

Please sign in to comment.