improve script and add example codes

This commit is contained in:
mathew 2023-06-18 14:38:31 +08:00
parent aeb066f1f4
commit ab9a28a3e1
4 changed files with 31 additions and 5 deletions

View File

@ -3,9 +3,15 @@ neovim plugin template integration test and doc publish
## Usage ## Usage
click `use this template` button generate a repo on your github. then clone your plugin repo.open 1. click `use this template` button generate a repo on your github.
terminal then cd plugin directory , run `python3 rename.py your-plugin-name` this will replace all 2. clone your plugin repo.open terminal then cd plugin directory.
`nvim-plugin-template` to your `pluing-name`. Then develope your plugin. Enjoy! 3. run `python3 rename.py your-plugin-name` this will replace all `nvim-plugin-template` to your `pluing-name`.
then it will prompt you input `y` or `n` to remove example codes in `init.lua` and
`test/plugin_spec.lua`. if you are familiar this repo just input y. if you are first look at this
template I suggest you look at them first. after these step the `rename.py` will also auto
remove.
now you have a clean plugin env . enjoy!
## Format ## Format

View File

@ -0,0 +1,7 @@
local function example()
return true
end
return {
example = example,
}

View File

@ -3,9 +3,11 @@
import os, sys import os, sys
pdir = os.getcwd()
if len(sys.argv) == 2: if len(sys.argv) == 2:
new_name = sys.argv[1] new_name = sys.argv[1]
for dir in os.listdir(os.getcwd()): for dir in os.listdir(pdir):
if dir == "lua": if dir == "lua":
os.rename(os.path.join("lua", "nvim-plugin-template"), os.path.join("lua",new_name)) os.rename(os.path.join("lua", "nvim-plugin-template"), os.path.join("lua",new_name))
if dir == "plugin": if dir == "plugin":
@ -21,4 +23,12 @@ if len(sys.argv) == 2:
f.seek(0, 0) f.seek(0, 0)
f.write(t) f.write(t)
choice = input("Do you want also remove example code in init.lua and test (y|n): ")
if choice.lower() == 'y':
with open(os.path.join(pdir, 'lua','nvim-plugin-template','init.lua'), 'w') as f:
f.truncate()
with open(os.path.join(pdir, 'test','plugin_spec.lua'), 'w') as f:
f.truncate()
os.remove(os.path.join(os.getcwd(), 'rename.py')) os.remove(os.path.join(os.getcwd(), 'rename.py'))

View File

@ -1,5 +1,8 @@
local example = require('nvim-plugin-template').example
describe('neovim plugin', function() describe('neovim plugin', function()
it('work as expect', function() it('work as expect', function()
assert.is_true(true) local result = example()
assert.is_true(result)
end) end)
end) end)