diff --git a/integrations/lua-api.lua b/integrations/lua-api.lua index 0d15243..b543bce 100644 --- a/integrations/lua-api.lua +++ b/integrations/lua-api.lua @@ -10,10 +10,51 @@ local cache = { ttl = 300 -- 5 minutes default TTL } +-- Find merkwerk binary using universal detection pattern +local function find_merkwerk_binary() + -- Check development binary + local dev_handle = io.popen("test -x './bin/merkwerk' && echo './bin/merkwerk' 2>/dev/null") + if dev_handle then + local dev_result = dev_handle:read("*line") + dev_handle:close() + if dev_result and dev_result ~= "" then + return dev_result + end + end + + -- Check installed binary + local inst_handle = io.popen("test -x '/usr/local/bin/merkwerk' && echo '/usr/local/bin/merkwerk' 2>/dev/null") + if inst_handle then + local inst_result = inst_handle:read("*line") + inst_handle:close() + if inst_result and inst_result ~= "" then + return inst_result + end + end + + -- Check PATH + local path_handle = io.popen("command -v merkwerk 2>/dev/null") + if path_handle then + local path_result = path_handle:read("*line") + path_handle:close() + if path_result and path_result ~= "" then + return "merkwerk" + end + end + + return nil +end + -- Execute merkwerk command and return result local function execute_merkwerk(args) args = args or "info --json" - local command = "./tools/merkwerk/bin/merkwerk " .. args .. " 2>/dev/null" + + local merkwerk_cmd = find_merkwerk_binary() + if not merkwerk_cmd then + return nil, "merkwerk binary not found" + end + + local command = merkwerk_cmd .. " " .. args .. " 2>/dev/null" local handle = io.popen(command) if not handle then