From 0bbc8be520ffdfb4b603014d00666086fdf33660 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Sun, 16 Feb 2025 14:34:58 +0100 Subject: [PATCH] Small fix --- tools/generate-config.lua | 56 +++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/tools/generate-config.lua b/tools/generate-config.lua index d06d31e..b92db64 100644 --- a/tools/generate-config.lua +++ b/tools/generate-config.lua @@ -1,27 +1,49 @@ +local function serialize(t, indent) + indent = indent or "" + local result = "{\n" + for k, v in pairs(t) do + result = result .. indent .. " " + + if type(k) == "string" then + result = result .. "[\"" .. k .. "\"] = " + else + result = result .. "[" .. k .. "] = " + end + + if type(v) == "table" then + result = result .. serialize(v, indent .. " ") + elseif type(v) == "string" then + result = result .. "\"" .. v .. "\"" + else + result = result .. tostring(v) + end + result = result .. ",\n" + end + return result .. indent .. "}" +end + local function scanDir(dir) local files = {} - for file in io.popen('find "'..dir..'" -type f -name "*.lua"'):lines() do - local name = file:match("([^/]+)%.lua$") - if name then - files[file] = { - name = name, - path = file:gsub("^src", ""), - } + for _, file in ipairs(fs.list(dir)) do + local path = fs.combine(dir, file) + if fs.isDir(path) then + for subFile, content in pairs(scanDir(path)) do + files[fs.combine(file, subFile)] = content + end + else + local f = fs.open(path, "r") + files[file] = f.readAll() + f.close() end end return files end +local sourceFiles = scanDir("src") local config = { - repo = "https://raw.githubusercontent.com/Pyroxenium/Basalt2/master", - required = { - ["src/init.lua"] = "/init.lua", - ["src/render.lua"] = "/render.lua", - }, - elements = scanDir("src/elements"), - plugins = scanDir("src/plugins") + files = sourceFiles, } -local f = io.open("config.lua", "w") -f:write("return " .. textutils.serialize(config)) -f:close() +local f = fs.open("config.lua", "w") +f.write("return " .. serialize(config)) +f.close()