mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 07:56:02 +01:00
fix(version): compare semver numbers
Values were being compared as whole strings.
This commit is contained in:
@@ -17,11 +17,16 @@ function lib.versionCheck(repository)
|
|||||||
if response.prerelease then return end
|
if response.prerelease then return end
|
||||||
|
|
||||||
local latestVersion = response.tag_name:match('%d%.%d+%.%d+')
|
local latestVersion = response.tag_name:match('%d%.%d+%.%d+')
|
||||||
if not latestVersion then return end
|
if not latestVersion or latestVersion == currentVersion then return end
|
||||||
|
|
||||||
if currentVersion >= latestVersion then return end
|
local cv = { string.strsplit('.', currentVersion) }
|
||||||
|
local lv = { string.strsplit('.', latestVersion) }
|
||||||
|
|
||||||
print(('^3An update is available for %s (current version: %s)\r\n%s^0'):format(resource, currentVersion, response.html_url))
|
for i = 1, #cv do
|
||||||
|
if tonumber(cv[i]) < tonumber(lv[i]) then
|
||||||
|
return print(('^3An update is available for %s (current version: %s)\r\n%s^0'):format(resource, currentVersion, response.html_url))
|
||||||
|
end
|
||||||
|
end
|
||||||
end, 'GET')
|
end, 'GET')
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
function lib.checkDependency(resource, minimumVersion, printMessage)
|
function lib.checkDependency(resource, minimumVersion, printMessage)
|
||||||
local currentVersion = GetResourceMetadata(resource, 'version', 0):match('%d%.%d+%.%d+')
|
local currentVersion = GetResourceMetadata(resource, 'version', 0):match('%d%.%d+%.%d+')
|
||||||
|
|
||||||
if currentVersion < minimumVersion then
|
if currentVersion ~= minimumVersion then
|
||||||
|
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)
|
local msg = ("^1%s requires version '%s' of '%s' (current version: %s)^0"):format(GetInvokingResource() or GetCurrentResourceName(), minimumVersion, resource, currentVersion)
|
||||||
|
|
||||||
if printMessage then
|
for i = 1, #cv do
|
||||||
return print(msg)
|
if tonumber(cv[i]) < tonumber(mv[i]) then
|
||||||
end
|
if printMessage then
|
||||||
|
return print(msg)
|
||||||
|
end
|
||||||
|
|
||||||
return false, msg
|
return false, msg
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user