REFACTOR: Completely changed how project creation is done so I can make
other languages easier and hopefully faster
This commit is contained in:
+36
-14
@@ -1,5 +1,22 @@
|
||||
local M = {}
|
||||
|
||||
-- -- Simple test function that pulls directly from the table and prints
|
||||
-- function M.test_print()
|
||||
-- local configs = require("vern.configs")
|
||||
-- local pconfigs = require("vern.configs.python")
|
||||
--
|
||||
-- local cfg = vim.tbl_deep_extend("force", {}, configs, pconfigs)
|
||||
-- -- Pulling straight from the python_config table
|
||||
-- local raw_path = cfg.python.templates.project.bin.path
|
||||
-- local dirs = cfg.python.dirs
|
||||
-- local context = { project_name = "my_cool_app" }
|
||||
--
|
||||
-- local final_path = M.resolve_path(raw_path, dirs, context)
|
||||
--
|
||||
-- print("Raw path:", raw_path)
|
||||
-- print("Resolved path:", final_path)
|
||||
-- end
|
||||
|
||||
local utils = require("vern.utils")
|
||||
local templates = require("vern.templates")
|
||||
|
||||
@@ -19,18 +36,19 @@ function M.create_project(opts)
|
||||
local py = cfg.python
|
||||
|
||||
local root = join(vim.fn.expand(cfg.workspace_root), py.root, pname)
|
||||
vim.fn.mkdir(join(root, utils.fmt(py.source_root, ctx)), "p")
|
||||
|
||||
local tmpl = get(py, "templates", "project") or {}
|
||||
local function dump(k, alt, id)
|
||||
local path = join(root, utils.fmt(get(tmpl, k, "target") or alt, ctx))
|
||||
utils.dump(path, templates.fetch("python", id, pname))
|
||||
return path
|
||||
local bin
|
||||
for tbl_name, tbl in pairs(py.templates.project) do
|
||||
local raw_path = join(tbl.path, tbl.name)
|
||||
local path = utils.resolve_path(raw_path, py.dirs, ctx)
|
||||
if tbl_name == "bin" then
|
||||
bin = join(root, path)
|
||||
end
|
||||
local abs_file_path = join(root, path)
|
||||
local abs_dir_path = vim.fs.dirname(abs_file_path)
|
||||
vim.fn.mkdir(abs_dir_path, "p")
|
||||
utils.dump(abs_file_path, templates.fetch(tbl.kind_path, tbl.kind, pname))
|
||||
end
|
||||
|
||||
local bin = dump("bin", "src/{project_name}/main.py", "main")
|
||||
dump("pkg", "src/{project_name}/__init__.py", "__init__")
|
||||
dump("spec", "pyproject.toml", "pyproject")
|
||||
utils.init_git(root, "python")
|
||||
|
||||
local venv_path = root .. "/venv"
|
||||
@@ -46,9 +64,13 @@ function M.create_file(opts)
|
||||
if not fname or fname == "" then
|
||||
return
|
||||
end
|
||||
local root = get(opts, "python", "templates", "file", "module").target or {}
|
||||
local py = get(opts, "python")
|
||||
local cfg = get(py, "templates", "file", "mod") or {}
|
||||
|
||||
local raw_path = join(cfg.path, cfg.name)
|
||||
local context = { project_name = utils.proj_name(), name = fname }
|
||||
local path = join(utils.proj_root(), utils.fmt(root, context))
|
||||
local path = utils.resolve_path(raw_path, py.dirs or {}, context)
|
||||
|
||||
utils.dump(path, templates.fetch("python", "module", fname))
|
||||
vim.cmd.edit(vim.fn.expand(path))
|
||||
end)
|
||||
@@ -61,8 +83,8 @@ function M.run(opts)
|
||||
local root = utils.proj_root() or "."
|
||||
local pname = vim.fs.basename(root)
|
||||
|
||||
local exe = opts.python.templates.project.bin.target or "src/%s/main.py"
|
||||
local full_path = vim.fn.expand(root, utils.fmt(exe, { project_name = pname }))
|
||||
local exe = opts.python.templates.project.bin.target or "src/{project_name}/main.py"
|
||||
local full_path = join(vim.fn.expand(root), utils.fmt(exe, { project_name = pname }))
|
||||
utils.term({ "python3 " .. full_path }, opts.terminal or {})
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user