REFACTOR: Completely changed how project creation is done so I can make

other languages easier and hopefully faster
This commit is contained in:
2026-10-22 00:19:19 -04:00
parent df760783ba
commit 3bb97d833b
9 changed files with 347 additions and 105 deletions
+62
View File
@@ -0,0 +1,62 @@
return {
--[[ =====================================================================
TEMPLATE: MAIN (Entrypoint)
File: main.c
Target: src/{project_name}/main.py
===================================================================== --]]
main = vim.trim([=[
#include <stdio.h>
int
main()
{
char* str = "Hello World";
printf("%s\n", str);
return 0;
}
]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: INIT (Package Anchor)
File: __init__.py
Target: src/{project_name}/__init__.py
===================================================================== --]]
__init__ = vim.trim([=[
# %s init
__all__: list[str] = []
]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: PYPROJECT (Spec / Build Manifest)
File: pyproject.toml
Target: pyproject.toml
===================================================================== --]]
pyproject = vim.trim([=[
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "%s"
version = "0.1.0"
description = "Project %s"
readme = "README.md"
requires-python = ">=3.10"
dependencies = []
[project.scripts]
%s = "%s.main:main"
]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: MODULE (Standalone File)
File: {name}.py
Target: src/{project_name}/{name}.py
===================================================================== --]]
module = vim.trim([=[
"""
Module: %s
"""
]=]) .. "\n",
}
+7 -7
View File
@@ -1,17 +1,17 @@
local M = {}
---@param ft string Filetype of template
---@param template string Template in language table
---@param path string Filetype of template
---@param kind string Template in language table
---@param name string A string to replace temp values in template
---@return string
function M.fetch(ft, template, name)
ft, template, name = ft or "", template or "", name or ""
if ft == "" or template == "" or name == "" then
function M.fetch(kind_path, kind, name)
kind_path, kind, name = kind_path or "", kind or "", name or ""
if kind_path == "" or kind == "" or name == "" then
return ""
end
local ok, mod = pcall(require, "vern.templates." .. ft)
local ok, mod = pcall(require, kind_path)
if ok and type(mod) == "table" then
return (string.gsub(mod[template], "%%s", name))
return (string.gsub(mod[kind], "%%s", name))
end
return ""
end