2022-11-22 21:28:08 +01:00
|
|
|
local Config = require("lazy.core.config")
|
2022-11-27 11:02:28 +01:00
|
|
|
local Runner = require("lazy.manage.runner")
|
2022-11-25 22:48:17 +01:00
|
|
|
local Plugin = require("lazy.core.plugin")
|
2022-11-20 22:33:47 +01:00
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
2022-11-28 11:04:32 +01:00
|
|
|
---@class ManagerOpts
|
|
|
|
---@field wait? boolean
|
|
|
|
---@field clear? boolean
|
2022-11-30 23:07:09 +01:00
|
|
|
---@field show? boolean
|
2022-11-29 10:30:14 +01:00
|
|
|
---@field mode? string
|
2022-11-29 10:56:17 +01:00
|
|
|
---@field plugins? LazyPlugin[]
|
2022-12-05 20:36:49 +01:00
|
|
|
---@field concurrency? number
|
2022-11-20 22:33:47 +01:00
|
|
|
|
2022-11-28 11:04:32 +01:00
|
|
|
---@param ropts RunnerOpts
|
2022-11-20 22:33:47 +01:00
|
|
|
---@param opts? ManagerOpts
|
2022-11-28 11:04:32 +01:00
|
|
|
function M.run(ropts, opts)
|
2022-11-20 22:34:55 +01:00
|
|
|
opts = opts or {}
|
|
|
|
|
2022-11-29 10:56:17 +01:00
|
|
|
if opts.plugins then
|
|
|
|
ropts.plugins = opts.plugins
|
|
|
|
end
|
|
|
|
|
2022-12-05 20:36:49 +01:00
|
|
|
ropts.concurrency = ropts.concurrency or opts.concurrency or Config.options.concurrency
|
2022-11-30 23:14:31 +01:00
|
|
|
|
2022-11-20 22:34:55 +01:00
|
|
|
if opts.clear then
|
|
|
|
M.clear()
|
|
|
|
end
|
|
|
|
|
2022-11-30 23:07:09 +01:00
|
|
|
if opts.show ~= false then
|
2022-11-29 07:56:29 +01:00
|
|
|
vim.schedule(function()
|
2022-11-29 10:30:14 +01:00
|
|
|
require("lazy.view").show(opts.mode)
|
2022-11-29 07:56:29 +01:00
|
|
|
end)
|
2022-11-20 22:34:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
---@type Runner
|
2022-11-28 11:04:32 +01:00
|
|
|
local runner = Runner.new(ropts)
|
|
|
|
runner:start()
|
2022-11-20 22:34:55 +01:00
|
|
|
|
|
|
|
vim.cmd([[do User LazyRender]])
|
|
|
|
|
2022-11-28 11:04:32 +01:00
|
|
|
-- wait for post-install to finish
|
2022-11-20 22:34:55 +01:00
|
|
|
runner:wait(function()
|
2022-11-28 11:04:32 +01:00
|
|
|
vim.cmd([[do User LazyRender]])
|
2022-11-30 23:06:26 +01:00
|
|
|
Plugin.update_state()
|
2022-12-13 10:07:36 +01:00
|
|
|
require("lazy.manage.checker").fast_check()
|
2022-11-20 22:34:55 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
if opts.wait then
|
|
|
|
runner:wait()
|
|
|
|
end
|
2022-11-29 00:15:13 +01:00
|
|
|
return runner
|
2022-11-20 22:33:47 +01:00
|
|
|
end
|
|
|
|
|
2022-12-21 22:27:36 +01:00
|
|
|
---@generic O: ManagerOpts
|
|
|
|
---@param opts? O
|
|
|
|
---@param defaults? ManagerOpts
|
|
|
|
---@return O
|
|
|
|
function M.opts(opts, defaults)
|
|
|
|
return vim.tbl_deep_extend("force", { clear = true }, defaults or {}, opts or {})
|
|
|
|
end
|
|
|
|
|
2022-11-20 22:33:47 +01:00
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.install(opts)
|
2022-12-21 22:27:36 +01:00
|
|
|
opts = M.opts(opts, { mode = "install" })
|
2022-12-05 20:36:49 +01:00
|
|
|
return M.run({
|
2022-11-28 22:03:44 +01:00
|
|
|
pipeline = {
|
|
|
|
"git.clone",
|
|
|
|
"git.checkout",
|
|
|
|
"plugin.docs",
|
|
|
|
"wait",
|
2022-12-01 07:43:28 +01:00
|
|
|
"plugin.build",
|
2022-11-28 22:03:44 +01:00
|
|
|
},
|
2022-11-28 11:04:32 +01:00
|
|
|
plugins = function(plugin)
|
2022-12-06 11:12:54 +01:00
|
|
|
return plugin.url and not plugin._.installed
|
2022-11-28 11:04:32 +01:00
|
|
|
end,
|
2022-12-15 14:07:37 +01:00
|
|
|
}, opts):wait(function()
|
|
|
|
require("lazy.help").update()
|
|
|
|
end)
|
2022-11-20 22:33:47 +01:00
|
|
|
end
|
|
|
|
|
2022-11-29 00:15:13 +01:00
|
|
|
---@param opts? ManagerOpts|{lockfile?:boolean}
|
2022-11-20 22:33:47 +01:00
|
|
|
function M.update(opts)
|
2022-12-21 22:27:36 +01:00
|
|
|
opts = M.opts(opts, { mode = "update" })
|
2022-12-05 20:36:49 +01:00
|
|
|
return M.run({
|
2022-11-28 22:03:44 +01:00
|
|
|
pipeline = {
|
|
|
|
"git.branch",
|
|
|
|
"git.fetch",
|
2022-11-29 00:15:13 +01:00
|
|
|
{ "git.checkout", lockfile = opts.lockfile },
|
2022-11-28 22:03:44 +01:00
|
|
|
"plugin.docs",
|
|
|
|
"wait",
|
2022-12-01 07:43:28 +01:00
|
|
|
"plugin.build",
|
2022-11-28 22:03:44 +01:00
|
|
|
{ "git.log", updated = true },
|
|
|
|
},
|
2022-11-28 11:04:32 +01:00
|
|
|
plugins = function(plugin)
|
2022-12-06 11:12:54 +01:00
|
|
|
return plugin.url and plugin._.installed
|
2022-11-28 11:04:32 +01:00
|
|
|
end,
|
2022-11-29 00:15:13 +01:00
|
|
|
}, opts):wait(function()
|
|
|
|
require("lazy.manage.lock").update()
|
2022-12-15 14:07:37 +01:00
|
|
|
require("lazy.help").update()
|
2022-11-29 00:15:13 +01:00
|
|
|
end)
|
2022-11-20 22:33:47 +01:00
|
|
|
end
|
2022-12-21 22:27:36 +01:00
|
|
|
--
|
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.restore(opts)
|
|
|
|
opts = M.opts(opts, { mode = "restore", lockfile = true })
|
|
|
|
return M.update(opts)
|
|
|
|
end
|
2022-11-20 22:33:47 +01:00
|
|
|
|
2022-12-05 20:36:49 +01:00
|
|
|
---@param opts? ManagerOpts
|
2022-11-29 08:23:23 +01:00
|
|
|
function M.check(opts)
|
2022-12-21 22:27:36 +01:00
|
|
|
opts = M.opts(opts, { mode = "check" })
|
2022-11-29 08:23:23 +01:00
|
|
|
opts = opts or {}
|
2022-12-05 20:36:49 +01:00
|
|
|
return M.run({
|
2022-11-29 08:23:23 +01:00
|
|
|
pipeline = {
|
|
|
|
"git.fetch",
|
|
|
|
"wait",
|
|
|
|
{ "git.log", check = true },
|
|
|
|
},
|
|
|
|
plugins = function(plugin)
|
2022-12-06 11:12:54 +01:00
|
|
|
return plugin.url and plugin._.installed
|
2022-11-29 08:23:23 +01:00
|
|
|
end,
|
|
|
|
}, opts)
|
|
|
|
end
|
|
|
|
|
2022-11-22 21:12:50 +01:00
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.log(opts)
|
2022-12-21 22:27:36 +01:00
|
|
|
opts = M.opts(opts, { mode = "log" })
|
2022-12-05 20:36:49 +01:00
|
|
|
return M.run({
|
2022-11-28 11:04:32 +01:00
|
|
|
pipeline = { "git.log" },
|
|
|
|
plugins = function(plugin)
|
2022-12-06 11:12:54 +01:00
|
|
|
return plugin.url and plugin._.installed
|
2022-11-28 11:04:32 +01:00
|
|
|
end,
|
|
|
|
}, opts)
|
2022-11-23 16:12:43 +01:00
|
|
|
end
|
|
|
|
|
2022-12-21 22:27:36 +01:00
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.sync(opts)
|
|
|
|
opts = M.opts(opts, { mode = "sync" })
|
|
|
|
if opts.clear then
|
|
|
|
M.clear()
|
|
|
|
opts.clear = false
|
|
|
|
end
|
|
|
|
M.clean(opts)
|
|
|
|
M.install(opts)
|
|
|
|
M.update(opts)
|
|
|
|
end
|
|
|
|
|
2022-11-20 22:33:47 +01:00
|
|
|
---@param opts? ManagerOpts
|
|
|
|
function M.clean(opts)
|
2022-12-21 22:27:36 +01:00
|
|
|
opts = M.opts(opts, { mode = "clean" })
|
2022-12-05 20:36:49 +01:00
|
|
|
return M.run({
|
2022-11-28 22:03:44 +01:00
|
|
|
pipeline = { "fs.clean" },
|
2022-11-28 11:04:32 +01:00
|
|
|
plugins = Config.to_clean,
|
|
|
|
}, opts)
|
2022-11-20 22:33:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.clear()
|
2022-12-03 00:12:49 +01:00
|
|
|
Plugin.load()
|
2022-11-21 00:27:28 +01:00
|
|
|
for _, plugin in pairs(Config.plugins) do
|
2022-12-05 20:36:49 +01:00
|
|
|
plugin._.has_updates = nil
|
2022-11-28 11:19:50 +01:00
|
|
|
plugin._.updated = nil
|
2022-11-29 00:15:13 +01:00
|
|
|
plugin._.cloned = nil
|
|
|
|
plugin._.dirty = nil
|
2022-11-20 22:34:55 +01:00
|
|
|
-- clear finished tasks
|
2022-11-28 11:19:50 +01:00
|
|
|
if plugin._.tasks then
|
2022-11-20 23:25:56 +01:00
|
|
|
---@param task LazyTask
|
2022-11-28 11:19:50 +01:00
|
|
|
plugin._.tasks = vim.tbl_filter(function(task)
|
2022-11-28 11:04:32 +01:00
|
|
|
return task:is_running()
|
2022-11-28 11:19:50 +01:00
|
|
|
end, plugin._.tasks)
|
2022-11-20 22:34:55 +01:00
|
|
|
end
|
|
|
|
end
|
2022-11-23 16:12:43 +01:00
|
|
|
vim.cmd([[do User LazyRender]])
|
2022-11-20 22:33:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|