2023-07-01 03:19:30 +08:00
|
|
|
local Config = require("lazy.core.config")
|
2023-10-09 17:25:42 +08:00
|
|
|
local Loader = require("lazy.core.loader")
|
|
|
|
local Util = require("lazy.util")
|
2022-11-28 18:04:32 +08:00
|
|
|
|
|
|
|
---@type table<string, LazyTaskDef>
|
|
|
|
local M = {}
|
|
|
|
|
2023-07-01 00:22:39 +08:00
|
|
|
---@param plugin LazyPlugin
|
|
|
|
local function get_build_file(plugin)
|
|
|
|
for _, path in ipairs({ "build.lua", "build/init.lua" }) do
|
|
|
|
path = plugin.dir .. "/" .. path
|
|
|
|
if Util.file_exists(path) then
|
|
|
|
return path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-01 14:43:28 +08:00
|
|
|
M.build = {
|
2023-01-01 16:41:43 +08:00
|
|
|
---@param opts? {force:boolean}
|
|
|
|
skip = function(plugin, opts)
|
|
|
|
if opts and opts.force then
|
|
|
|
return false
|
|
|
|
end
|
2023-07-01 00:22:39 +08:00
|
|
|
return not (plugin._.dirty and (plugin.build or get_build_file(plugin)))
|
2022-11-28 18:04:32 +08:00
|
|
|
end,
|
|
|
|
run = function(self)
|
2023-01-13 16:19:51 +08:00
|
|
|
vim.cmd([[silent! runtime plugin/rplugin.vim]])
|
|
|
|
|
2022-12-01 18:06:44 +08:00
|
|
|
Loader.load(self.plugin, { task = "build" })
|
2022-12-04 00:45:40 +08:00
|
|
|
|
2022-12-24 16:17:29 +08:00
|
|
|
local builders = self.plugin.build
|
2023-07-01 00:22:39 +08:00
|
|
|
|
2023-11-04 17:14:03 +08:00
|
|
|
-- Skip if `build` is set to `false`
|
|
|
|
if builders == false then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-07-01 00:22:39 +08:00
|
|
|
local build_file = get_build_file(self.plugin)
|
|
|
|
if build_file then
|
|
|
|
if builders then
|
2023-07-01 03:19:30 +08:00
|
|
|
if Config.options.build.warn_on_override then
|
|
|
|
Util.warn(
|
|
|
|
("Plugin **%s** provides its own build script, but you also defined a `build` command.\nThe `build.lua` file will not be used"):format(
|
|
|
|
self.plugin.name
|
|
|
|
)
|
2023-07-01 00:22:39 +08:00
|
|
|
)
|
2023-07-01 03:19:30 +08:00
|
|
|
end
|
|
|
|
else
|
|
|
|
builders = function()
|
|
|
|
Loader.source(build_file)
|
|
|
|
end
|
2023-07-01 00:22:39 +08:00
|
|
|
end
|
|
|
|
end
|
2022-12-24 16:17:29 +08:00
|
|
|
if builders then
|
|
|
|
builders = type(builders) == "table" and builders or { builders }
|
|
|
|
---@cast builders (string|fun(LazyPlugin))[]
|
|
|
|
for _, build in ipairs(builders) do
|
|
|
|
if type(build) == "string" and build:sub(1, 1) == ":" then
|
|
|
|
local cmd = vim.api.nvim_parse_cmd(build:sub(2), {})
|
|
|
|
self.output = vim.api.nvim_cmd(cmd, { output = true })
|
|
|
|
elseif type(build) == "function" then
|
2022-12-27 05:59:02 +08:00
|
|
|
build(self.plugin)
|
2022-12-24 16:17:29 +08:00
|
|
|
else
|
|
|
|
local shell = vim.env.SHELL or vim.o.shell
|
|
|
|
local shell_args = shell:find("cmd.exe", 1, true) and "/c" or "-c"
|
2022-11-28 18:04:32 +08:00
|
|
|
|
2022-12-24 16:17:29 +08:00
|
|
|
self:spawn(shell, {
|
|
|
|
args = { shell_args, build },
|
|
|
|
cwd = self.plugin.dir,
|
|
|
|
})
|
|
|
|
end
|
2022-11-28 18:04:32 +08:00
|
|
|
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
|