From 59b1f734e70327796130e20f16e2b6b9cac87543 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Tue, 18 Feb 2025 19:40:30 +0100 Subject: [PATCH] Fix --- src/elementManager.lua | 31 +++++++++++++++++++++++++++++++ src/main.lua | 6 +++++- tools/bundler.lua | 33 +++++++++++++++++++++++++++------ 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/elementManager.lua b/src/elementManager.lua index b35cc6a..7c88dcd 100644 --- a/src/elementManager.lua +++ b/src/elementManager.lua @@ -58,6 +58,37 @@ if fs.exists(pluginsDirectory) then end end +if(minified)then + if(minified_elementDirectory==nil)then + error("Unable to find minified_elementDirectory please report this bug to our discord.") + end + for name,v in pairs(minfied_elementDirectory)do + ElementManager._elements[name:gsub(".lua", "")] = { + class = nil, + plugins = {}, + loaded = false + } + end + if(minified_pluginDirectory==nil)then + error("Unable to find minified_pluginDirectory please report this bug to our discord.") + end + for name,_ in pairs(minified_pluginDirectory)do + local plugin = require(fs.combine("plugins", name)) + if type(plugin) == "table" then + for k,v in pairs(plugin) do + if(k ~= "API")then + if(ElementManager._plugins[k]==nil)then + ElementManager._plugins[k] = {} + end + table.insert(ElementManager._plugins[k], v) + else + ElementManager._APIs[k] = v + end + end + end + end +end + --- Loads an element by name. This will load the element and apply any plugins to it. --- @param name string The name of the element to load --- @usage ElementManager.loadElement("Button") diff --git a/src/main.lua b/src/main.lua index 7f076ab..faf6122 100644 --- a/src/main.lua +++ b/src/main.lua @@ -22,7 +22,11 @@ basalt._events = {} basalt._schedule = {} basalt._plugins = {} basalt.LOGGER = require("log") -basalt.path = fs.getDir(select(2, ...)) +if(minified)then + basalt.path = fs.getDir(shell.getRunningProgram()) +else + basalt.path = fs.getDir(select(2, ...)) +end local mainFrame = nil local updaterActive = false diff --git a/tools/bundler.lua b/tools/bundler.lua index c8ba220..cd517fe 100644 --- a/tools/bundler.lua +++ b/tools/bundler.lua @@ -18,34 +18,55 @@ local function bundle() local output = { 'local minified = true\n', + 'local minified_elementDirectory = {}\n', + 'local minified_pluginDirectory = {}\n', 'local project = {}\n', 'local baseRequire = require\n', 'require = function(path) return project[path..".lua"] or baseRequire(path) end\n' } - + + for _, file in ipairs(files) do + + local elementName = file.path:match("^elements/(.+)%.lua$") + if elementName then + table.insert(output, string.format( + 'minified_elementDirectory["%s"] = {}\n', + elementName + )) + end + + local pluginName = file.path:match("^plugins/(.+)%.lua$") + if pluginName then + table.insert(output, string.format( + 'minified_pluginDirectory["%s"] = {}\n', + pluginName + )) + end + end + for _, file in ipairs(files) do local f = io.open(file.fullPath, "r") local content = f:read("*all") f:close() - + local success, minified = minify(content) if not success then print("Failed to minify " .. file.path) os.exit(1) end - + table.insert(output, string.format( 'project["%s"] = function(...) %s end\n', file.path, minified )) end - + table.insert(output, 'return project["main.lua"]()') - + local out = io.open("release/basalt.lua", "w") out:write(table.concat(output)) out:close() - + print("Successfully bundled files:") for _, file in ipairs(files) do print("- " .. file.path)