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:
+2
-31
@@ -2,6 +2,7 @@ local M = {}
|
||||
|
||||
local utils = require("vern.utils")
|
||||
local templates = require("vern.templates")
|
||||
local action_utils = require("vern.actions.utils")
|
||||
|
||||
local join = vim.fs.joinpath
|
||||
|
||||
@@ -17,38 +18,8 @@ function M.create_project(opts)
|
||||
|
||||
---@type VernCConfig
|
||||
local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {})
|
||||
local ctx = { project_name = pname }
|
||||
|
||||
local root = join(vim.fn.expand(cfg.workspace_root), cfg.c.root, pname)
|
||||
vim.fn.mkdir(root, "p")
|
||||
local bin
|
||||
for tbl_name, tbl in pairs(cfg.c.templates.project) do
|
||||
local raw_path = join(tbl.path, tbl.name)
|
||||
local path = utils.resolve_path(raw_path, cfg.c.dirs, ctx)
|
||||
if tbl_name == "primary" then
|
||||
bin = join(root, path)
|
||||
end
|
||||
local abs_file_path = vim.fs.normalize(join(root, path))
|
||||
print("File Path: " .. abs_file_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.c.templates.extras) do
|
||||
if tbl.enabled then
|
||||
local raw_path = join(tbl.path, tbl.name)
|
||||
local path = utils.resolve_path(raw_path, cfg.c.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
|
||||
|
||||
local bin = action_utils.create(cfg.c, pname, root)
|
||||
utils.init_git(root, "c")
|
||||
|
||||
vim.cmd.edit(vim.fn.fnameescape(bin))
|
||||
|
||||
Reference in New Issue
Block a user