fix: fixed git initialization for project
chore: change write_file to take table instead of string
This commit is contained in:
@@ -16,15 +16,14 @@ local M = {}
|
|||||||
---@alias TemplatesLanguageName "java" | "python" | "lua" | "c" | "cpp" | "rust" | "html"
|
---@alias TemplatesLanguageName "java" | "python" | "lua" | "c" | "cpp" | "rust" | "html"
|
||||||
|
|
||||||
local function init_git(path, gitignore_lines)
|
local function init_git(path, gitignore_lines)
|
||||||
local full_path = vim.fn.expand(path)
|
vim.fn.mkdir(path, "p")
|
||||||
vim.fn.mkdir(full_path, "p")
|
|
||||||
|
|
||||||
-- Initialize Git
|
-- Initialize Git
|
||||||
vim.fn.system({ "git", "-C", full_path, "init" })
|
vim.fn.system({ "git", "-C", path, "init" })
|
||||||
|
|
||||||
-- Write .gitignore if provided
|
-- Write .gitignore if provided
|
||||||
if gitignore_lines and #gitignore_lines > 0 then
|
if gitignore_lines and #gitignore_lines > 0 then
|
||||||
local gitignore_path = full_path .. "/.gitignore"
|
local gitignore_path = { path, ".gitignore" }
|
||||||
local contents = table.concat(gitignore_lines, "\n")
|
local contents = table.concat(gitignore_lines, "\n")
|
||||||
utils.write_file(gitignore_path, contents)
|
utils.write_file(gitignore_path, contents)
|
||||||
end
|
end
|
||||||
@@ -47,7 +46,7 @@ public class Main {
|
|||||||
"build/"
|
"build/"
|
||||||
}
|
}
|
||||||
init_git(full_project_root, java_gitignore)
|
init_git(full_project_root, java_gitignore)
|
||||||
utils.write_file(full_project_root .. "/src/Main.java", main_java_content)
|
utils.write_file({full_project_root, "src", "Main.java"}, main_java_content)
|
||||||
return full_project_root
|
return full_project_root
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ function M.is_dir(path)
|
|||||||
return stat and stat.type == "directory"
|
return stat and stat.type == "directory"
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.write_file(path, content)
|
function M.write_file(path_segments, content)
|
||||||
|
local path = table.concat(path_segments, "/")
|
||||||
local file = assert(io.open(path, "w"), "Error creating file: " .. path)
|
local file = assert(io.open(path, "w"), "Error creating file: " .. path)
|
||||||
file:write(content)
|
file:write(content)
|
||||||
file:close()
|
file:close()
|
||||||
|
|||||||
Reference in New Issue
Block a user