feat(version): version and dependency checks

This commit is contained in:
Linden
2022-02-28 00:49:24 +00:00
parent d3ef7d5018
commit 478cd93e97
2 changed files with 36 additions and 15 deletions

View File

@@ -0,0 +1,36 @@
function lib.versionCheck(repository)
SetTimeout(1000, function()
local resource = repository:sub(repository:find('/') + 1, #repository)
PerformHttpRequest(('https://api.github.com/repos/%s/releases/latest'):format(repository), function(status, response)
if status ~= 200 then return end
response = json.decode(response)
if response.prerelease then return end
local currentVersion = GetResourceMetadata(resource, 'version', 0):match('%d%.%d+%.%d+')
if not currentVersion then return end
local latestVersion = response.tag_name:match('%d%.%d+%.%d+')
if not latestVersion then return end
print(currentVersion, latestVersion)
if currentVersion >= latestVersion then return end
print(('^3An update is available for %s (current version: %s)\r\n%s^0'):format(resource, currentVersion, response.html_url))
end, 'GET')
end)
end
function lib.checkDependency(resource, minimumVersion)
local currentVersion = GetResourceMetadata(resource, 'version', 0):match('%d%.%d+%.%d+')
if currentVersion < minimumVersion then
return print(("^1%s requires version '%s' of '%s' (current version: %s)^0"):format(GetInvokingResource() or GetCurrentResourceName(), minimumVersion, resource, currentVersion))
end
return true
end
lib.versionCheck('overextended/ox_lib')

View File

@@ -1,15 +0,0 @@
CreateThread(function()
Wait(1000)
local resource = GetCurrentResourceName()
local url = GetResourceMetadata(resource, 'repository', 0)
local version = GetResourceMetadata(resource, 'version', 0)
PerformHttpRequest(('%s/master/fxmanifest.lua'):format(url:gsub('github.com', 'raw.githubusercontent.com')), function(error, response)
if error == 200 and response then
local latest = response:match('%d%.%d+%.%d+')
if version < latest then
print(('^3An update is available for pe-lualib - please download the latest release (current version: %s)\n ^3- %s^0'):format(latest, version, ('%s/archive/refs/tags/%s.zip'):format(url, latest, latest)))
end
end
end, 'GET')
end)