mirror of
https://github.com/mistricky/codesnap.nvim.git
synced 2024-12-26 11:26:30 +00:00
Initial commit
This commit is contained in:
commit
b5e86f5d4f
17 changed files with 227 additions and 0 deletions
31
.github/workflows/lint.yml
vendored
Normal file
31
.github/workflows/lint.yml
vendored
Normal file
|
@ -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 .
|
47
.github/workflows/release.yml
vendored
Normal file
47
.github/workflows/release.yml
vendored
Normal file
|
@ -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
|
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Lua
|
||||
/luarocks
|
||||
/lua_modules
|
||||
/.luarocks
|
||||
|
||||
# OS
|
||||
.DS_Store
|
13
README.md
Normal file
13
README.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
<h1 align="center">Nvim Plugin Template</h1>
|
||||
|
||||
<p align="center">
|
||||
|
||||
<img src="https://img.shields.io/badge/Neovim-57A143?logo=neovim&logoColor=fff&style=for-the-badge" alt="Neovim" />
|
||||
|
||||
<img src="https://img.shields.io/badge/Made%20With%20Lua-2C2D72?logo=lua&logoColor=fff&style=for-the-badge" alt="made with lua" >
|
||||
|
||||
<img src="https://img.shields.io/github/actions/workflow/status/mistricky/nvim-plugin-template/release.yml?style=for-the-badge&label=release" alt="release action status" />
|
||||
|
||||
<img src="https://img.shields.io/github/actions/workflow/status/mistricky/nvim-plugin-template/lint.yml?style=for-the-badge&label=Lint" alt="release action status" />
|
||||
|
||||
</p>
|
4
commitlint.config.js
Normal file
4
commitlint.config.js
Normal file
|
@ -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",
|
||||
};
|
4
doc/plugin-name.txt
Normal file
4
doc/plugin-name.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
**plugin-name** description
|
||||
|
||||
Author: Mist <mist.zzh@gmail.com>
|
||||
version: 0.0.2
|
9
lua/plugin-name/init.lua
Normal file
9
lua/plugin-name/init.lua
Normal file
|
@ -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
|
3
lua/plugin-name/static.lua
Normal file
3
lua/plugin-name/static.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
return {
|
||||
config = {},
|
||||
}
|
12
lua/plugin-name/utils/command.lua
Normal file
12
lua/plugin-name/utils/command.lua
Normal file
|
@ -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
|
23
lua/plugin-name/utils/list.lua
Normal file
23
lua/plugin-name/utils/list.lua
Normal file
|
@ -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
|
15
lua/plugin-name/utils/string.lua
Normal file
15
lua/plugin-name/utils/string.lua
Normal file
|
@ -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
|
17
lua/plugin-name/utils/table.lua
Normal file
17
lua/plugin-name/utils/table.lua
Normal file
|
@ -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
|
3
plugin/plugin-name.lua
Normal file
3
plugin/plugin-name.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
local plugin = require("plugin-name")
|
||||
|
||||
vim.api.nvim_create_user_command("CommandName", function() end, {})
|
6
project.toml
Normal file
6
project.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[project]
|
||||
name = "plugin-name"
|
||||
version = "0.0.2"
|
||||
description = "description"
|
||||
author = "Mist"
|
||||
email = "mist.zzh@gmail.com"
|
19
scripts/replace-template.py
Normal file
19
scripts/replace-template.py
Normal file
|
@ -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'])
|
10
stylua.toml
Normal file
10
stylua.toml
Normal file
|
@ -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
|
4
template/doc/plugin-name.txt.template
Normal file
4
template/doc/plugin-name.txt.template
Normal file
|
@ -0,0 +1,4 @@
|
|||
**{{project.name}}** {{project.description}}
|
||||
|
||||
Author: {{project.author}} <{{project.email}}>
|
||||
version: {{project.version}}
|
Loading…
Reference in a new issue