From e371c801fed71bb73bc7c027e3de5ad2a6116673 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 20 Apr 2026 19:30:28 +0200 Subject: add tests and fix path resolution bug --- src/lib/builder.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/lib/builder.lua') diff --git a/src/lib/builder.lua b/src/lib/builder.lua index adb55c8..1a9b0af 100644 --- a/src/lib/builder.lua +++ b/src/lib/builder.lua @@ -12,6 +12,10 @@ function Builder:from_template(path) source = path, } + if not builder.template or getmetatable(builder.template) ~= Template then + error('invalid template') + end + builder.source_directory = builder.source:parent() setmetatable(builder, self) @@ -41,13 +45,13 @@ function Builder:entries() for _, value in ipairs(self.template.files) do entries[#entries + 1] = { - path = Path:new(value.path), + path = self.source_directory / value.path, env = value.env, } end for _, value in ipairs(self.template.directories) do - for entry in Path:new(value.path):children() do + for entry in (self.source_directory / value.path):children() do entries[#entries + 1] = { path = entry, env = value.env, @@ -68,8 +72,8 @@ function Builder:build(args) for entry in self:entries() do instance:register( - entry.path, - entry.path.is_directory and nil or self:process_file(entry) + entry.path:relative_to_parent(self.source_directory), + not entry.path:is_directory() and self:process_file(entry) or nil ) end @@ -77,11 +81,11 @@ function Builder:build(args) end function Builder:process_file(file) - if not (self.source_directory / file.path):exists() then + if not file.path:exists() then error(tostring(file.path) .. ' does not exist.') end - local f = (self.source_directory / file.path):open("r") + local f = file.path:open("r") local raw = f:read("*all") f:close() -- cgit v1.2.3-70-g09d2