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:
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
|
## 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
|
||||||
|
|
||||||
|
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 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
|
||||||
|
|
||||||
|
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 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]
|
||||||
|
Loading…
Reference in New Issue
Block a user