diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cf41862 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,63 @@ +name: Ci + +on: [push] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Stylua + uses: JohnnyMorganz/stylua-action@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: latest + args: --check . + + + docs: + runs-on: ubuntu-latest + name: pandoc to vimdoc + if: ${{ github.ref == 'refs/heads/main' }} + steps: + - uses: actions/checkout@v3 + - name: panvimdoc + uses: kdheepak/panvimdoc@main + with: + vimdoc: nvim-plugin-template + treesitter: true + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: 'chore(doc): auto generate docs' + commit_user_name: "github-actions[bot]" + commit_user_email: "github-actions[bot]@users.noreply.github.com" + commit_author: "github-actions[bot] " + + test: + name: Run Test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + steps: + - uses: actions/checkout@v3 + - uses: rhysd/action-setup-vim@v1 + id: vim + with: + neovim: true + version: nightly + + - name: luajit + uses: leafo/gh-actions-lua@v10 + with: + luaVersion: "luajit-2.1.0-beta3" + + - name: luarocks + uses: leafo/gh-actions-luarocks@v4 + + - name: run test + shell: bash + run: | + luarocks install luacheck + luarocks install vusted + vusted ./test diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 0000000..a2b3447 --- /dev/null +++ b/.stylua.toml @@ -0,0 +1,6 @@ +column_width = 100 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferSingle" +call_parentheses = "Always" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ef7e302 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 nvimdev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..977faee --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# nvim-plugin-template +neovim plugin template integration test and doc publish + +## Usage + +1. click `use this template` button generate a repo on your github. +2. clone your plugin repo.open terminal then cd plugin directory. +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 use `stylua` and provide `.stylua.toml`. + +## Test +use vusted for test install by using `luarocks --lua-version=5.1 install vusted` then run `vusted test` +for your test cases. + +create test case in test folder file rule is `foo_spec.lua` with `_spec` more usage please check +[busted usage](https://lunarmodules.github.io/busted/) + +## Ci +Ci support auto generate doc from README and integration test and lint check by `stylua`. + + +## More +Other usage you can look at my plugins + +## License MIT diff --git a/doc/nvim-plugin-template.txt b/doc/nvim-plugin-template.txt new file mode 100644 index 0000000..a1e7b8f --- /dev/null +++ b/doc/nvim-plugin-template.txt @@ -0,0 +1,62 @@ +*nvim-plugin-template.txt* For NVIM v0.8.0 Last change: 2023 August 05 + +============================================================================== +Table of Contents *nvim-plugin-template-table-of-contents* + +1. nvim-plugin-template |nvim-plugin-template-nvim-plugin-template| + - Usage |nvim-plugin-template-nvim-plugin-template-usage| + - Format |nvim-plugin-template-nvim-plugin-template-format| + - Test |nvim-plugin-template-nvim-plugin-template-test| + - Ci |nvim-plugin-template-nvim-plugin-template-ci| + - More |nvim-plugin-template-nvim-plugin-template-more| + - License MIT |nvim-plugin-template-nvim-plugin-template-license-mit| + +============================================================================== +1. nvim-plugin-template *nvim-plugin-template-nvim-plugin-template* + +neovim plugin template integration test and doc publish + + +USAGE *nvim-plugin-template-nvim-plugin-template-usage* + +1. click `use this template` button generate a repo on your github. +2. clone your plugin repo.open terminal then cd plugin directory. +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 *nvim-plugin-template-nvim-plugin-template-format* + +format use `stylua` and provide `.stylua.toml`. + + +TEST *nvim-plugin-template-nvim-plugin-template-test* + +use vusted for test install by using `luarocks --lua-version=5.1 install +vusted` then run `vusted test` for your test cases. + +create test case in test folder file rule is `foo_spec.lua` with `_spec` more +usage please check busted usage + + +CI *nvim-plugin-template-nvim-plugin-template-ci* + +Ci support auto generate doc from README and integration test and lint check by +`stylua`. + + +MORE *nvim-plugin-template-nvim-plugin-template-more* + +Other usage you can look at my plugins + + +LICENSE MIT *nvim-plugin-template-nvim-plugin-template-license-mit* + +Generated by panvimdoc + +vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/lua/nvim-plugin-template/init.lua b/lua/nvim-plugin-template/init.lua new file mode 100644 index 0000000..afa0777 --- /dev/null +++ b/lua/nvim-plugin-template/init.lua @@ -0,0 +1,7 @@ +local function example() + return true +end + +return { + example = example, +} diff --git a/plugin/nvim-plugin-template.lua b/plugin/nvim-plugin-template.lua new file mode 100644 index 0000000..e69de29 diff --git a/rename.py b/rename.py new file mode 100644 index 0000000..0dea3d6 --- /dev/null +++ b/rename.py @@ -0,0 +1,34 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- + +import os, sys + +pdir = os.getcwd() + +if len(sys.argv) == 2: + new_name = sys.argv[1] + for dir in os.listdir(pdir): + if dir == "lua": + os.rename(os.path.join("lua", "nvim-plugin-template"), os.path.join("lua",new_name)) + if dir == "plugin": + os.rename(os.path.join("plugin", "nvim-plugin-template.lua"), + os.path.join("plugin",new_name + ".lua")) + if dir == 'doc': + os.rename(os.path.join("doc", "nvim-plugin-template.txt"), + os.path.join("doc",new_name + ".txt")) + if dir == '.github': + with open(os.path.join(".github","workflows","ci.yml"), 'r+') as f: + d = f.read() + t = d.replace('nvim-plugin-template', new_name) + f.seek(0, 0) + 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',new_name,'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')) diff --git a/test/plugin_spec.lua b/test/plugin_spec.lua new file mode 100644 index 0000000..4f1ef32 --- /dev/null +++ b/test/plugin_spec.lua @@ -0,0 +1,8 @@ +local example = require('nvim-plugin-template').example + +describe('neovim plugin', function() + it('work as expect', function() + local result = example() + assert.is_true(result) + end) +end)