1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-14 05:17:59 +08:00

feat(nvim-plug): support build option

This commit is contained in:
Eric Wong 2025-02-05 00:15:33 +08:00
parent 7071473003
commit daf276de98
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848
3 changed files with 62 additions and 28 deletions

View File

@ -32,13 +32,14 @@ require('plug').add({
## Plugin Spec ## Plugin Spec
| name | description | | name | description |
| -------- | ------------------------------------------------------- | | -------- | --------------------------------------------------------------------------------- |
| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` | | `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` |
| `cmds` | `table<string>`, commands lazy loading | | `cmds` | `table<string>`, commands lazy loading |
| `events` | `table<string>`, events lazy loading | | `events` | `table<string>`, events lazy loading |
| `on_ft` | `table<string>`, filetypes lazy loading | | `on_ft` | `table<string>`, filetypes lazy loading |
| `type` | `string`, plugin type including `color`, `plugin` | | `type` | `string`, plugin type including `color`, `plugin` |
| `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api |
## Commands ## Commands

View File

@ -7,24 +7,13 @@
local M = {} local M = {}
local job = require("spacevim.api.job") local job = require('spacevim.api.job')
local notify = require("spacevim.api.notify") local notify = require('spacevim.api.notify')
local jobs = {} local jobs = {}
local function install_plugin(plugSpec) --- @param plugSpec PluginSpec
local cmd = { "git", "clone", "--depth", "1" } local function build(plugSpec)
if plugSpec.branch then local jobid = job.start(plugSpec.build, {
table.insert(cmd, "--branch")
table.insert(cmd, plugSpec.branch)
elseif plugSpec.tag then
table.insert(cmd, "--branch")
table.insert(cmd, plugSpec.tag)
end
table.insert(cmd, plugSpec.url)
table.insert(cmd, plugSpec.path)
vim.print(plugSpec)
local jobid = job.start(cmd, {
on_stdout = function(id, data) on_stdout = function(id, data)
for _, v in ipairs(data) do for _, v in ipairs(data) do
notify.notify(jobs['jobid_' .. id .. ':' .. v]) notify.notify(jobs['jobid_' .. id .. ':' .. v])
@ -35,14 +24,52 @@ local function install_plugin(plugSpec)
notify.notify(jobs['jobid_' .. id .. ':' .. v]) notify.notify(jobs['jobid_' .. id .. ':' .. v])
end end
end, end,
on_exit = function(id, data, single) on_exit = function(id, data, single)
if data == 0 and single == 0 then if data == 0 and single == 0 then
notify.notify('Successfully build ' .. jobs['jobid_' .. id])
else
notify.notify('failed to build ' .. jobs['jobid_' .. id])
end
end,
})
jobs['jobid_' .. jobid] = plugSpec.name
end
--- @param plugSpec PluginSpec
local function install_plugin(plugSpec)
local cmd = { 'git', 'clone', '--depth', '1' }
if plugSpec.branch then
table.insert(cmd, '--branch')
table.insert(cmd, plugSpec.branch)
elseif plugSpec.tag then
table.insert(cmd, '--branch')
table.insert(cmd, plugSpec.tag)
end
table.insert(cmd, plugSpec.url)
table.insert(cmd, plugSpec.path)
local jobid = job.start(cmd, {
on_stdout = function(id, data)
for _, v in ipairs(data) do
notify.notify(jobs['jobid_' .. id .. ':' .. v])
end
end,
on_stderr = function(id, data)
for _, v in ipairs(data) do
notify.notify(jobs['jobid_' .. id .. ':' .. v])
end
end,
on_exit = function(id, data, single)
if data == 0 and single == 0 then
notify.notify('Successfully installed ' .. jobs['jobid_' .. id]) notify.notify('Successfully installed ' .. jobs['jobid_' .. id])
if plugSpec.build then
build(plugSpec)
end
else else
notify.notify('failed to install ' .. jobs['jobid_' .. id]) notify.notify('failed to install ' .. jobs['jobid_' .. id])
end end
end, end,
}) })
jobs['jobid_' .. jobid] = plugSpec.name jobs['jobid_' .. jobid] = plugSpec.name
end end

View File

@ -14,6 +14,12 @@ local config = require("plug.config")
--- @field events table<string> --- @field events table<string>
--- @field cmds table<string> --- @field cmds table<string>
--- @field config function --- @field config function
--- @field name string
--- @field branch string
--- @field tag string
--- @field url string
--- @field path string
--- @field build string|table<string>
function M.parser(plugSpec) function M.parser(plugSpec)
plugSpec.name = vim.split(plugSpec[1], '/')[2] plugSpec.name = vim.split(plugSpec[1], '/')[2]