diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2023-11-27 10:42:44 -0500 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2023-11-27 10:42:44 -0500 |
commit | fd31dcacfd2be3ff9f4cb45263ea3ee2562af00d (patch) | |
tree | e8963bd380aef44fdb43af98e63b410b2a446de8 | |
parent | 734b3e6b4e26ae39f3bb7f8977e48fa35faedaf3 (diff) | |
download | lite-xl-plugin-manager-fd31dcacfd2be3ff9f4cb45263ea3ee2562af00d.tar.gz lite-xl-plugin-manager-fd31dcacfd2be3ff9f4cb45263ea3ee2562af00d.zip |
Allowed for generation for repos that are just init.lua by guessing the id better.
-rw-r--r-- | src/lpm.lua | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/lpm.lua b/src/lpm.lua index 40a4a16..cbf1401 100644 --- a/src/lpm.lua +++ b/src/lpm.lua @@ -373,6 +373,7 @@ function common.sort(t, f) table.sort(t, f) return t end function common.write(path, contents) local f, err = io.open(path, "wb") if not f then error("can't write to " .. path .. ": " .. err) end f:write(contents) f:flush() f:close() end function common.read(path) local f, err = io.open(path, "rb") if not f then error("can't read from " .. path .. ": " .. err) end return f:read("*all") end function common.uniq(l) local t = {} local k = {} for i,v in ipairs(l) do if not k[v] then table.insert(t, v) k[v] = true end end return t end +function common.delete(h, d) local t = {} for k,v in pairs(h) do if k ~= d then t[k] = v end end return t end function common.split(splitter, str) local o = 1 local res = {} @@ -1095,15 +1096,26 @@ function Repository:generate_manifest(repo_id) if file:find("%.lua$") then local filename = common.basename(file):gsub("%.lua$", "") local name = filename - if repo_id and name == "init" then name = repo_id end + if name == "init" then name = repo_id or common.basename(self.remote) end if name ~= "init" then local type = folder == "colors" and "color" or (folder == "libraries" and "library" or "plugin") local addon = { description = nil, id = name:lower():gsub("[^a-z0-9%-_]", ""), name = name, mod_version = LATEST_MOD_VERSION, version = "0.1", path = (filename ~= "init" and (addon_dir .. PATHSEP .. file) or nil), type = type } for line in io.lines(path .. PATHSEP .. addon_dir .. PATHSEP .. file) do local _, _, mod_version = line:find("%-%-.*mod%-version:%s*(%w+)") if mod_version then addon.mod_version = mod_version end - local _, _, required_addon = line:find("require [\"']plugins.([%w_-]+)") - if required_addon and not CORE_PLUGINS[required_addon] then if required_addon ~= addon.id then if not addon.dependencies then addon.dependencies = {} end addon.dependencies[required_addon] = ">=0.1" end end + local _, _, required_addon = line:find("require [\"']plugins%.([%w_-]+)") + if required_addon and not CORE_PLUGINS[required_addon] then + if required_addon ~= addon.id then + if not addon.dependencies then addon.dependencies = {} end + addon.dependencies[required_addon] = ">=0.1" + end + end + local _, _, name_override = line:find("config%.plugins%.([%w_-]+)%s*=%s*common%.merge") + if not repo_id and name_override then + addon.name = name_override + addon.id = name_override:lower():gsub("[^a-z0-9%-_]", "") + addon.dependencies = common.delete(addon.dependencies, addon.id) + end end if addon_map[addon.id] then addon = common.merge(addon, addon_map[addon.id]) |