Skip to content

Commit

Permalink
export all modules
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Apr 23, 2024
1 parent 02af5e5 commit c5b45c1
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions xmake/plugins/show/lists/apis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import("core.project.project")
import("core.project.option")
import("core.package.package")
import("core.sandbox.sandbox")
import("core.sandbox.module")
import("core.tool.toolchain")
import(".showlist")

Expand Down Expand Up @@ -224,22 +225,25 @@ end
-- get import module apis
function import_module_apis()
local result = {}
local modulefiles = os.files(path.join(os.programdir(), "modules/**.lua|private/**.lua|core/tools/**.lua|detect/tools/**.lua"))
if modulefiles then
for _, modulefile in ipairs(modulefiles) do
local modulename = path.relative(modulefile, path.join(os.programdir(), "modules"))
if path.filename(modulename) == "main.lua" then
modulename = path.directory(modulename)
end
modulename = modulename:gsub("/", "."):gsub("%.lua", "")
local instance = import(modulename, {try = true, anonymous = true})
if _is_callable(instance) then
table.insert(result, modulename)
elseif type(instance) == "table" then
for k, v in pairs(instance) do
print(k)
if not k:startswith("_") and type(v) == "function" then
table.insert(result, modulename .. "." .. k)
local moduledirs = module.directories()
for _, moduledir in ipairs(moduledirs) do
moduledir = path.absolute(moduledir)
local modulefiles = os.files(path.join(moduledir, "**.lua|private/**.lua|core/tools/**.lua|detect/tools/**.lua"))
if modulefiles then
for _, modulefile in ipairs(modulefiles) do
local modulename = path.relative(modulefile, moduledir)
if path.filename(modulename) == "main.lua" then
modulename = path.directory(modulename)
end
modulename = modulename:gsub("/", "."):gsub("%.lua", "")
local instance = import(modulename, {try = true, anonymous = true})
if _is_callable(instance) then
table.insert(result, modulename)
elseif type(instance) == "table" then
for k, v in pairs(instance) do
if not k:startswith("_") and type(v) == "function" then
table.insert(result, modulename .. "." .. k)
end
end
end
end
Expand Down

0 comments on commit c5b45c1

Please sign in to comment.