From b5e86f5d4f369f76f67ac269d171cb3272dba33e Mon Sep 17 00:00:00 2001 From: Mist Date: Tue, 13 Feb 2024 14:05:36 +0800 Subject: [PATCH] Initial commit --- .github/workflows/lint.yml | 31 ++++++++++++++++++ .github/workflows/release.yml | 47 +++++++++++++++++++++++++++ .gitignore | 7 ++++ README.md | 13 ++++++++ commitlint.config.js | 4 +++ doc/plugin-name.txt | 4 +++ lua/plugin-name/init.lua | 9 +++++ lua/plugin-name/static.lua | 3 ++ lua/plugin-name/utils/command.lua | 12 +++++++ lua/plugin-name/utils/list.lua | 23 +++++++++++++ lua/plugin-name/utils/string.lua | 15 +++++++++ lua/plugin-name/utils/table.lua | 17 ++++++++++ plugin/plugin-name.lua | 3 ++ project.toml | 6 ++++ scripts/replace-template.py | 19 +++++++++++ stylua.toml | 10 ++++++ template/doc/plugin-name.txt.template | 4 +++ 17 files changed, 227 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 README.md create mode 100644 commitlint.config.js create mode 100644 doc/plugin-name.txt create mode 100644 lua/plugin-name/init.lua create mode 100644 lua/plugin-name/static.lua create mode 100644 lua/plugin-name/utils/command.lua create mode 100644 lua/plugin-name/utils/list.lua create mode 100644 lua/plugin-name/utils/string.lua create mode 100644 lua/plugin-name/utils/table.lua create mode 100644 plugin/plugin-name.lua create mode 100644 project.toml create mode 100644 scripts/replace-template.py create mode 100644 stylua.toml create mode 100644 template/doc/plugin-name.txt.template diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..18dcf17 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,31 @@ +name: Lint + +on: push + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + + - name: Setup nodejs + uses: actions/setup-node@v4 + with: + node-version: latest + + - name: Install commit message convention lib + run: npm i commitlint-config-wizardoc -D + + - name: Check commit message + uses: wagoid/commitlint-github-action@v4 + + - name: Check code style + uses: JohnnyMorganz/stylua-action@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: latest + args: --check . diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..eac73b4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,47 @@ +name: Release + +on: + push: + branches: + - main + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Replace template + run: python3 scripts/replace-template.py + + - name: Commit changes + uses: EndBug/add-and-commit@v9 + with: + message: "[Update] apply template" + + - name: Read version from project config + id: read_toml + uses: SebRollen/toml-action@v1.0.2 + with: + file: project.toml + field: project.version + + - name: Bump version and push tag + id: tag_version + uses: mathieudutour/github-tag-action@v6.1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + custom_tag: ${{ steps.read_toml.outputs.value }} + + - name: Create a GitHub release + uses: ncipollo/release-action@v1 + with: + tag: ${{ steps.tag_version.outputs.new_tag }} + name: Release ${{ steps.tag_version.outputs.new_tag }} + generateReleaseNotes: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..876b9e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# Lua +/luarocks +/lua_modules +/.luarocks + +# OS +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..1ed0b8c --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +

Nvim Plugin Template

+ +

+ +Neovim + +made with lua + +release action status + +release action status + +

diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..339eaee --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,4 @@ +module.exports = { + // This line config will read the NPM package named "commitlint-config-wizardoc", so please make sure you have installed it before config this line. + extends: "wizardoc", +}; diff --git a/doc/plugin-name.txt b/doc/plugin-name.txt new file mode 100644 index 0000000..ef3bf68 --- /dev/null +++ b/doc/plugin-name.txt @@ -0,0 +1,4 @@ +**plugin-name** description + +Author: Mist +version: 0.0.2 diff --git a/lua/plugin-name/init.lua b/lua/plugin-name/init.lua new file mode 100644 index 0000000..b3660b5 --- /dev/null +++ b/lua/plugin-name/init.lua @@ -0,0 +1,9 @@ +local table_utils = require("utils.table") +local static = require("plugin-name.static") +local main = {} + +function main.setup(config) + static.config = table_utils.merge(static.config, config) +end + +return main diff --git a/lua/plugin-name/static.lua b/lua/plugin-name/static.lua new file mode 100644 index 0000000..83cb1e4 --- /dev/null +++ b/lua/plugin-name/static.lua @@ -0,0 +1,3 @@ +return { + config = {}, +} diff --git a/lua/plugin-name/utils/command.lua b/lua/plugin-name/utils/command.lua new file mode 100644 index 0000000..4dc8f28 --- /dev/null +++ b/lua/plugin-name/utils/command.lua @@ -0,0 +1,12 @@ +local command_util = {} + +function command_util.exec_command(command, mode) + local handle = assert(io.popen(command, mode)) + local origin = assert(handle:read("*a")) + + handle:close() + + return origin +end + +return command_util diff --git a/lua/plugin-name/utils/list.lua b/lua/plugin-name/utils/list.lua new file mode 100644 index 0000000..ee2d2de --- /dev/null +++ b/lua/plugin-name/utils/list.lua @@ -0,0 +1,23 @@ +local list_utils = {} + +function list_utils.find(list, predicate) + for _, value in ipairs(list) do + if predicate(value) then + return value + end + end + + return nil +end + +function list_utils.some(list, predicate) + return list_utils.find(list, predicate) ~= nil +end + +function list_utils.includes(list, value) + return list_utils.find(list, function(item) + return item == value + end) ~= nil +end + +return list_utils diff --git a/lua/plugin-name/utils/string.lua b/lua/plugin-name/utils/string.lua new file mode 100644 index 0000000..d15cac2 --- /dev/null +++ b/lua/plugin-name/utils/string.lua @@ -0,0 +1,15 @@ +local string_util = {} + +function string_util.trim(str) + return str:gsub("%s+", "") +end + +function string_util.escape(str) + return str:gsub("[%(%)%.%%%+%-%*%?%[%^%$%]]", "%%%1") +end + +function string_util.ends_with(str, suffix) + return str:sub(-#suffix) == suffix +end + +return string_util diff --git a/lua/plugin-name/utils/table.lua b/lua/plugin-name/utils/table.lua new file mode 100644 index 0000000..965313e --- /dev/null +++ b/lua/plugin-name/utils/table.lua @@ -0,0 +1,17 @@ +local table_utils = {} + +function table_utils.assign(t, props) + for k, v in pairs(props) do + t[k] = v + end +end + +function table_utils.merge(t1, t2) + for k, v in pairs(t2) do + t1[k] = v + end + + return t1 +end + +return table_utils diff --git a/plugin/plugin-name.lua b/plugin/plugin-name.lua new file mode 100644 index 0000000..e6762f2 --- /dev/null +++ b/plugin/plugin-name.lua @@ -0,0 +1,3 @@ +local plugin = require("plugin-name") + +vim.api.nvim_create_user_command("CommandName", function() end, {}) diff --git a/project.toml b/project.toml new file mode 100644 index 0000000..db5888c --- /dev/null +++ b/project.toml @@ -0,0 +1,6 @@ +[project] +name = "plugin-name" +version = "0.0.2" +description = "description" +author = "Mist" +email = "mist.zzh@gmail.com" diff --git a/scripts/replace-template.py b/scripts/replace-template.py new file mode 100644 index 0000000..16cfce6 --- /dev/null +++ b/scripts/replace-template.py @@ -0,0 +1,19 @@ +from glob import glob +from typing import Callable, Final +from re import sub +from functools import reduce +import tomllib + +PROJECT_CONFIG_PATH: Final = "project.toml" +TEMPLATE_PATH: Final = "template/**/*.template" + +read_config: Callable[[str], dict] = lambda path: tomllib.load(open(path, 'rb')) + +apply_config: Callable[[dict, list[str]], str] = lambda config, keys: reduce(lambda config, key: config[key], keys, config) + +replace: Callable[[str, dict], str] = lambda content, config: sub(r"{{([^}]+)}}", lambda match: apply_config(config, match.group(1).split('.')), content) + +update: Callable[[str, str], None] = lambda path, content: open(sub(r'^template/(.+)\.template$', r"\1", path), 'w').write(content) + +for template in map(lambda file: {'path': file, 'content': replace(open(file, 'r').read(), read_config(PROJECT_CONFIG_PATH))}, glob(TEMPLATE_PATH)): + update(template['path'], template['content']) diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..fb3dcf8 --- /dev/null +++ b/stylua.toml @@ -0,0 +1,10 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferDouble" +call_parentheses = "Always" +collapse_simple_statement = "Never" + +[sort_requires] +enabled = false diff --git a/template/doc/plugin-name.txt.template b/template/doc/plugin-name.txt.template new file mode 100644 index 0000000..927b169 --- /dev/null +++ b/template/doc/plugin-name.txt.template @@ -0,0 +1,4 @@ +**{{project.name}}** {{project.description}} + +Author: {{project.author}} <{{project.email}}> +version: {{project.version}}