initial commit
This commit is contained in:
commit
894692f380
5 changed files with 181 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
doc/tags
|
||||||
|
vim.toml
|
||||||
|
selene.toml
|
||||||
4
.stylua.toml
Normal file
4
.stylua.toml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
quote_style = "AutoPreferSingle"
|
||||||
|
call_parentheses = "None"
|
||||||
|
indent_type = "Spaces"
|
||||||
|
column_width = 80
|
||||||
44
doc/live-server.txt
Normal file
44
doc/live-server.txt
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
*live-server* *live-server.txt*
|
||||||
|
|
||||||
|
Author: Barrett Ruth <https://barrett-ruth.github.io>
|
||||||
|
Homepage: <https://github.com/barrett-ruth/live-server.nvim>
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
INTRODUCTION *live-server.nvim*
|
||||||
|
|
||||||
|
live-server.nvim automatically reloads HTML, CSS, and JavaScript files in the
|
||||||
|
browser via a local development server.
|
||||||
|
|
||||||
|
Author: Barrett Ruth <https://barrett-ruth.github.io>
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
SETUP *live-server.setup()*
|
||||||
|
>lua
|
||||||
|
require('live-server').setup(config)
|
||||||
|
<
|
||||||
|
Parameters: ~
|
||||||
|
|
||||||
|
{config} `(table | nil)`: (Optional) table containing configuration for
|
||||||
|
live-server. Defaults shown below.
|
||||||
|
|
||||||
|
Usage: ~
|
||||||
|
>lua
|
||||||
|
require('live-server').setup {
|
||||||
|
-- Arguments passed to live-server via `vim.fn.jobstart()`
|
||||||
|
-- Run `live-server --help` to see list of available options
|
||||||
|
-- For example, to use port 7000 and browser firefox:
|
||||||
|
-- args = { '--port=7000', '--browser=firefox' }
|
||||||
|
args = {}
|
||||||
|
}
|
||||||
|
<
|
||||||
|
===============================================================================
|
||||||
|
COMMANDS *live-server.commands*
|
||||||
|
|
||||||
|
*LiveServerStart*
|
||||||
|
:LiveServerStart Start the live server.
|
||||||
|
|
||||||
|
*LiveServerStop*
|
||||||
|
:LiveServerStop Stop the live server.
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
vim:tw=80:ft=help:
|
||||||
82
lua/live-server.lua
Normal file
82
lua/live-server.lua
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local function log(message, level)
|
||||||
|
vim.notify_once(
|
||||||
|
string.format('import-cost.nvim: %s', message),
|
||||||
|
vim.log.levels[level]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
M.config = {
|
||||||
|
-- let live-server handle the defaults
|
||||||
|
args = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
M.setup = function(user_config)
|
||||||
|
M.config = vim.tbl_deep_extend('force', M.config, user_config or {})
|
||||||
|
|
||||||
|
if not vim.fn.executable 'live-server' then
|
||||||
|
log(
|
||||||
|
'live-server is not executable. Ensure the npm module is properly installed',
|
||||||
|
vim.log.levels.ERROR
|
||||||
|
)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_create_user_command('LiveServerStart', M.start, {})
|
||||||
|
vim.api.nvim_create_user_command('LiveServerStop', M.stop, {})
|
||||||
|
end
|
||||||
|
|
||||||
|
local job_cache = {}
|
||||||
|
|
||||||
|
M.start = function()
|
||||||
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
|
||||||
|
local cmd = { 'live-server' }
|
||||||
|
vim.list_extend(cmd, M.config.args)
|
||||||
|
|
||||||
|
if job_cache[bufnr] then
|
||||||
|
log('live-server instance already running', 'INFO')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local job_id = vim.fn.jobstart(cmd, {
|
||||||
|
on_stderr = function(_, data)
|
||||||
|
if data[1] == '' then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
log(data[1]:match '.-m(.-)\27', 'ERROR')
|
||||||
|
end,
|
||||||
|
on_exit = function(_, exit_code)
|
||||||
|
job_cache[bufnr] = nil
|
||||||
|
|
||||||
|
if exit_code == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
log(
|
||||||
|
string.format(
|
||||||
|
'live-server stopped unexpectedly with exit code %s',
|
||||||
|
exit_code
|
||||||
|
),
|
||||||
|
'ERROR'
|
||||||
|
)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
job_cache[bufnr] = job_id
|
||||||
|
end
|
||||||
|
|
||||||
|
M.stop = function()
|
||||||
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
|
||||||
|
if job_cache[bufnr] then
|
||||||
|
vim.fn.jobstop(job_cache[bufnr])
|
||||||
|
job_cache[bufnr] = nil
|
||||||
|
else
|
||||||
|
log('no live-server instance running', 'INFO')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
48
readme.md
Normal file
48
readme.md
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
# live-server.nvim
|
||||||
|
|
||||||
|
Live reload HTML, CSS, and JavaScript files inside neovim with the power of
|
||||||
|
[live-server](https://www.npmjs.com/package/live-server).
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. Install [live-server](https://www.npmjs.com/package/live-server) globally
|
||||||
|
with your node.js package manager of choice.
|
||||||
|
|
||||||
|
2. Install regularly with your neovim package manager
|
||||||
|
|
||||||
|
For example, a config with [yarn](https://yarnpkg.com) and
|
||||||
|
[lazy.nvim](https://github.com/folke/lazy.nvim) may look like the following:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require('lazy').setup {
|
||||||
|
{
|
||||||
|
'barrett-ruth/live-server.nvim',
|
||||||
|
build = 'yarn global add live-server'
|
||||||
|
config = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Configure via the setup function (or use the defaults with no arguments):
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require('live-server').setup(opts)
|
||||||
|
```
|
||||||
|
|
||||||
|
See `:h live-server` for more information
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
`:LiveServerStart`: start the live server
|
||||||
|
|
||||||
|
`:LiveServerStop`: stop the live-server
|
||||||
|
|
||||||
|
## Acknowledgements
|
||||||
|
|
||||||
|
1. [mazeloth/live-server](https://github.com/manzeloth/live-server/blob/main/plugin/live-server.vim):
|
||||||
|
the first ever live-server port to vim
|
||||||
|
2. [aurum77/live-server.nvim](https://github.com/aurum77/live-server.nvim): the
|
||||||
|
first live-server port to neovim (however, it unecessarily depends on `npm`
|
||||||
|
and didn't quite cut it for me)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue