2022-11-22 20:28:08 +00:00
|
|
|
local Config = require("lazy.core.config")
|
2022-11-27 10:02:28 +00:00
|
|
|
local Runner = require("lazy.manage.runner")
|
2022-11-25 21:48:17 +00:00
|
|
|
local Plugin = require("lazy.core.plugin")
|
2022-11-20 21:33:47 +00:00
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
2022-11-28 10:04:32 +00:00
|
|
|
---@class ManagerOpts
|
|
|
|
---@field wait? boolean
|
|
|
|
---@field clear? boolean
|
|
|
|
---@field interactive? boolean
|
2022-11-20 21:33:47 +00:00
|
|
|
|
2022-11-28 10:04:32 +00:00
|
|
|
---@param ropts RunnerOpts
|
2022-11-20 21:33:47 +00:00
|
|
|
---@param opts? ManagerOpts
|
2022-11-28 10:04:32 +00:00
|
|
|
function M.run(ropts, opts)
|
2022-11-20 21:34:55 +00:00
|
|
|
opts = opts or {}
|
2022-11-28 10:04:32 +00:00
|
|
|
if opts.interactive == nil then
|
|
|
|
opts.interactive = Config.options.interactive
|
|
|
|
end
|
2022-11-20 21:34:55 +00:00
|
|
|
|
|
|
|
if opts.clear then
|
|
|
|
M.clear()
|
|
|
|
end
|
|
|
|
|
2022-11-28 10:04:32 +00:00
|
|
|
if opts.interactive then
|
2022-11-20 21:34:55 +00:00
|
|
|
require("lazy.view").show()
|
|
|
|
end
|
|
|
|
|
|
|
|
---@type Runner
|
2022-11-28 10:04:32 +00:00
|
|
|
local runner = Runner.new(ropts)
|
|
|
|
runner:start()
|
2022-11-20 21:34:55 +00:00
|
|
|
|
|
|
|
vim.cmd([[do User LazyRender]])
|
|
|
|
|
2022-11-28 10:04:32 +00:00
|
|
|
-- wait for post-install to finish
|
2022-11-20 21:34:55 +00:00
|
|
|
runner:wait(function()
|
2022-11-28 10:04:32 +00:00
|
|
|
vim.cmd([[do User LazyRender]])
|
2022-11-20 21:34:55 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
if opts.wait then
|
|
|
|
runner:wait()
|
|
|
|
end
|
2022-11-20 21:33:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.install(opts)
|
2022-11-28 10:04:32 +00:00
|
|
|
M.run({
|
2022-11-28 21:03:44 +00:00
|
|
|
pipeline = {
|
|
|
|
"fs.symlink",
|
|
|
|
"git.clone",
|
|
|
|
"git.checkout",
|
|
|
|
"plugin.docs",
|
|
|
|
"wait",
|
|
|
|
"plugin.run",
|
|
|
|
},
|
2022-11-28 10:04:32 +00:00
|
|
|
plugins = function(plugin)
|
2022-11-28 10:19:50 +00:00
|
|
|
return plugin.uri and not plugin._.installed
|
2022-11-28 10:04:32 +00:00
|
|
|
end,
|
|
|
|
}, opts)
|
2022-11-20 21:33:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.update(opts)
|
2022-11-28 10:04:32 +00:00
|
|
|
M.run({
|
2022-11-28 21:03:44 +00:00
|
|
|
pipeline = {
|
|
|
|
"fs.symlink",
|
|
|
|
"git.branch",
|
|
|
|
"git.fetch",
|
|
|
|
"git.checkout",
|
|
|
|
"plugin.docs",
|
|
|
|
"plugin.run",
|
|
|
|
"wait",
|
|
|
|
{ "git.log", updated = true },
|
|
|
|
},
|
2022-11-28 10:04:32 +00:00
|
|
|
plugins = function(plugin)
|
2022-11-28 10:19:50 +00:00
|
|
|
return plugin.uri and plugin._.installed
|
2022-11-28 10:04:32 +00:00
|
|
|
end,
|
|
|
|
}, opts)
|
2022-11-20 21:33:47 +00:00
|
|
|
end
|
|
|
|
|
2022-11-22 20:12:50 +00:00
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.log(opts)
|
2022-11-28 10:04:32 +00:00
|
|
|
M.run({
|
|
|
|
pipeline = { "git.log" },
|
|
|
|
plugins = function(plugin)
|
2022-11-28 10:19:50 +00:00
|
|
|
return plugin.uri and plugin._.installed
|
2022-11-28 10:04:32 +00:00
|
|
|
end,
|
|
|
|
}, opts)
|
2022-11-23 15:12:43 +00:00
|
|
|
end
|
|
|
|
|
2022-11-20 21:33:47 +00:00
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.clean(opts)
|
2022-11-25 21:48:17 +00:00
|
|
|
Plugin.update_state(true)
|
2022-11-28 10:04:32 +00:00
|
|
|
M.run({
|
2022-11-28 21:03:44 +00:00
|
|
|
pipeline = { "fs.clean" },
|
2022-11-28 10:04:32 +00:00
|
|
|
plugins = Config.to_clean,
|
|
|
|
}, opts)
|
2022-11-20 21:33:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.clear()
|
2022-11-20 23:27:28 +00:00
|
|
|
for _, plugin in pairs(Config.plugins) do
|
2022-11-23 15:12:43 +00:00
|
|
|
-- clear updated status
|
2022-11-28 10:19:50 +00:00
|
|
|
plugin._.updated = nil
|
2022-11-20 21:34:55 +00:00
|
|
|
-- clear finished tasks
|
2022-11-28 10:19:50 +00:00
|
|
|
if plugin._.tasks then
|
2022-11-20 22:25:56 +00:00
|
|
|
---@param task LazyTask
|
2022-11-28 10:19:50 +00:00
|
|
|
plugin._.tasks = vim.tbl_filter(function(task)
|
2022-11-28 10:04:32 +00:00
|
|
|
return task:is_running()
|
2022-11-28 10:19:50 +00:00
|
|
|
end, plugin._.tasks)
|
2022-11-20 21:34:55 +00:00
|
|
|
end
|
|
|
|
end
|
2022-11-23 15:12:43 +00:00
|
|
|
vim.cmd([[do User LazyRender]])
|
2022-11-20 21:33:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|