CHORE: officially renamed files to be deprecated and also made making
templates simpler
This commit is contained in:
+30
-90
@@ -1,6 +1,7 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern.utils")
|
||||
local render = require("vern.templates")
|
||||
local templates = require("vern.templates.python")
|
||||
|
||||
function M.create_project(opts)
|
||||
@@ -25,99 +26,33 @@ function M.create_project(opts)
|
||||
cfg.python.root,
|
||||
pname
|
||||
)
|
||||
local context = {
|
||||
local ctx = {
|
||||
project_name = pname,
|
||||
}
|
||||
|
||||
local bin = vim.tbl_get(
|
||||
cfg,
|
||||
"python",
|
||||
"templates",
|
||||
"project",
|
||||
"bin",
|
||||
"target"
|
||||
) or ""
|
||||
-- bin = bin["bin"].target or "src/{project_name}/main.py"
|
||||
local dest = vim.tbl_get(cfg, "python", "templates", "project") or {}
|
||||
|
||||
local bin_path = utils.interpolate(bin, context)
|
||||
vim.notify(bin_path, vim.log.levels.INFO)
|
||||
vim.fn.mkdir(
|
||||
vim.fs.dirname(vim.fs.joinpath(project_root, bin_path)),
|
||||
vim.fs.joinpath(
|
||||
project_root,
|
||||
utils.fmt(cfg.python.source_root, ctx)
|
||||
),
|
||||
"p"
|
||||
)
|
||||
utils.write_file(
|
||||
vim.fs.joinpath(project_root, bin_path),
|
||||
templates.main(pname)
|
||||
local function dump(dst, alt, tmpl)
|
||||
local full_path = vim.fs.joinpath(
|
||||
project_root,
|
||||
utils.fmt(vim.tbl_get(dest, dst, "target") or alt, ctx)
|
||||
)
|
||||
vim.notify(
|
||||
string.format("Created project %s at %s", pname, project_root),
|
||||
vim.log.levels.INFO
|
||||
)
|
||||
-- vim.cmd("edit " .. utils.get_project_root() .. "/" .. rel_path)
|
||||
-- vim.fn.mkdir(full_project_root .. "/include", "p")
|
||||
-- utils.write_file(
|
||||
-- { full_project_root, "main.py" },
|
||||
-- [[
|
||||
-- def main():
|
||||
-- print("Hello, World!")
|
||||
--
|
||||
-- if __name__ == "__main__":
|
||||
-- main()
|
||||
-- ]]
|
||||
-- )
|
||||
-- utils.write_file({ full_project_root, "include/__init__.py" }, "")
|
||||
-- utils.write_file({ full_project_root, "requirements.txt" }, "")
|
||||
-- utils.write_file(
|
||||
-- { full_project_root, "setup.py" },
|
||||
-- string.format(
|
||||
-- [[
|
||||
-- from setuptools import setup, find_packages
|
||||
--
|
||||
-- setup(
|
||||
-- name="%s",
|
||||
-- version="0.1.0",
|
||||
-- packages=find_packages(),
|
||||
-- install_requires=[],
|
||||
-- python_requires=">=3.6",
|
||||
-- )
|
||||
-- ]],
|
||||
-- project_name
|
||||
-- )
|
||||
-- )
|
||||
-- local gitignore = {
|
||||
-- "venv/",
|
||||
-- }
|
||||
-- utils.init_git(full_project_root, gitignore)
|
||||
-- vim.cmd("edit " .. full_project_root .. "/main.py")
|
||||
-- local venv_path = full_project_root .. "/venv"
|
||||
-- vim.fn.system("python3 -m venv " .. venv_path)
|
||||
-- vim.g.python3_host_prog = venv_path .. "/bin/python"
|
||||
-- vim.fn.setenv("VIRTUAL_ENV", venv_path)
|
||||
-- vim.fn.setenv("PATH", venv_path .. "/bin:" .. vim.fn.getenv("PATH"))
|
||||
-- print("Virtual environment activated for " .. project_name)
|
||||
-- end
|
||||
--
|
||||
-- local context = {
|
||||
-- project_name = utils.get_project_name(),
|
||||
-- name = pname,
|
||||
-- }
|
||||
-- -- local exe = opts.python.templates.project["executable"].target
|
||||
-- local init = opts.python.templates.project["init"].target
|
||||
-- local manifest = opts.python.templates.project["manifest"].target
|
||||
--
|
||||
-- local exe = (
|
||||
-- opts.python.templates.project["executable"].target:gsub(
|
||||
-- "{(%w+)}",
|
||||
-- context
|
||||
-- )
|
||||
-- )
|
||||
--
|
||||
-- -- local loc = opts.python.templates.file["module"].target
|
||||
-- -- local rel_path = (loc:gsub("{(%w+)}", context))
|
||||
-- local path = vim.fs.joinpath(utils.get_project_root(), exe)
|
||||
-- utils.write_file(path, templates.main(pname))
|
||||
utils.dump(full_path, tmpl)
|
||||
return full_path
|
||||
end
|
||||
local bin =
|
||||
dump("bin", "src/{project_name}/main.py", templates.main(pname))
|
||||
dump("pkg", "src/{project_name}/__init__.py", templates.__init__(pname))
|
||||
dump("spec", "pyproject.toml", templates.pyproject(pname))
|
||||
|
||||
-- vim.cmd("edit " .. utils.get_project_root() .. "/" .. exe)
|
||||
vim.cmd.edit(vim.fn.fnameescape(bin))
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -128,14 +63,20 @@ function M.create_file(opts)
|
||||
default = "",
|
||||
}, function(fname)
|
||||
if fname ~= nil and vim.trim(fname) ~= "" then
|
||||
local loc = opts.python.templates.file["module"].target
|
||||
local loc = vim.tbl_get(
|
||||
opts,
|
||||
"python",
|
||||
"templates",
|
||||
"file",
|
||||
"module"
|
||||
).target or {}
|
||||
local context = {
|
||||
project_name = utils.get_project_name(),
|
||||
name = fname,
|
||||
}
|
||||
local rel_path = (loc:gsub("{(%w+)}", context))
|
||||
local rel_path = utils.fmt(loc, context)
|
||||
local path = vim.fs.joinpath(utils.get_project_root(), rel_path)
|
||||
utils.write_file(path, templates.module(fname))
|
||||
utils.dump(path, templates.)
|
||||
vim.cmd("edit " .. utils.get_project_root() .. "/" .. rel_path)
|
||||
end
|
||||
end)
|
||||
@@ -148,10 +89,9 @@ function M.run(opts)
|
||||
local root = utils.get_project_root() or "."
|
||||
local project_name = vim.fs.basename(root)
|
||||
|
||||
local exe = opts.python.templates.project.executable.target
|
||||
or "src/%s/main.py"
|
||||
local exe = opts.python.templates.project.bin.target or "src/%s/main.py"
|
||||
-- local rel_path = exe:find("%%s") and string.format(exe, project_name) or exe
|
||||
local rel_path = string.gsub(exe, "%%s", project_name)
|
||||
local rel_path = utils.fmt(exe, { project_name = project_name })
|
||||
local full_path = root .. "/" .. rel_path
|
||||
utils.terminal({ "python3 " .. full_path }, opts.terminal or {})
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
return {
|
||||
python = {
|
||||
root = "Python", --- later will concat the project_root to the front
|
||||
root = "Python",
|
||||
source_root = "src/{project_name}",
|
||||
keybinds = {
|
||||
["<leader>pr"] = {
|
||||
desc = "Executes python code",
|
||||
@@ -16,10 +17,10 @@ return {
|
||||
["bin"] = {
|
||||
target = "src/{project_name}/main.py",
|
||||
},
|
||||
["init"] = {
|
||||
["pkg"] = {
|
||||
target = "src/{project_name}/__init__.py",
|
||||
},
|
||||
["manifest"] = {
|
||||
["spec"] = {
|
||||
target = "pyproject.toml",
|
||||
},
|
||||
},
|
||||
|
||||
@@ -0,0 +1,487 @@
|
||||
local utils = require("Polydev.utils")
|
||||
|
||||
local M = {}
|
||||
|
||||
local function extras(guard, file_type, file_name)
|
||||
if not file_name then
|
||||
return print("Header file creation canceled")
|
||||
end
|
||||
local guard_macro = file_name:upper():gsub("[^A-Z0-9]", "_") .. guard
|
||||
local content = string.format(
|
||||
[[
|
||||
#ifndef %s
|
||||
#define %s
|
||||
|
||||
// Add code here
|
||||
|
||||
#endif
|
||||
]],
|
||||
guard_macro,
|
||||
guard_macro
|
||||
)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "include", file_name .. file_type },
|
||||
content
|
||||
)
|
||||
end
|
||||
|
||||
M.projects = {
|
||||
javascript = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root)
|
||||
.. "/"
|
||||
.. project_name
|
||||
vim.fn.mkdir(full_project_root, "p")
|
||||
utils.write_file(
|
||||
{ full_project_root, "main.js" },
|
||||
[[
|
||||
console.log("Hello World!");
|
||||
]]
|
||||
)
|
||||
local gitignore = { "" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd("edit " .. full_project_root .. "/main.js")
|
||||
end,
|
||||
},
|
||||
lua = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root)
|
||||
.. "/"
|
||||
.. project_name
|
||||
vim.fn.mkdir(full_project_root .. "/lua/" .. project_name, "p")
|
||||
utils.write_file(
|
||||
{ full_project_root, "lua", project_name, "init.lua" },
|
||||
[[
|
||||
local M = {}
|
||||
|
||||
return M
|
||||
]]
|
||||
)
|
||||
local gitignore = { "" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd(
|
||||
"edit "
|
||||
.. full_project_root
|
||||
.. "/lua/"
|
||||
.. project_name
|
||||
.. "/init.lua"
|
||||
)
|
||||
end,
|
||||
},
|
||||
java = {
|
||||
run = function(project_name, project_root)
|
||||
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
|
||||
local content = [[
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
||||
]]
|
||||
local gitignore = {
|
||||
"build/",
|
||||
}
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
utils.write_file({ full_project_root, "src", "Main.java" }, content)
|
||||
end,
|
||||
},
|
||||
python = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root)
|
||||
.. "/"
|
||||
.. project_name
|
||||
vim.fn.mkdir(full_project_root .. "/include", "p")
|
||||
utils.write_file(
|
||||
{ full_project_root, "main.py" },
|
||||
[[
|
||||
def main():
|
||||
print("Hello, World!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
]]
|
||||
)
|
||||
utils.write_file({ full_project_root, "include/__init__.py" }, "")
|
||||
utils.write_file({ full_project_root, "requirements.txt" }, "")
|
||||
utils.write_file(
|
||||
{ full_project_root, "setup.py" },
|
||||
string.format(
|
||||
[[
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="%s",
|
||||
version="0.1.0",
|
||||
packages=find_packages(),
|
||||
install_requires=[],
|
||||
python_requires=">=3.6",
|
||||
)
|
||||
]],
|
||||
project_name
|
||||
)
|
||||
)
|
||||
local gitignore = {
|
||||
"venv/",
|
||||
}
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd("edit " .. full_project_root .. "/main.py")
|
||||
local venv_path = full_project_root .. "/venv"
|
||||
vim.fn.system("python3 -m venv " .. venv_path)
|
||||
vim.g.python3_host_prog = venv_path .. "/bin/python"
|
||||
vim.fn.setenv("VIRTUAL_ENV", venv_path)
|
||||
vim.fn.setenv("PATH", venv_path .. "/bin:" .. vim.fn.getenv("PATH"))
|
||||
print("Virtual environment activated for " .. project_name)
|
||||
end,
|
||||
},
|
||||
c = {
|
||||
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, ".clang-format" },
|
||||
[[
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
Standard: Latest
|
||||
UseTab: Always
|
||||
TabWidth: 8
|
||||
IndentWidth: 8
|
||||
BreakBeforeBraces: Allman
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SeparateDefinitionBlocks: Always
|
||||
Cpp11BracedListStyle: false
|
||||
BreakAfterReturnType: TopLevel
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
ReflowComments: Always
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
IndentAccessModifiers: false # Indent access specifiers by one level
|
||||
AccessModifierOffset: -4 # Optional: adjust offset relative to the class indentation level
|
||||
]]
|
||||
)
|
||||
utils.write_file(
|
||||
{ full_project_root, "src/main.c" },
|
||||
[[
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("%s", "Hello World");
|
||||
return 0;
|
||||
}
|
||||
]]
|
||||
)
|
||||
|
||||
utils.write_file(
|
||||
{ full_project_root, ".clang-tidy" },
|
||||
string.format([[
|
||||
---
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
concurrency-*,
|
||||
misc-*,
|
||||
modernize-*,
|
||||
performance-*,
|
||||
readability-*,
|
||||
portability-*,
|
||||
-readability-braces-around-statements,
|
||||
-readability-implicit-bool-conversion
|
||||
|
||||
WarningsAsErrors: ""
|
||||
|
||||
CheckOptions:
|
||||
- key: readability-identifier-naming.VariableCase
|
||||
value: lower_case
|
||||
- key: readability-identifier-naming.FunctionCase
|
||||
value: lower_case
|
||||
---
|
||||
]])
|
||||
)
|
||||
utils.write_file(
|
||||
{ full_project_root, "CMakeLists.txt" },
|
||||
string.format(
|
||||
[[
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(CMAKE_C_STANDARD 23)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
include_directories(include)
|
||||
project(%s LANGUAGES C)
|
||||
|
||||
set(SOURCES
|
||||
src/main.c
|
||||
)
|
||||
|
||||
add_executable(%s ${SOURCES})
|
||||
]],
|
||||
project_name,
|
||||
project_name,
|
||||
project_name
|
||||
)
|
||||
)
|
||||
local gitignore = { "build/", ".cache/" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.fn.system(
|
||||
string.format(
|
||||
"cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..",
|
||||
full_project_root
|
||||
)
|
||||
)
|
||||
vim.cmd("edit " .. full_project_root .. "/src/main.c")
|
||||
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, ".clang-format" },
|
||||
[[
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
Standard: Latest
|
||||
UseTab: Always
|
||||
TabWidth: 8
|
||||
IndentWidth: 8
|
||||
BreakBeforeBraces: Allman
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SeparateDefinitionBlocks: Always
|
||||
Cpp11BracedListStyle: false
|
||||
BreakAfterReturnType: TopLevel
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
ReflowComments: Always
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
IndentAccessModifiers: false # Indent access specifiers by one level
|
||||
AccessModifierOffset: -4 # Optional: adjust offset relative to the class indentation level
|
||||
]]
|
||||
)
|
||||
|
||||
utils.write_file(
|
||||
{ full_project_root, "src/main.cpp" },
|
||||
[[
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello World\n";
|
||||
return 0;
|
||||
}
|
||||
]]
|
||||
)
|
||||
|
||||
utils.write_file(
|
||||
{ full_project_root, ".clang-tidy" },
|
||||
string.format([[
|
||||
---
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
concurrency-*,
|
||||
misc-*,
|
||||
modernize-*,
|
||||
performance-*,
|
||||
readability-*,
|
||||
portability-*,
|
||||
-readability-braces-around-statements,
|
||||
-readability-implicit-bool-conversion
|
||||
|
||||
WarningsAsErrors: ""
|
||||
|
||||
CheckOptions:
|
||||
- key: readability-identifier-naming.VariableCase
|
||||
value: lower_case
|
||||
- key: readability-identifier-naming.FunctionCase
|
||||
value: lower_case
|
||||
---
|
||||
]])
|
||||
)
|
||||
|
||||
utils.write_file(
|
||||
{ full_project_root, "CMakeLists.txt" },
|
||||
string.format(
|
||||
[[
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
project(%s LANGUAGES CXX)
|
||||
|
||||
|
||||
set(SOURCES
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
add_executable(%s ${SOURCES})
|
||||
]],
|
||||
project_name,
|
||||
project_name
|
||||
)
|
||||
)
|
||||
|
||||
local gitignore = { "build/", ".cache/" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.fn.system(
|
||||
string.format(
|
||||
"cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..",
|
||||
full_project_root
|
||||
)
|
||||
)
|
||||
vim.cmd("edit " .. full_project_root .. "/src/main.cpp")
|
||||
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
|
||||
if vim.fn.isdirectory(full_project_root) == 0 then
|
||||
vim.fn.mkdir(full_project_root, "p") -- Create directory with parent directories
|
||||
end
|
||||
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,
|
||||
},
|
||||
}
|
||||
|
||||
M.files = {
|
||||
lua = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{
|
||||
utils.get_project_root(),
|
||||
"lua",
|
||||
utils.get_project_name(),
|
||||
file_name .. ".lua",
|
||||
},
|
||||
""
|
||||
)
|
||||
end,
|
||||
},
|
||||
java = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "src", file_name .. ".java" },
|
||||
string.format(
|
||||
[[
|
||||
public class %s {
|
||||
// New File
|
||||
}
|
||||
]],
|
||||
file_name
|
||||
)
|
||||
)
|
||||
end,
|
||||
},
|
||||
python = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "include", file_name .. ".py" },
|
||||
""
|
||||
)
|
||||
end,
|
||||
},
|
||||
c = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "src", file_name .. ".c" },
|
||||
""
|
||||
)
|
||||
end,
|
||||
},
|
||||
cpp = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "src", file_name .. ".cpp" },
|
||||
""
|
||||
)
|
||||
end,
|
||||
},
|
||||
rust = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "src", file_name .. ".rs" },
|
||||
""
|
||||
)
|
||||
end,
|
||||
},
|
||||
html = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ ".", file_name .. ".html" },
|
||||
string.format([[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>My First Heading</h1>
|
||||
<p>My first paragraph.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
]])
|
||||
)
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
M.extras = {
|
||||
run = function(lang, file_name)
|
||||
if lang == "c" then
|
||||
extras("_H", ".h", file_name)
|
||||
print("Successful creation of " .. file_name .. ".h")
|
||||
elseif lang == "cpp" then
|
||||
extras("_HPP", ".hpp", file_name)
|
||||
print("Successful creation of " .. file_name .. ".hpp")
|
||||
else
|
||||
print("Extras language is not found: enter cpp or c")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -1,371 +0,0 @@
|
||||
local utils = require("Polydev.utils")
|
||||
|
||||
local M = {}
|
||||
|
||||
local function extras(guard, file_type, file_name)
|
||||
if not file_name then return print("Header file creation canceled") end
|
||||
local guard_macro = file_name:upper():gsub("[^A-Z0-9]", "_") .. guard
|
||||
local content = string.format([[
|
||||
#ifndef %s
|
||||
#define %s
|
||||
|
||||
// Add code here
|
||||
|
||||
#endif
|
||||
]], guard_macro, guard_macro)
|
||||
utils.write_file({ utils.get_project_root(), "include", file_name .. file_type }, content)
|
||||
end
|
||||
|
||||
M.projects = {
|
||||
javascript = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
vim.fn.mkdir(full_project_root, "p")
|
||||
utils.write_file({ full_project_root, "main.js" }, [[
|
||||
console.log("Hello World!");
|
||||
]])
|
||||
local gitignore = { "" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd("edit " .. full_project_root .. "/main.js")
|
||||
end
|
||||
},
|
||||
lua = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
vim.fn.mkdir(full_project_root .. "/lua/" .. project_name, "p")
|
||||
utils.write_file({ full_project_root, "lua", project_name, "init.lua" }, [[
|
||||
local M = {}
|
||||
|
||||
return M
|
||||
]])
|
||||
local gitignore = { "" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd("edit " .. full_project_root .. "/lua/" .. project_name .. "/init.lua")
|
||||
end
|
||||
},
|
||||
java = {
|
||||
run = function(project_name, project_root)
|
||||
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
|
||||
local content = [[
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
||||
]]
|
||||
local gitignore = {
|
||||
"build/"
|
||||
}
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
utils.write_file({ full_project_root, "src", "Main.java" }, content)
|
||||
end
|
||||
},
|
||||
python = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
vim.fn.mkdir(full_project_root .. "/include", "p")
|
||||
utils.write_file({ full_project_root, "main.py" }, [[
|
||||
def main():
|
||||
print("Hello, World!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
]])
|
||||
utils.write_file({ full_project_root, "include/__init__.py" }, "")
|
||||
utils.write_file({ full_project_root, "requirements.txt" }, "")
|
||||
utils.write_file({ full_project_root, "setup.py" }, string.format([[
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="%s",
|
||||
version="0.1.0",
|
||||
packages=find_packages(),
|
||||
install_requires=[],
|
||||
python_requires=">=3.6",
|
||||
)
|
||||
]], project_name))
|
||||
local gitignore = {
|
||||
"venv/"
|
||||
}
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd("edit " .. full_project_root .. "/main.py")
|
||||
local venv_path = full_project_root .. "/venv"
|
||||
vim.fn.system("python3 -m venv " .. venv_path)
|
||||
vim.g.python3_host_prog = venv_path .. "/bin/python"
|
||||
vim.fn.setenv("VIRTUAL_ENV", venv_path)
|
||||
vim.fn.setenv("PATH", venv_path .. "/bin:" .. vim.fn.getenv("PATH"))
|
||||
print("Virtual environment activated for " .. project_name)
|
||||
end
|
||||
},
|
||||
c = {
|
||||
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, ".clang-format" }, [[
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
Standard: Latest
|
||||
UseTab: Always
|
||||
TabWidth: 8
|
||||
IndentWidth: 8
|
||||
BreakBeforeBraces: Allman
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SeparateDefinitionBlocks: Always
|
||||
Cpp11BracedListStyle: false
|
||||
BreakAfterReturnType: TopLevel
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
ReflowComments: Always
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
IndentAccessModifiers: false # Indent access specifiers by one level
|
||||
AccessModifierOffset: -4 # Optional: adjust offset relative to the class indentation level
|
||||
]])
|
||||
utils.write_file({ full_project_root, "src/main.c" }, [[
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("%s", "Hello World");
|
||||
return 0;
|
||||
}
|
||||
]])
|
||||
|
||||
utils.write_file({ full_project_root, ".clang-tidy" }, string.format([[
|
||||
---
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
concurrency-*,
|
||||
misc-*,
|
||||
modernize-*,
|
||||
performance-*,
|
||||
readability-*,
|
||||
portability-*,
|
||||
-readability-braces-around-statements,
|
||||
-readability-implicit-bool-conversion
|
||||
|
||||
WarningsAsErrors: ""
|
||||
|
||||
CheckOptions:
|
||||
- key: readability-identifier-naming.VariableCase
|
||||
value: lower_case
|
||||
- key: readability-identifier-naming.FunctionCase
|
||||
value: lower_case
|
||||
---
|
||||
]]))
|
||||
utils.write_file({ full_project_root, "CMakeLists.txt" }, string.format([[
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(CMAKE_C_STANDARD 23)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
include_directories(include)
|
||||
project(%s LANGUAGES C)
|
||||
|
||||
set(SOURCES
|
||||
src/main.c
|
||||
)
|
||||
|
||||
add_executable(%s ${SOURCES})
|
||||
]], project_name, project_name, project_name))
|
||||
local gitignore = { "build/", ".cache/" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.fn.system(string.format(
|
||||
"cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..",
|
||||
full_project_root))
|
||||
vim.cmd("edit " .. full_project_root .. "/src/main.c")
|
||||
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, ".clang-format" }, [[
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
Standard: Latest
|
||||
UseTab: Always
|
||||
TabWidth: 8
|
||||
IndentWidth: 8
|
||||
BreakBeforeBraces: Allman
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SeparateDefinitionBlocks: Always
|
||||
Cpp11BracedListStyle: false
|
||||
BreakAfterReturnType: TopLevel
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
ReflowComments: Always
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
IndentAccessModifiers: false # Indent access specifiers by one level
|
||||
AccessModifierOffset: -4 # Optional: adjust offset relative to the class indentation level
|
||||
]])
|
||||
|
||||
utils.write_file({ full_project_root, "src/main.cpp" }, [[
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello World\n";
|
||||
return 0;
|
||||
}
|
||||
]])
|
||||
|
||||
utils.write_file({ full_project_root, ".clang-tidy" }, string.format([[
|
||||
---
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
concurrency-*,
|
||||
misc-*,
|
||||
modernize-*,
|
||||
performance-*,
|
||||
readability-*,
|
||||
portability-*,
|
||||
-readability-braces-around-statements,
|
||||
-readability-implicit-bool-conversion
|
||||
|
||||
WarningsAsErrors: ""
|
||||
|
||||
CheckOptions:
|
||||
- key: readability-identifier-naming.VariableCase
|
||||
value: lower_case
|
||||
- key: readability-identifier-naming.FunctionCase
|
||||
value: lower_case
|
||||
---
|
||||
]]))
|
||||
|
||||
utils.write_file({ full_project_root, "CMakeLists.txt" }, string.format([[
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
project(%s LANGUAGES CXX)
|
||||
|
||||
|
||||
set(SOURCES
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
add_executable(%s ${SOURCES})
|
||||
]], project_name, project_name))
|
||||
|
||||
local gitignore = { "build/", ".cache/" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.fn.system(string.format(
|
||||
"cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..",
|
||||
full_project_root))
|
||||
vim.cmd("edit " .. full_project_root .. "/src/main.cpp")
|
||||
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
|
||||
if vim.fn.isdirectory(full_project_root) == 0 then
|
||||
vim.fn.mkdir(full_project_root, "p") -- Create directory with parent directories
|
||||
end
|
||||
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
|
||||
},
|
||||
}
|
||||
|
||||
M.files = {
|
||||
lua = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "lua", utils.get_project_name(), file_name .. ".lua" }, "")
|
||||
end
|
||||
},
|
||||
java = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ utils.get_project_root(), "src", file_name .. ".java" }, string.format([[
|
||||
public class %s {
|
||||
// New File
|
||||
}
|
||||
]], file_name))
|
||||
end
|
||||
},
|
||||
python = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ utils.get_project_root(), "include", file_name .. ".py" }, "")
|
||||
end
|
||||
},
|
||||
c = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ utils.get_project_root(), "src", file_name .. ".c" }, "")
|
||||
end
|
||||
|
||||
},
|
||||
cpp = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ utils.get_project_root(), "src", file_name .. ".cpp" }, "")
|
||||
end
|
||||
},
|
||||
rust = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ utils.get_project_root(), "src", file_name .. ".rs" }, "")
|
||||
end
|
||||
},
|
||||
html = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ ".", file_name .. ".html" }, string.format([[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>My First Heading</h1>
|
||||
<p>My first paragraph.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
]]))
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
M.extras = {
|
||||
run = function(lang, file_name)
|
||||
if lang == "c" then
|
||||
extras("_H", ".h", file_name)
|
||||
print("Successful creation of " .. file_name .. ".h")
|
||||
elseif lang == "cpp" then
|
||||
extras("_HPP", ".hpp", file_name)
|
||||
print("Successful creation of " .. file_name .. ".hpp")
|
||||
else
|
||||
print("Extras language is not found: enter cpp or c")
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,14 @@
|
||||
local M = {}
|
||||
|
||||
function M.imp(ft, template, name)
|
||||
ft, template, name = ft or "", template or "", name or ""
|
||||
if ft == "" or template == "" or name == "" then
|
||||
return
|
||||
end
|
||||
local ok, mod = pcall(require, "vern.templates." .. ft)
|
||||
if ok and type(mod) ~= "table" then
|
||||
return string.gsub(mod[template], "%%s", name)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,29 +1,18 @@
|
||||
local M = {}
|
||||
|
||||
M.main = function(opts)
|
||||
local template = [=[
|
||||
return {
|
||||
main = vim.trim([=[
|
||||
def main() -> None:
|
||||
print("Hello from %s!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
]=]
|
||||
return string.format(template, opts)
|
||||
end
|
||||
|
||||
M.__init__ = function(opts)
|
||||
local template = [=[
|
||||
# %s
|
||||
]=]),
|
||||
__init__ = vim.trim([=[
|
||||
# %s init
|
||||
|
||||
__all__: list[str] = []
|
||||
]=]
|
||||
return string.format(template, opts.project_name)
|
||||
end
|
||||
|
||||
M.pyproject = function(opts)
|
||||
local n = opts.project_name
|
||||
local template = [=[
|
||||
]=]),
|
||||
pyproject = vim.trim([=[
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
@@ -38,17 +27,11 @@ dependencies = []
|
||||
|
||||
[project.scripts]
|
||||
%s = "%s.main:main"
|
||||
]=]
|
||||
return string.format(template, n, n, n, n)
|
||||
end
|
||||
|
||||
M.module = function(opts)
|
||||
local template = [=[
|
||||
]=]),
|
||||
module = vim.trim([=[
|
||||
"""
|
||||
%s module
|
||||
Module: %s
|
||||
"""
|
||||
]=]
|
||||
return string.format(template, opts)
|
||||
end
|
||||
|
||||
return M
|
||||
]=]),
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,13 +2,13 @@ local M = {}
|
||||
|
||||
---@param path string
|
||||
---@param content string
|
||||
function M.write_file(path, content)
|
||||
function M.dump(path, content)
|
||||
local file = assert(io.open(path, "w"), "Error creating file: " .. path)
|
||||
file:write(content)
|
||||
file:close()
|
||||
end
|
||||
|
||||
function M.interpolate(str, ctx)
|
||||
function M.fmt(str, ctx)
|
||||
return (str:gsub("{([^}]+)}", ctx))
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user