mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-13 23:27:59 +08:00
feat(nvim-plug): support build
option
This commit is contained in:
parent
7071473003
commit
daf276de98
15
bundle/nvim-plug/README.md
vendored
15
bundle/nvim-plug/README.md
vendored
@ -32,13 +32,14 @@ require('plug').add({
|
||||
|
||||
## Plugin Spec
|
||||
|
||||
| name | description |
|
||||
| -------- | ------------------------------------------------------- |
|
||||
| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` |
|
||||
| `cmds` | `table<string>`, commands lazy loading |
|
||||
| `events` | `table<string>`, events lazy loading |
|
||||
| `on_ft` | `table<string>`, filetypes lazy loading |
|
||||
| `type` | `string`, plugin type including `color`, `plugin` |
|
||||
| name | description |
|
||||
| -------- | --------------------------------------------------------------------------------- |
|
||||
| `[1]` | `string`, plugin repo short name, `wsdjeg/flygrep.nvim` |
|
||||
| `cmds` | `table<string>`, commands lazy loading |
|
||||
| `events` | `table<string>`, events lazy loading |
|
||||
| `on_ft` | `table<string>`, filetypes lazy loading |
|
||||
| `type` | `string`, plugin type including `color`, `plugin` |
|
||||
| `build` | `string` or `table<string>`, executed by [job](https://spacevim.org/api/job/) api |
|
||||
|
||||
## Commands
|
||||
|
||||
|
69
bundle/nvim-plug/lua/plug/installer.lua
vendored
69
bundle/nvim-plug/lua/plug/installer.lua
vendored
@ -7,24 +7,13 @@
|
||||
|
||||
local M = {}
|
||||
|
||||
local job = require("spacevim.api.job")
|
||||
local notify = require("spacevim.api.notify")
|
||||
local job = require('spacevim.api.job')
|
||||
local notify = require('spacevim.api.notify')
|
||||
local jobs = {}
|
||||
|
||||
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)
|
||||
vim.print(plugSpec)
|
||||
local jobid = job.start(cmd, {
|
||||
--- @param plugSpec PluginSpec
|
||||
local function build(plugSpec)
|
||||
local jobid = job.start(plugSpec.build, {
|
||||
on_stdout = function(id, data)
|
||||
for _, v in ipairs(data) do
|
||||
notify.notify(jobs['jobid_' .. id .. ':' .. v])
|
||||
@ -35,14 +24,52 @@ local function install_plugin(plugSpec)
|
||||
notify.notify(jobs['jobid_' .. id .. ':' .. v])
|
||||
end
|
||||
end,
|
||||
on_exit = function(id, data, single)
|
||||
if data == 0 and single == 0 then
|
||||
on_exit = function(id, data, single)
|
||||
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])
|
||||
if plugSpec.build then
|
||||
build(plugSpec)
|
||||
end
|
||||
else
|
||||
notify.notify('failed to install ' .. jobs['jobid_' .. id])
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
jobs['jobid_' .. jobid] = plugSpec.name
|
||||
end
|
||||
|
||||
|
6
bundle/nvim-plug/lua/plug/loader.lua
vendored
6
bundle/nvim-plug/lua/plug/loader.lua
vendored
@ -14,6 +14,12 @@ local config = require("plug.config")
|
||||
--- @field events table<string>
|
||||
--- @field cmds table<string>
|
||||
--- @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)
|
||||
plugSpec.name = vim.split(plugSpec[1], '/')[2]
|
||||
|
Loading…
Reference in New Issue
Block a user