Chore: moved similar functions to a utils for actions so they dont

repeat and copy costantly. Going to have to think of a better way that
consolidates it all as a lot of it overlaps
This commit is contained in:
2026-10-22 14:36:19 -04:00
parent 685a711644
commit b6d46a0cef
5 changed files with 57 additions and 82 deletions
+46
View File
@@ -0,0 +1,46 @@
local M = {}
local utils = require("vern.utils")
local templates = require("vern.templates")
local join = vim.fs.joinpath
---@param cfg table Language config
---@param pname string Name of project
---@param root string Project location
---@return string bin Location of executable
function M.create(cfg, pname, root)
local ctx = { project_name = pname }
vim.fn.mkdir(root, "p")
local bin
for tbl_name, tbl in pairs(cfg.templates.project) do
local raw_path = join(tbl.path, tbl.name)
local path = utils.resolve_path(raw_path, cfg.dirs, ctx)
if tbl_name == "primary" then
bin = join(root, path)
end
local abs_file_path = vim.fs.normalize(join(root, path))
local abs_dir_path = vim.fs.dirname(abs_file_path)
if abs_dir_path ~= root and not vim.startswith(root, abs_dir_path) then
vim.fn.mkdir(abs_dir_path, "p")
end
utils.dump(abs_file_path, templates.fetch(tbl.kind_path, tbl.kind, pname))
end
for _, tbl in pairs(cfg.templates.extras) do
if tbl.enabled then
local raw_path = join(tbl.path, tbl.name)
local path = utils.resolve_path(raw_path, cfg.dirs, ctx)
local abs_file_path = vim.fs.normalize(join(root, path))
local abs_dir_path = vim.fs.dirname(abs_file_path)
if abs_dir_path ~= root and not vim.startswith(root, abs_dir_path) then
vim.fn.mkdir(abs_dir_path, "p")
end
utils.dump(abs_file_path, templates.fetch(tbl.kind_path, tbl.kind, pname))
end
end
return bin
end
return M