lazy.nvim/lua/lazy/manage/task/plugin.lua

49 lines
1.2 KiB
Lua
Raw Normal View History

2022-11-28 18:04:32 +08:00
local Util = require("lazy.util")
local Loader = require("lazy.core.loader")
---@type table<string, LazyTaskDef>
local M = {}
M.build = {
2022-11-28 20:11:20 +08:00
skip = function(plugin)
return not (plugin._.dirty and plugin.build)
2022-11-28 18:04:32 +08:00
end,
run = function(self)
Loader.load(self.plugin, { task = "build" })
-- we need to source its plugin files before startup,
-- to make sure the build command has everything available
Loader.source_runtime(self.plugin.dir, "plugin")
2022-11-28 18:04:32 +08:00
local build = self.plugin.build
if build then
if type(build) == "string" and build:sub(1, 1) == ":" then
local cmd = vim.api.nvim_parse_cmd(build:sub(2), {})
2022-11-28 18:04:32 +08:00
self.output = vim.api.nvim_cmd(cmd, { output = true })
elseif type(build) == "function" then
build()
2022-11-28 18:04:32 +08:00
else
local args = vim.split(build, "%s+")
2022-11-28 18:04:32 +08:00
return self:spawn(table.remove(args, 1), {
args = args,
cwd = self.plugin.dir,
})
end
end
end,
}
M.docs = {
2022-11-28 20:11:20 +08:00
skip = function(plugin)
return not plugin._.dirty
2022-11-28 18:04:32 +08:00
end,
run = function(self)
local docs = self.plugin.dir .. "/doc/"
if Util.file_exists(docs) then
self.output = vim.api.nvim_cmd({ cmd = "helptags", args = { docs } }, { output = true })
end
end,
}
return M