mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-16 22:46:03 +01:00
fix(version): split and compare semver in 3 parts
'11.10' is equal to '11.1' cause maths.
This commit is contained in:
@@ -19,12 +19,18 @@ function lib.versionCheck(repository)
|
||||
local latestVersion = response.tag_name:match('%d%.%d+%.%d+')
|
||||
if not latestVersion or latestVersion == currentVersion then return end
|
||||
|
||||
local cMajor, cMinor = string.strsplit('.', currentVersion, 2)
|
||||
local lMajor, lMinor = string.strsplit('.', latestVersion, 2)
|
||||
local cv = { string.strsplit('.', currentVersion) }
|
||||
local lv = { string.strsplit('.', latestVersion) }
|
||||
|
||||
if tonumber(cMajor) < tonumber(lMajor) or tonumber(cMinor) < tonumber(lMinor) then
|
||||
return print(('^3An update is available for %s (current version: %s)\r\n%s^0'):format(resource, currentVersion, response.html_url))
|
||||
end
|
||||
for i = 1, #cv do
|
||||
local current, minimum = tonumber(cv[i]), tonumber(lv[i])
|
||||
|
||||
if current ~= minimum then
|
||||
if current < minimum then
|
||||
return print(('^3An update is available for %s (current version: %s)\r\n%s^0'):format(resource, currentVersion, response.html_url))
|
||||
else break end
|
||||
end
|
||||
end
|
||||
end, 'GET')
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -2,16 +2,22 @@ function lib.checkDependency(resource, minimumVersion, printMessage)
|
||||
local currentVersion = GetResourceMetadata(resource, 'version', 0):match('%d%.%d+%.%d+')
|
||||
|
||||
if currentVersion ~= minimumVersion then
|
||||
local cMajor, cMinor = string.strsplit('.', currentVersion, 2)
|
||||
local mMajor, mMinor = string.strsplit('.', minimumVersion, 2)
|
||||
|
||||
local cv = { string.strsplit('.', currentVersion) }
|
||||
local mv = { string.strsplit('.', minimumVersion) }
|
||||
local msg = ("^1%s requires version '%s' of '%s' (current version: %s)^0"):format(GetInvokingResource() or GetCurrentResourceName(), minimumVersion, resource, currentVersion)
|
||||
if tonumber(cMajor) < tonumber(mMajor) or tonumber(cMinor) < tonumber(mMinor) then
|
||||
if printMessage then
|
||||
return print(msg)
|
||||
end
|
||||
|
||||
return false, msg
|
||||
for i = 1, #cv do
|
||||
local current, minimum = tonumber(cv[i]), tonumber(mv[i])
|
||||
|
||||
if current ~= minimum then
|
||||
if current < minimum then
|
||||
if printMessage then
|
||||
return print(msg)
|
||||
end
|
||||
|
||||
return false, msg
|
||||
else break end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user