Changed the files to work with templates
This commit is contained in:
+16
-12
@@ -1,14 +1,15 @@
|
|||||||
|
---@type table
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@class Keybinds
|
---@class KeybindConfigs
|
||||||
---@field [string] string
|
---@field [string] string
|
||||||
---
|
---
|
||||||
---@class ConfigsLanguage
|
---@class LanguageConfigs
|
||||||
---@field project_root? string
|
---@field project_root? string
|
||||||
---@field keybinds? Keybinds -- ? makes fields optional
|
---@field keybinds? KeybindConfigs -- ? makes fields optional
|
||||||
---@field build_attributes? string
|
---@field build_attributes? string
|
||||||
---
|
---
|
||||||
---@class Terminal
|
---@class TerminalConfigs
|
||||||
---@field right_padding integer
|
---@field right_padding integer
|
||||||
---@field left_padding integer
|
---@field left_padding integer
|
||||||
---@field bottom_padding integer
|
---@field bottom_padding integer
|
||||||
@@ -18,14 +19,14 @@ local M = {}
|
|||||||
---@field relativenumber boolean
|
---@field relativenumber boolean
|
||||||
---
|
---
|
||||||
---@class Defaults
|
---@class Defaults
|
||||||
---@field html ConfigsLanguage
|
---@field html LanguageConfigs
|
||||||
---@field rust ConfigsLanguage
|
---@field rust LanguageConfigs
|
||||||
---@field java ConfigsLanguage
|
---@field java LanguageConfigs
|
||||||
---@field python ConfigsLanguage
|
---@field python LanguageConfigs
|
||||||
---@field lua ConfigsLanguage
|
---@field lua LanguageConfigs
|
||||||
---@field c ConfigsLanguage
|
---@field c LanguageConfigs
|
||||||
---@field cpp ConfigsLanguage
|
---@field cpp LanguageConfigs
|
||||||
---@field terminal Terminal
|
---@field terminal TerminalConfigs
|
||||||
|
|
||||||
---@type Defaults
|
---@type Defaults
|
||||||
M.defaults = {
|
M.defaults = {
|
||||||
@@ -91,13 +92,16 @@ M.defaults = {
|
|||||||
---@type string[]
|
---@type string[]
|
||||||
M.user_config = {}
|
M.user_config = {}
|
||||||
|
|
||||||
|
---@param user_opts table
|
||||||
function M.setup(user_opts)
|
function M.setup(user_opts)
|
||||||
M.user_config = vim.tbl_deep_extend("force", {}, M.defaults, user_opts or {})
|
M.user_config = vim.tbl_deep_extend("force", {}, M.defaults, user_opts or {})
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param lang string
|
---@param lang string
|
||||||
|
---@return string|table
|
||||||
function M.get(lang)
|
function M.get(lang)
|
||||||
return M.user_config[lang] or {}
|
return M.user_config[lang] or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return table
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ function M.create_new_file()
|
|||||||
vim.ui.input({ prompt = "Enter language for new file: " }, function(lang)
|
vim.ui.input({ prompt = "Enter language for new file: " }, function(lang)
|
||||||
if not lang or lang == "" then return print("File creation canceled.") end
|
if not lang or lang == "" then return print("File creation canceled.") end
|
||||||
|
|
||||||
if M.load_language_module(lang) and M.loaded_languages[lang].create_new_file then
|
if M.load_language_module(lang) and templates.files[lang] and templates.files[lang].run then
|
||||||
M.loaded_languages[lang].create_new_file()
|
templates.create_new_file(lang)
|
||||||
else
|
else
|
||||||
print("Error: No File creation method for " .. lang)
|
print("Error: No File creation method for " .. lang)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,94 +25,6 @@ function M.setup(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.create_project()
|
|
||||||
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
|
|
||||||
if not project_name or project_name == "" then
|
|
||||||
print("Project creation canceled.")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
|
|
||||||
for _, path in ipairs({ "/src", "/build", "/include" }) do
|
|
||||||
vim.fn.mkdir(project_root .. path, "p")
|
|
||||||
end
|
|
||||||
|
|
||||||
utils.write_file(project_root .. "/build/" .. project_name .. ".polydev", project_name)
|
|
||||||
utils.write_file(project_root .. "/src/main.c", [[
|
|
||||||
/* If you have vcpkg and want to use it:
|
|
||||||
vcpkg new --application
|
|
||||||
vcpkg add port <package_name>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
printf("%s", "Hello World");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
]])
|
|
||||||
|
|
||||||
utils.write_file(project_root .. "/CMakeLists.txt", string.format([[
|
|
||||||
cmake_minimum_required(VERSION 3.10)
|
|
||||||
project(%s)
|
|
||||||
include_directories(include)
|
|
||||||
set(SOURCES src/main.c)
|
|
||||||
add_executable(%s ${SOURCES})
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
||||||
set(CMAKE_C_STANDARD 23)
|
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
||||||
|
|
||||||
# find_package(SDL3 CONFIG REQUIRED) # An example of how to import libraries from vcpkg
|
|
||||||
# target_link_libraries(Game PRIVATE SDL3::SDL3)
|
|
||||||
]], project_name, project_name))
|
|
||||||
|
|
||||||
|
|
||||||
utils.write_file(project_root .. "/CMakePresets.json", string.format([[
|
|
||||||
# For the purposes of vcpkg, DO NOT REMOVE, but feel free to change as needed
|
|
||||||
{
|
|
||||||
"version": 2,
|
|
||||||
"configurePresets": [
|
|
||||||
{
|
|
||||||
"name": "vcpkg",
|
|
||||||
"generator": "Ninja",
|
|
||||||
"binaryDir": "${sourceDir}/build",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]]))
|
|
||||||
|
|
||||||
utils.write_file(project_root .. "/CMakeUserPresets.json", string.format([[
|
|
||||||
{
|
|
||||||
"version": 2,
|
|
||||||
"configurePresets": [
|
|
||||||
{
|
|
||||||
"name": "default",
|
|
||||||
"inherits": "vcpkg",
|
|
||||||
"environment": {
|
|
||||||
"VCPKG_ROOT": "/Users/<USER>/vcpkg"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
]]))
|
|
||||||
vim.cmd("edit " .. project_root .. "/src/main.c")
|
|
||||||
vim.fn.system(string.format("cd %s/build/ && cmake .. && cmake --build .", project_root))
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.create_new_file()
|
|
||||||
vim.ui.input({ prompt = "Enter file name: " }, function(class_name)
|
|
||||||
if not class_name or class_name == "" then return print("File creation canceled.") end
|
|
||||||
local root_dir = M.get_project_root()
|
|
||||||
if not root_dir then return print("Error: Project root not found.") end
|
|
||||||
utils.write_file(root_dir .. "/src/" .. class_name .. ".c", "")
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.create_new_header_file()
|
function M.create_new_header_file()
|
||||||
vim.ui.input({ prompt = "Enter header file name: " }, function(header_name)
|
vim.ui.input({ prompt = "Enter header file name: " }, function(header_name)
|
||||||
if not header_name then return print("Header file creation canceled.") end
|
if not header_name then return print("Header file creation canceled.") end
|
||||||
|
|||||||
@@ -25,95 +25,6 @@ function M.setup(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.create_project()
|
|
||||||
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
|
|
||||||
if not project_name or project_name == "" then
|
|
||||||
print("Project creation canceled.")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
|
|
||||||
for _, path in ipairs({ "/src", "/build", "/include" }) do
|
|
||||||
vim.fn.mkdir(project_root .. path, "p")
|
|
||||||
end
|
|
||||||
|
|
||||||
utils.write_file(project_root .. "/build/" .. project_name .. ".polydev", project_name)
|
|
||||||
utils.write_file(project_root .. "/src/main.cpp", [[
|
|
||||||
/* If you have vcpkg and want to use it:
|
|
||||||
vcpkg new --application
|
|
||||||
vcpkg add port <package_name>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::cout << "Hello World" << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
]])
|
|
||||||
|
|
||||||
utils.write_file(project_root .. "/CMakeLists.txt", string.format([[
|
|
||||||
cmake_minimum_required(VERSION 3.10)
|
|
||||||
project(%s)
|
|
||||||
include_directories(include)
|
|
||||||
set(SOURCES src/main.cpp)
|
|
||||||
add_executable(%s ${SOURCES})
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
||||||
set(CMAKE_C_STANDARD 23)
|
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
||||||
|
|
||||||
# find_package(SDL3 CONFIG REQUIRED) # An example of how to import libraries from vcpkg
|
|
||||||
# target_link_libraries(Game PRIVATE SDL3::SDL3)
|
|
||||||
]], project_name, project_name))
|
|
||||||
|
|
||||||
|
|
||||||
utils.write_file(project_root .. "/CMakePresets.json", string.format([[
|
|
||||||
# For the purposes of vcpkg, DO NOT REMOVE, but feel free to change as needed
|
|
||||||
{
|
|
||||||
"version": 2,
|
|
||||||
"configurePresets": [
|
|
||||||
{
|
|
||||||
"name": "vcpkg",
|
|
||||||
"generator": "Ninja",
|
|
||||||
"binaryDir": "${sourceDir}/build",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]]))
|
|
||||||
|
|
||||||
utils.write_file(project_root .. "/CMakeUserPresets.json", string.format([[
|
|
||||||
{
|
|
||||||
"version": 2,
|
|
||||||
"configurePresets": [
|
|
||||||
{
|
|
||||||
"name": "default",
|
|
||||||
"inherits": "vcpkg",
|
|
||||||
"environment": {
|
|
||||||
"VCPKG_ROOT": "/Users/<USER>/vcpkg"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
]]))
|
|
||||||
vim.fn.system(string.format("cd %s/build/ && cmake .. && cmake --build .", project_root))
|
|
||||||
|
|
||||||
vim.cmd("edit " .. project_root .. "/src/main.cpp")
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.create_new_file()
|
|
||||||
vim.ui.input({ prompt = "Enter file name: " }, function(class_name)
|
|
||||||
if not class_name or class_name == "" then return print("File creation canceled.") end
|
|
||||||
local root_dir = M.get_project_root()
|
|
||||||
if not root_dir then return print("Error: Project root not found.") end
|
|
||||||
utils.write_file(root_dir .. "/src/" .. class_name .. ".cpp", "")
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.create_new_header_file()
|
function M.create_new_header_file()
|
||||||
vim.ui.input({ prompt = "Enter header file name: " }, function(header_name)
|
vim.ui.input({ prompt = "Enter header file name: " }, function(header_name)
|
||||||
if not header_name then return print("Header file creation canceled.") end
|
if not header_name then return print("Header file creation canceled.") end
|
||||||
|
|||||||
@@ -1,55 +1,13 @@
|
|||||||
local utils = require("Polydev.utils")
|
---@type table
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
---@type table|nil
|
||||||
M.opts = nil
|
M.opts = nil
|
||||||
|
|
||||||
|
---@param opts table
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("html"), opts or {})
|
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("html"), opts or {})
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.create_project()
|
---@return table
|
||||||
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
|
|
||||||
if not project_name or project_name == "" then return print("Project creation canceled.") end
|
|
||||||
local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
|
|
||||||
|
|
||||||
local main_html_content = [[
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Page Title</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<h1>My First Heading</h1>
|
|
||||||
<p>My first paragraph.</p>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
]]
|
|
||||||
utils.write_file(project_root .. "index.html", main_html_content)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.create_new_file()
|
|
||||||
vim.ui.input({ prompt = "Enter page name: " }, function(page)
|
|
||||||
if not page or page == "" then return print("Class creation canceled.") end
|
|
||||||
local html_content = string.format([[
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Page Title</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<h1>My First Heading</h1>
|
|
||||||
<p>My first paragraph.</p>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
]])
|
|
||||||
|
|
||||||
utils.write_file("./" .. page .. ".html", html_content)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -21,21 +21,6 @@ function M.setup(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.create_new_file()
|
|
||||||
vim.ui.input({ prompt = "Enter class name: " }, function(class_name)
|
|
||||||
if not class_name or class_name == "" then return print("Class creation canceled.") end
|
|
||||||
local root_dir = vim.fn.expand("%:p:h"):match("(.*)/src")
|
|
||||||
if not root_dir then return print("Error: src directory not found.") end
|
|
||||||
local java_content = string.format([[
|
|
||||||
public class %s {
|
|
||||||
// New File
|
|
||||||
}
|
|
||||||
]], class_name)
|
|
||||||
|
|
||||||
utils.write_file(root_dir .. "/src/" .. class_name .. ".java", java_content)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.build()
|
function M.build()
|
||||||
local project_root = vim.fn.expand("%:p:h"):match("(.*)/src")
|
local project_root = vim.fn.expand("%:p:h"):match("(.*)/src")
|
||||||
if not project_root then return print("Error: Could not detect project root directory.") end
|
if not project_root then return print("Error: Could not detect project root directory.") end
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
|
---@module "Polydev.utils"
|
||||||
local utils = require("Polydev.utils")
|
local utils = require("Polydev.utils")
|
||||||
|
|
||||||
|
---@type table
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
---@type table
|
||||||
M.keybinds = {}
|
M.keybinds = {}
|
||||||
|
|
||||||
|
---@type table|nil
|
||||||
M.opts = nil
|
M.opts = nil
|
||||||
|
|
||||||
|
---@param opts table
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("lua"), opts or {})
|
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("lua"), opts or {})
|
||||||
for key, command in pairs(M.opts.keybinds) do
|
for key, command in pairs(M.opts.keybinds) do
|
||||||
@@ -17,7 +24,9 @@ function M.setup(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_project_root()
|
function M.run()
|
||||||
|
---@return string|nil
|
||||||
|
local function get_project_root()
|
||||||
local dir = vim.fn.expand("%:p:h")
|
local dir = vim.fn.expand("%:p:h")
|
||||||
while dir ~= "/" do
|
while dir ~= "/" do
|
||||||
local polydev_file = vim.fn.glob(dir .. "/*.polydev")
|
local polydev_file = vim.fn.glob(dir .. "/*.polydev")
|
||||||
@@ -27,49 +36,18 @@ function M.get_project_root()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_project_name()
|
---@return string
|
||||||
local polydev_file = vim.fn.glob((M.get_project_root() or "") .. "/*.polydev")
|
local function get_project_name()
|
||||||
return polydev_file:match("([^/]+)%.polydev$")
|
return vim.fn.glob((M.get_project_root() or "") .. "/*.polydev"):match("([^/]+)%.polydev$")
|
||||||
end
|
end
|
||||||
|
if not get_project_root() or not get_project_name() then return print("Error: Project root not found.") end
|
||||||
function M.create_project()
|
local init_lua_path = get_project_root() .. "/lua/" .. get_project_name() .. "/init.lua"
|
||||||
vim.ui.input({ prompt = "Enter project name: " },
|
|
||||||
function(project_name)
|
|
||||||
if not project_name or project_name == "" then return print("Project creation canceled.") end
|
|
||||||
local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
|
|
||||||
for _, path in ipairs({ "/lua/" .. project_name }) do vim.fn.mkdir(project_root .. path, "p") end
|
|
||||||
|
|
||||||
utils.write_file(project_root .. "/lua/" .. project_name .. "/init.lua", [[
|
|
||||||
local M = {}
|
|
||||||
|
|
||||||
return M
|
|
||||||
]])
|
|
||||||
|
|
||||||
utils.write_file(project_root .. "/" .. project_name .. ".polydev", "[[DO NOT REMOVE THIS FILE]]")
|
|
||||||
vim.cmd("edit " .. project_root .. "/lua/" .. project_name .. "/init.lua")
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.create_new_file()
|
|
||||||
vim.ui.input({ prompt = "Enter file name: " }, function(class_name)
|
|
||||||
if not class_name or class_name == "" then return print("File creation canceled.") end
|
|
||||||
local root_dir = M.get_project_root()
|
|
||||||
local project_name = M.get_project_name()
|
|
||||||
if not root_dir or not project_name then return print("Error: Project root not found.") end
|
|
||||||
utils.write_file(root_dir .. "/lua/" .. project_name .. "/" .. class_name .. ".lua", "")
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.run()
|
|
||||||
local root = M.get_project_root()
|
|
||||||
local project_name = M.get_project_name()
|
|
||||||
if not root or not project_name then return print("Error: Project root not found.") end
|
|
||||||
local init_lua_path = root .. "/lua/" .. project_name .. "/init.lua"
|
|
||||||
if vim.fn.filereadable(init_lua_path) == 1 then
|
if vim.fn.filereadable(init_lua_path) == 1 then
|
||||||
utils.open_float_terminal("lua " .. init_lua_path)
|
utils.open_float_terminal("lua " .. init_lua_path)
|
||||||
else
|
else
|
||||||
print("Error: " .. init_lua_path .. " not found in " .. root)
|
print("Error: " .. init_lua_path .. " not found in " .. get_project_root())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return table
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -42,26 +42,6 @@ function M.get_project_root()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.create_new_file()
|
|
||||||
vim.ui.input({ prompt = "Enter file name: " }, function(file_name)
|
|
||||||
if not file_name or file_name == "" then
|
|
||||||
return print("File creation canceled.")
|
|
||||||
end
|
|
||||||
|
|
||||||
if not file_name:match("%.py$") then
|
|
||||||
file_name = file_name .. ".py"
|
|
||||||
end
|
|
||||||
|
|
||||||
local root_dir = M.get_project_root()
|
|
||||||
if not root_dir then
|
|
||||||
return print("Error: Project root not found.")
|
|
||||||
end
|
|
||||||
|
|
||||||
local file_path = root_dir .. "/include/" .. file_name
|
|
||||||
utils.write_file(file_path, "")
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.install_dependency()
|
function M.install_dependency()
|
||||||
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
|
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
|
||||||
if not pip_module or pip_module == "" then
|
if not pip_module or pip_module == "" then
|
||||||
|
|||||||
@@ -21,24 +21,6 @@ function M.setup(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.create_project()
|
|
||||||
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
|
|
||||||
if not project_name or project_name == "" then return print("Project creation canceled.") end
|
|
||||||
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
|
|
||||||
vim.fn.system("cargo new " .. project_root)
|
|
||||||
vim.cmd("edit " .. project_root .. "/src/main.rs")
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.create_new_file()
|
|
||||||
vim.ui.input({ prompt = "Enter file name: " }, function(class_name)
|
|
||||||
if not class_name or class_name == "" then return print("File creation canceled.") end
|
|
||||||
local root_dir = M.get_project_root()
|
|
||||||
if not root_dir then return print("Error: Project root not found.") end
|
|
||||||
utils.write_file(root_dir .. "/src/" .. class_name .. ".rs", "")
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.get_project_root()
|
function M.get_project_root()
|
||||||
local dir = vim.fn.expand("%:p:h")
|
local dir = vim.fn.expand("%:p:h")
|
||||||
while dir ~= "/" do
|
while dir ~= "/" do
|
||||||
|
|||||||
+301
-7
@@ -11,7 +11,11 @@ local M = {}
|
|||||||
---@field java TemplateLanguage
|
---@field java TemplateLanguage
|
||||||
---@field python TemplateLanguage
|
---@field python TemplateLanguage
|
||||||
---@field lua TemplateLanguage
|
---@field lua TemplateLanguage
|
||||||
---@alias TemplatesLanguageName "java" | "python" | "lua"
|
---@field c TemplateLanguage
|
||||||
|
---@field cpp TemplateLanguage
|
||||||
|
---@field rust TemplateLanguage
|
||||||
|
---@field html TemplateLanguage
|
||||||
|
---@alias TemplatesLanguageName "java" | "python" | "lua" | "c" | "cpp" | "rust" | "html"
|
||||||
|
|
||||||
---@type Projects
|
---@type Projects
|
||||||
M.projects = {
|
M.projects = {
|
||||||
@@ -19,7 +23,6 @@ M.projects = {
|
|||||||
run = function(project_name, project_root)
|
run = function(project_name, project_root)
|
||||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||||
for _, path in ipairs({ "/src", "/build" }) do vim.fn.mkdir(full_project_root .. path, "p") end
|
for _, path in ipairs({ "/src", "/build" }) do vim.fn.mkdir(full_project_root .. path, "p") end
|
||||||
|
|
||||||
local main_java_content = [[
|
local main_java_content = [[
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -35,7 +38,6 @@ public class Main {
|
|||||||
run = function(project_name, project_root)
|
run = function(project_name, project_root)
|
||||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||||
vim.fn.mkdir(full_project_root .. "/include", "p")
|
vim.fn.mkdir(full_project_root .. "/include", "p")
|
||||||
|
|
||||||
utils.write_file(full_project_root .. "/main.py", [[
|
utils.write_file(full_project_root .. "/main.py", [[
|
||||||
def main():
|
def main():
|
||||||
print("Hello, World!")
|
print("Hello, World!")
|
||||||
@@ -43,7 +45,6 @@ def main():
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
]])
|
]])
|
||||||
|
|
||||||
utils.write_file(full_project_root .. "/include/__init__.py", "")
|
utils.write_file(full_project_root .. "/include/__init__.py", "")
|
||||||
utils.write_file(full_project_root .. "/requirements.txt", "")
|
utils.write_file(full_project_root .. "/requirements.txt", "")
|
||||||
utils.write_file(full_project_root .. "/setup.py", string.format([[
|
utils.write_file(full_project_root .. "/setup.py", string.format([[
|
||||||
@@ -57,14 +58,12 @@ setup(
|
|||||||
python_requires=">=3.6",
|
python_requires=">=3.6",
|
||||||
)
|
)
|
||||||
]], project_name))
|
]], project_name))
|
||||||
|
|
||||||
vim.cmd("edit " .. full_project_root .. "/main.py")
|
vim.cmd("edit " .. full_project_root .. "/main.py")
|
||||||
local venv_path = full_project_root .. "/venv"
|
local venv_path = full_project_root .. "/venv"
|
||||||
vim.fn.system("python3 -m venv " .. venv_path)
|
vim.fn.system("python3 -m venv " .. venv_path)
|
||||||
vim.g.python3_host_prog = venv_path .. "/bin/python"
|
vim.g.python3_host_prog = venv_path .. "/bin/python"
|
||||||
vim.fn.setenv("VIRTUAL_ENV", venv_path)
|
vim.fn.setenv("VIRTUAL_ENV", venv_path)
|
||||||
vim.fn.setenv("PATH", venv_path .. "/bin:" .. vim.fn.getenv("PATH"))
|
vim.fn.setenv("PATH", venv_path .. "/bin:" .. vim.fn.getenv("PATH"))
|
||||||
|
|
||||||
print("Virtual environment activated for " .. project_name)
|
print("Virtual environment activated for " .. project_name)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -73,7 +72,6 @@ setup(
|
|||||||
run = function(project_name, project_root)
|
run = function(project_name, project_root)
|
||||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||||
for _, path in ipairs({ "/lua/" .. project_name }) do vim.fn.mkdir(full_project_root .. path, "p") end
|
for _, path in ipairs({ "/lua/" .. project_name }) do vim.fn.mkdir(full_project_root .. path, "p") end
|
||||||
|
|
||||||
utils.write_file(full_project_root .. "/lua/" .. project_name .. "/init.lua", [[
|
utils.write_file(full_project_root .. "/lua/" .. project_name .. "/init.lua", [[
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -84,6 +82,294 @@ return M
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
c = {
|
||||||
|
run = function(project_name, project_root)
|
||||||
|
local full_project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
|
||||||
|
for _, path in ipairs({ "/src", "/build", "/include" }) do vim.fn.mkdir(full_project_root .. path, "p") end
|
||||||
|
utils.write_file(full_project_root .. "/build/" .. project_name .. ".polydev", project_name)
|
||||||
|
utils.write_file(full_project_root .. "/src/main.c", [[
|
||||||
|
/* If you have vcpkg and want to use it:
|
||||||
|
vcpkg new --application
|
||||||
|
vcpkg add port <package_name>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
printf("%s", "Hello World");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
]])
|
||||||
|
utils.write_file(full_project_root .. "/CMakeLists.txt", string.format([[
|
||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
project(%s)
|
||||||
|
include_directories(include)
|
||||||
|
set(SOURCES src/main.c)
|
||||||
|
add_executable(%s ${SOURCES})
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
set(CMAKE_C_STANDARD 23)
|
||||||
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# find_package(SDL3 CONFIG REQUIRED) # An example of how to import libraries from vcpkg
|
||||||
|
# target_link_libraries(Game PRIVATE SDL3::SDL3)
|
||||||
|
]], project_name, project_name))
|
||||||
|
utils.write_file(full_project_root .. "/CMakePresets.json", string.format([[
|
||||||
|
# For the purposes of vcpkg, DO NOT REMOVE, but feel free to change as needed
|
||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"configurePresets": [
|
||||||
|
{
|
||||||
|
"name": "vcpkg",
|
||||||
|
"generator": "Ninja",
|
||||||
|
"binaryDir": "${sourceDir}/build",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]]))
|
||||||
|
utils.write_file(full_project_root .. "/CMakeUserPresets.json", string.format([[
|
||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"configurePresets": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"inherits": "vcpkg",
|
||||||
|
"environment": {
|
||||||
|
"VCPKG_ROOT": "/Users/<USER>/vcpkg"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
]]))
|
||||||
|
vim.cmd("edit " .. full_project_root .. "/src/main.c")
|
||||||
|
vim.fn.system(string.format("cd %s/build/ && cmake .. && cmake --build .", full_project_root))
|
||||||
|
end
|
||||||
|
},
|
||||||
|
cpp = {
|
||||||
|
run = function (project_name, project_root)
|
||||||
|
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||||
|
for _, path in ipairs({ "/src", "/build", "/include" }) do
|
||||||
|
vim.fn.mkdir(full_project_root .. path, "p")
|
||||||
|
end
|
||||||
|
utils.write_file(full_project_root .. "/build/" .. project_name .. ".polydev", project_name)
|
||||||
|
utils.write_file(full_project_root .. "/src/main.cpp", [[
|
||||||
|
/* If you have vcpkg and want to use it:
|
||||||
|
vcpkg new --application
|
||||||
|
vcpkg add port <package_name>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::cout << "Hello World" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
]])
|
||||||
|
utils.write_file(full_project_root .. "/CMakeLists.txt", string.format([[
|
||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
project(%s)
|
||||||
|
include_directories(include)
|
||||||
|
set(SOURCES src/main.cpp)
|
||||||
|
add_executable(%s ${SOURCES})
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
set(CMAKE_C_STANDARD 23)
|
||||||
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# find_package(SDL3 CONFIG REQUIRED) # An example of how to import libraries from vcpkg
|
||||||
|
# target_link_libraries(Game PRIVATE SDL3::SDL3)
|
||||||
|
]], project_name, project_name))
|
||||||
|
utils.write_file(full_project_root .. "/CMakePresets.json", string.format([[
|
||||||
|
# For the purposes of vcpkg, DO NOT REMOVE, but feel free to change as needed
|
||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"configurePresets": [
|
||||||
|
{
|
||||||
|
"name": "vcpkg",
|
||||||
|
"generator": "Ninja",
|
||||||
|
"binaryDir": "${sourceDir}/build",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]]))
|
||||||
|
utils.write_file(full_project_root .. "/CMakeUserPresets.json", string.format([[
|
||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"configurePresets": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"inherits": "vcpkg",
|
||||||
|
"environment": {
|
||||||
|
"VCPKG_ROOT": "/Users/<USER>/vcpkg"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
]]))
|
||||||
|
vim.fn.system(string.format("cd %s/build/ && cmake .. && cmake --build .", full_project_root))
|
||||||
|
vim.cmd("edit " .. full_project_root .. "/src/main.cpp")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
},
|
||||||
|
rust = {
|
||||||
|
run = function (project_name, project_root)
|
||||||
|
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||||
|
vim.fn.system("cargo new " .. full_project_root)
|
||||||
|
vim.cmd("edit " .. full_project_root .. "/src/main.rs")
|
||||||
|
end
|
||||||
|
},
|
||||||
|
html = {
|
||||||
|
run = function(project_name, project_root)
|
||||||
|
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||||
|
local main_html_content = [[
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Page Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>My First Heading</h1>
|
||||||
|
<p>My first paragraph.</p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
]]
|
||||||
|
utils.write_file(full_project_root .. "index.html", main_html_content)
|
||||||
|
end
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
---@class TemplateFile
|
||||||
|
---@field run fun(file_name: string): nil
|
||||||
|
|
||||||
|
---@class Files
|
||||||
|
---@field java TemplateFile
|
||||||
|
---@field python TemplateFile
|
||||||
|
---@field lua TemplateFile
|
||||||
|
---@field c TemplateFile
|
||||||
|
---@field cpp TemplateFile
|
||||||
|
---@field rust TemplateFile
|
||||||
|
---@field html TemplateFile
|
||||||
|
---@alias TemplatesFileName "java" | "python" | "lua" | "c" | "cpp" | "rust" | "html"
|
||||||
|
|
||||||
|
---@type Files
|
||||||
|
M.files = {
|
||||||
|
java = {
|
||||||
|
run = function (file_name)
|
||||||
|
local root_dir = vim.fn.expand("%:p:h"):match("(.*)/src")
|
||||||
|
if not root_dir then return print("Error: src directory not found.") end
|
||||||
|
local java_content = string.format([[
|
||||||
|
public class %s {
|
||||||
|
// New File
|
||||||
|
}
|
||||||
|
]], class_name)
|
||||||
|
|
||||||
|
utils.write_file(root_dir .. "/src/" .. file_name .. ".java", java_content)
|
||||||
|
end
|
||||||
|
},
|
||||||
|
python = {
|
||||||
|
run = function (file_name)
|
||||||
|
if not file_name:match("%.py$") then file_name = file_name .. ".py" end
|
||||||
|
local root_dir = M.get_project_root()
|
||||||
|
if not root_dir then return print("Error: Project root not found.") end
|
||||||
|
local file_path = root_dir .. "/include/" .. file_name
|
||||||
|
utils.write_file(file_path, "")
|
||||||
|
end
|
||||||
|
},
|
||||||
|
lua = {
|
||||||
|
run = function (file_name)
|
||||||
|
local function get_project_root()
|
||||||
|
local dir = vim.fn.expand("%:p:h")
|
||||||
|
while dir ~= "/" do
|
||||||
|
local polydev_file = vim.fn.glob(dir .. "/*.polydev")
|
||||||
|
if polydev_file ~= "" then return dir end
|
||||||
|
dir = vim.fn.fnamemodify(dir, ":h")
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local function get_project_name() return vim.fn.glob((get_project_root() or "") .. "/*.polydev"):match("([^/]+)%.polydev$") end
|
||||||
|
if not get_project_root() or not get_project_name() then return print("Error: Project root not found.") end
|
||||||
|
utils.write_file(get_project_root() .. "/lua/" .. get_project_name() .. "/" .. file_name .. ".lua", "")
|
||||||
|
end
|
||||||
|
},
|
||||||
|
c = {
|
||||||
|
run = function (file_name)
|
||||||
|
local function get_project_root()
|
||||||
|
local dir = vim.fn.expand("%:p:h")
|
||||||
|
while dir ~= "/" do
|
||||||
|
if vim.fn.isdirectory(dir .. "/src") == 1 or vim.fn.filereadable(dir .. "/CMakeLists.txt") == 1 then
|
||||||
|
return dir
|
||||||
|
end
|
||||||
|
dir = vim.fn.fnamemodify(dir, ":h")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not file_name or file_name == "" then return print("File creation canceled.") end
|
||||||
|
local root_dir = get_project_root()
|
||||||
|
if not root_dir then return print("Error: Project root not found.") end
|
||||||
|
utils.write_file(root_dir .. "/src/" .. file_name .. ".c", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
},
|
||||||
|
cpp = {
|
||||||
|
run = function (file_name)
|
||||||
|
local function get_project_root()
|
||||||
|
local dir = vim.fn.expand("%:p:h")
|
||||||
|
while dir ~= "/" do
|
||||||
|
if vim.fn.isdirectory(dir .. "/src") == 1 or vim.fn.filereadable(dir .. "/CMakeLists.txt") == 1 then
|
||||||
|
return dir
|
||||||
|
end
|
||||||
|
dir = vim.fn.fnamemodify(dir, ":h")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local root_dir = get_project_root()
|
||||||
|
if not root_dir then return print("Error: Project root not found.") end
|
||||||
|
utils.write_file(root_dir .. "/src/" .. file_name .. ".cpp", "")
|
||||||
|
end
|
||||||
|
},
|
||||||
|
rust = {
|
||||||
|
run = function (file_name)
|
||||||
|
local function get_project_root()
|
||||||
|
local dir = vim.fn.expand("%:p:h")
|
||||||
|
while dir ~= "/" do
|
||||||
|
if vim.fn.isdirectory(dir .. "/src") == 1 then
|
||||||
|
return dir
|
||||||
|
end
|
||||||
|
dir = vim.fn.fnamemodify(dir, ":h")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local root_dir = get_project_root()
|
||||||
|
if not root_dir then return print("Error: Project root not found.") end
|
||||||
|
utils.write_file(root_dir .. "/src/" .. file_name .. ".rs", "")
|
||||||
|
end
|
||||||
|
},
|
||||||
|
html = {
|
||||||
|
run = function (file_name)
|
||||||
|
local html_content = string.format([[
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Page Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>My First Heading</h1>
|
||||||
|
<p>My first paragraph.</p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
]])
|
||||||
|
|
||||||
|
utils.write_file("./" .. file_name .. ".html", html_content)
|
||||||
|
end
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
---@param lang TemplatesLanguageName
|
---@param lang TemplatesLanguageName
|
||||||
@@ -95,5 +381,13 @@ function M.create_project(lang, project_root)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param lang TemplatesFileName
|
||||||
|
function M.create_new_file(lang)
|
||||||
|
vim.ui.input({ prompt = "Enter file name: " }, function(file_name)
|
||||||
|
if not file_name or file_name == "" then return print("File creation canceled.") end
|
||||||
|
M.files[lang].run(file_name)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
---@return any
|
---@return any
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user