local M = require('module'):new() local package_manager = require('plugin/vim_plug') local file_exists = require('lib/file_exists') local has_command = require('lib/has_command') function M:initialize() self.path = self.config.path or "~/.config/nvim/plugins/" self.auto_install = self.config.auto_install or true self.auto_cleanup = self.config.auto_cleanup or true self.plugins = {} self.keymap = nukevim.modules:get('keymap') end function M:register() for idx, plugin in pairs(self.config.plugins) do if (plugin.enable == nil or plugin.enable == true) then self:add(plugin.name, plugin.config or nil, plugin.keys or nil, plugin.requires or nil) end end end function M:commit() package_manager:initialize(self.path) package_manager:enter() for idx, plugin in pairs(self.plugins) do package_manager:add(plugin.name, plugin.config or nil) end package_manager:exit() -- Check if any plugins have lua modules, if so register them for idx, plugin in pairs(self.plugins) do if (file_exists(vim.env.HOME .. '/.config/nvim/lua/plugin/' .. plugin.name:gsub('%.', '-') .. '.lua')) then local plugin_module = require('plugin/' .. plugin.name:gsub('%.', '-')):new() plugin_module:configure(plugin.config) nukevim.modules:addInstance(plugin.name, plugin_module) end end end function M:boot() if (self.auto_install and package_manager:hasPendingPackages()) then package_manager:install() end if (self.auto_cleanup) then package_manager:cleanup() end end function M:add(name, config, keys, requires) if (requires ~= nil) then for i=1,#requires do if (not has_command(requires[i])) then return end end end table.insert(self.plugins, { name = name, config = config }) if (keys ~= nil) then for idx, key in ipairs(keys) do self.keymap:add(key) end end end function M:has(name) for idx, plugin in pairs(self.plugins) do if (plugin.name == name) then return true end end return false end function M:install() package_manager:install() end function M:cleanup() package_manager:cleanup() end return M