feat(pkg): utils to get rock to url mappings

This commit is contained in:
Folke Lemaitre 2024-06-25 20:38:50 +02:00
parent 25981e1f39
commit be74a8a535
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 10 additions and 11 deletions

View File

@ -3,23 +3,22 @@ local M = {}
---@type table<string, string> ---@type table<string, string>
local mapping = nil local mapping = nil
local function _load() local function load()
if mapping then if not mapping then
return mapping = {}
end ---@type {name:string, url:string, version:string}[]
mapping = {} local gen = require("lazy.community._generated")
---@type {name:string, url:string, version:string}[] for _, rock in ipairs(gen) do
local gen = require("lazy.community._generated") mapping[rock.name] = rock.url
for _, rock in ipairs(gen) do end
mapping[rock.name] = rock.url
end end
return mapping
end end
---@param rock string ---@param rock string
---@return string? ---@return string?
function M.get_url(rock) function M.get_url(rock)
_load() return load()[rock]
return mapping[rock]
end end
return M return M