From e33f4763fcbebfa509c5cc725d5ecb92f3dfc5cb Mon Sep 17 00:00:00 2001 From: garret Date: Sun, 20 Nov 2022 06:48:33 +0000 Subject: feedmaker: actual feed-making capabilities --- make-feed.lua | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'make-feed.lua') diff --git a/make-feed.lua b/make-feed.lua index 639e74f..fd132a3 100755 --- a/make-feed.lua +++ b/make-feed.lua @@ -100,14 +100,55 @@ local function get_metadata(file) return meta end +local function clean_depctrl(depctrl) + local required = {} + for _, mod in ipairs(depctrl) do + if type(mod[1]) == "string" then + mod["moduleName"] = mod[1] + mod[1] = nil + else + mod[1]["moduleName"] = mod[1][1] + mod[1][1] = nil + end + table.insert(required, mod) + end + return required +end + +local function make_feed(macros) + local feed = { + dependencyControlFeedFormatVersion = "0.3.0", + name = config.name, + description = config.description, + knownFeeds = {}, + baseUrl = config.baseUrl, + url = config.url, + maintainer = config.maintainer, + fileBaseUrl = config.fileBaseUrl, + macros = {} + } + for _, script in ipairs(macros) do + local macro = {url = config.scriptUrl, author = script.author, name = script.name, description = script.description, channels = {}} + local channel_info = {version = script.version, released = script.release, default = true, files = {}} + channel_info.requiredModules = clean_depctrl(script.depctrl) + channel_info.files[".lua"] = {name = ".lua", url = config.fileUrl, sha1 = script.sha1} + macro.channels[config.channel] = channel_info + feed.macros[script.namespace] = macro + end + return json.encode(feed) +end + local function main() local files = get_files(args.macro_dir) - print(inspect(files)) local meta = {} for _, file in ipairs(files) do table.insert(meta, get_metadata(file)) end - print(inspect(meta)) + local feed = make_feed(meta) + + local out = output_writer(args.output) + out:write(feed) + out:close() end main() -- cgit v1.2.3-70-g09d2