95 lines
3.5 KiB
Lua
95 lines
3.5 KiB
Lua
local M = {}
|
|
|
|
local action_utils = require("vern-nvim.actions.utils")
|
|
local utils = require("vern-nvim.utils")
|
|
local templates = require("vern-nvim.templates")
|
|
|
|
M.create_project = function(opts)
|
|
opts = opts or {}
|
|
vim.ui.input(
|
|
{ prompt = "Project language (e.g. python): ", completion = "filetype" },
|
|
function(ft)
|
|
ft = ft and vim.trim(ft)
|
|
if not ft or vim.trim(ft) == "" then
|
|
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
|
|
title = "Vern Project",
|
|
})
|
|
return
|
|
end
|
|
local ok, actions = pcall(require, "vern-nvim.actions." .. ft)
|
|
local configs = require("vern-nvim.configs." .. ft)
|
|
local args = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
|
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
|
|
pname = pname and vim.trim(pname)
|
|
if not pname or pname == "" then
|
|
return
|
|
end
|
|
local root =
|
|
vim.fs.joinpath(vim.fn.expand(args.workspace_root), args[ft].root, pname)
|
|
local bin = action_utils.create(args[ft], args.env.author, pname, root)
|
|
utils.init_git(root, ft)
|
|
utils.init_readme(root)
|
|
if ok and actions and type(actions.create_project) == "function" then
|
|
actions.create_project(root)
|
|
end
|
|
vim.cmd.edit(vim.fn.fnameescape(bin))
|
|
vim.notify(
|
|
"Project: " .. pname .. " has been created!",
|
|
vim.log.levels.INFO,
|
|
{ title = "Vern Project" }
|
|
)
|
|
end)
|
|
end
|
|
)
|
|
end
|
|
|
|
M.create_file = function(opts)
|
|
opts = opts or {}
|
|
vim.ui.input({
|
|
prompt = "File language (e.g. python): ",
|
|
completion = "filetype",
|
|
}, function(ft)
|
|
ft = ft and vim.trim(ft)
|
|
if not ft or vim.trim(ft) == "" then
|
|
return
|
|
end
|
|
local ok, actions = pcall(require, "vern-nvim.actions." .. ft)
|
|
if not ok then
|
|
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
|
|
title = "Vern File",
|
|
})
|
|
return
|
|
end
|
|
local configs = require("vern-nvim.configs." .. ft)
|
|
local args = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
|
|
|
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
|
|
fname = fname and vim.trim(fname)
|
|
if not fname or fname == "" then
|
|
return
|
|
end
|
|
|
|
local mod
|
|
if ok and actions and type(actions.create_file) == "function" then
|
|
mod = actions.create_file(args[ft]) or args[ft].templates.file.source or {}
|
|
end
|
|
local raw_path = vim.fs.joinpath(mod.path, mod.name)
|
|
local context = {
|
|
project_name = utils.proj_name(),
|
|
company_name = opts.env.author,
|
|
file_name = fname,
|
|
}
|
|
local path = utils.resolve_path(raw_path, args[ft].dirs or {}, context)
|
|
local root = utils.proj_root()
|
|
utils.dump(
|
|
vim.fs.joinpath(root, path),
|
|
templates.fetch(mod.kind_path, mod.kind, context)
|
|
)
|
|
vim.cmd.edit(vim.fn.expand(path))
|
|
vim.notify(fname .. " has been created!", vim.log.levels.INFO, { title = "Vern File" })
|
|
end)
|
|
end)
|
|
end
|
|
|
|
return M
|