refactor: simplify module loading mechanism
This commit is contained in:
+1
-24
@@ -11,30 +11,7 @@ utils.wakatime_stats = require("utils.wakatime_stats")
|
||||
utils.music_stats = require("utils.music_stats")
|
||||
utils.highlight = require("utils.highlight")
|
||||
utils.blinky = require("utils.blinky")
|
||||
|
||||
-- Function to iterate over files in the directory and load them dynamically
|
||||
local function read_utils_dir()
|
||||
-- Getting the root path for the current module directory
|
||||
local dir_path = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h")
|
||||
|
||||
-- Open the directory
|
||||
local files = vim.fn.readdir(dir_path)
|
||||
|
||||
for _, file in ipairs(files) do
|
||||
-- Skip init.lua
|
||||
if file ~= "init.lua" and file:match(".*%.lua$") then
|
||||
-- Get the module name without the .lua extension
|
||||
local module_name = file:sub(1, -5)
|
||||
-- Load the module if not already explicitly set
|
||||
if not utils[module_name] then
|
||||
utils[module_name] = require("utils." .. module_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Read the directory to load any additional modules
|
||||
read_utils_dir()
|
||||
utils.indentor = require("utils.indentor")
|
||||
|
||||
---@alias UtilsModule table<string, any>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user