2021-07-18 20:08:14 +02:00
|
|
|
local plugin_loader = {}
|
|
|
|
|
2021-09-16 09:58:32 +02:00
|
|
|
local utils = require "utils"
|
|
|
|
local Log = require "core.log"
|
|
|
|
-- we need to reuse this outside of init()
|
|
|
|
local compile_path = get_config_dir() .. "/plugin/packer_compiled.lua"
|
|
|
|
|
2021-09-13 11:28:15 +02:00
|
|
|
function plugin_loader:init(opts)
|
|
|
|
opts = opts or {}
|
|
|
|
|
2021-09-13 17:22:27 +02:00
|
|
|
local install_path = opts.install_path or vim.fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim"
|
2021-09-13 11:28:15 +02:00
|
|
|
local package_root = opts.package_root or vim.fn.stdpath "data" .. "/site/pack"
|
|
|
|
|
2021-09-13 17:22:27 +02:00
|
|
|
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
|
|
|
|
vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }
|
2021-08-26 20:32:16 +02:00
|
|
|
vim.cmd "packadd packer.nvim"
|
2021-07-18 20:08:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local packer_ok, packer = pcall(require, "packer")
|
|
|
|
if not packer_ok then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
packer.init {
|
2021-09-13 11:28:15 +02:00
|
|
|
package_root = package_root,
|
|
|
|
compile_path = compile_path,
|
2021-07-18 20:08:14 +02:00
|
|
|
git = { clone_timeout = 300 },
|
|
|
|
display = {
|
|
|
|
open_fn = function()
|
2021-09-13 11:28:15 +02:00
|
|
|
return require("packer.util").float { border = "rounded" }
|
2021-07-18 20:08:14 +02:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
self.packer = packer
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
2021-09-16 09:58:32 +02:00
|
|
|
function plugin_loader:cache_clear()
|
|
|
|
if vim.fn.delete(compile_path) == 0 then
|
|
|
|
Log:debug "deleted packer_compiled.lua"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function plugin_loader:cache_reset()
|
|
|
|
self.cache_clear()
|
|
|
|
require("packer").compile()
|
|
|
|
if utils.is_file(compile_path) then
|
|
|
|
Log:debug "generated packer_compiled.lua"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-18 20:08:14 +02:00
|
|
|
function plugin_loader:load(configurations)
|
|
|
|
return self.packer.startup(function(use)
|
|
|
|
for _, plugins in ipairs(configurations) do
|
|
|
|
for _, plugin in ipairs(plugins) do
|
|
|
|
use(plugin)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2021-09-13 11:28:15 +02:00
|
|
|
return plugin_loader
|