forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_version.tsx
60 lines (52 loc) · 2.13 KB
/
server_version.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
/**
* Compare server versions, ignoring the configuration hash and licensed status.
*
* For example, the following two server versions are considered equal:
* 4.7.1.dev.3034fbc5fd566195d1b53e03890e35ff.true
* 4.7.1.dev.d131dd02c5e6eec4693d9a0698aff95c.false
*
* but the following two are not
* 4.7.0.dev.3034fbc5fd566195d1b53e03890e35ff.true
* 4.7.1.dev.d131dd02c5e6eec4693d9a0698aff95c.true
*/
export function equalServerVersions(a: string, b: string): boolean {
if (a === b) {
return true;
}
const ignoredComponents = 2;
const aIgnoringComponents = (a || '').split('.').slice(0, -ignoredComponents).join('.');
const bIgnoringComponents = (b || '').split('.').slice(0, -ignoredComponents).join('.');
if (aIgnoringComponents === bIgnoringComponents) {
return true;
}
return false;
}
/**
* Boolean function to check if a server version is greater than another.
*
* currentVersion: The server version being checked
* compareVersion: The version to compare the former version against
*
* eg. currentVersion = 4.16.0, compareVersion = 4.17.0 returns false
* currentVersion = 4.16.1, compareVersion = 4.16.1 returns true
*/
export function isServerVersionGreaterThanOrEqualTo(currentVersion: string, compareVersion: string): boolean {
if (currentVersion === compareVersion) {
return true;
}
// We only care about the numbers
const currentVersionNumber = (currentVersion || '').split('.').filter((x) => (/^[0-9]+$/).exec(x) !== null);
const compareVersionNumber = (compareVersion || '').split('.').filter((x) => (/^[0-9]+$/).exec(x) !== null);
for (let i = 0; i < Math.max(currentVersionNumber.length, compareVersionNumber.length); i++) {
if ((currentVersionNumber[i] || 0) > (compareVersionNumber[i] || 0)) {
return true;
}
if ((currentVersionNumber[i] || 0) < (compareVersionNumber[i] || 0)) {
return false;
}
}
// If all components are equal, then return true
return true;
}