feat(commands): added build command to force rebuild of a plugin

This commit is contained in:
Folke Lemaitre 2023-01-01 09:41:43 +01:00
parent 205ce42cdc
commit 23c0587791
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
5 changed files with 31 additions and 4 deletions

View File

@ -489,6 +489,7 @@ Any operation can be started from the UI, with a sub command or an API function:
| Command | Lua | Description |
| ------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `:Lazy build {plugins}` | `require("lazy").build(opts)` | Rebuild a plugin |
| `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) |
| `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed |
| `:Lazy clear` | `require("lazy").clear()` | Clear finished tasks |

View File

@ -144,6 +144,17 @@ function M.log(opts)
}, opts)
end
---@param opts? ManagerOpts
function M.build(opts)
opts = M.opts(opts, { mode = "build" })
return M.run({
pipeline = { { "plugin.build", force = true } },
plugins = function()
return false
end,
}, opts)
end
---@param opts? ManagerOpts
function M.sync(opts)
opts = M.opts(opts)

View File

@ -5,7 +5,11 @@ local Loader = require("lazy.core.loader")
local M = {}
M.build = {
skip = function(plugin)
---@param opts? {force:boolean}
skip = function(plugin, opts)
if opts and opts.force then
return false
end
return not (plugin._.dirty and plugin.build)
end,
run = function(self)

View File

@ -13,6 +13,12 @@ function M.cmd(cmd, opts)
local command = M.commands[cmd] --[[@as fun(opts)]]
if command == nil then
Util.error("Invalid lazy command '" .. cmd .. "'")
elseif
ViewConfig.commands[cmd]
and ViewConfig.commands[cmd].plugins_required
and not (opts and vim.tbl_count(opts.plugins or {}) > 0)
then
return Util.error("`Lazy " .. cmd .. "` requires at least one plugin")
else
command(opts)
end
@ -44,12 +50,10 @@ M.commands = {
end,
---@param opts ManagerOpts
load = function(opts)
if not (opts and opts.plugins and #opts.plugins > 0) then
return Util.error("`Lazy load` requires at least one plugin name to load")
end
require("lazy.core.loader").load(opts.plugins, { cmd = "LazyLoad" })
end,
log = Manage.log,
build = Manage.build,
clean = Manage.clean,
install = Manage.install,
sync = Manage.sync,

View File

@ -139,6 +139,13 @@ M.commands = {
desc = "Run `:checkhealth lazy`",
id = 14,
},
build = {
desc = "Rebuild a plugin",
id = 13,
plugins = true,
plugins_required = true,
key_plugin = "b",
},
}
return M