From ddf0f41582cc0fd13dcb6f2a23f21904ac396979 Mon Sep 17 00:00:00 2001 From: "Harrison (Harry) Cramer" <32515581+harrisoncramer@users.noreply.github.com> Date: Tue, 12 Nov 2024 08:58:33 -0500 Subject: [PATCH] fix: plugin failing to build on Windows (#419) --- cmd/app/emoji.go | 6 +++--- {config => cmd/config}/emojis.json | 0 lua/gitlab/emoji.lua | 6 ++++-- lua/gitlab/server.lua | 20 ++++++++++---------- 4 files changed, 17 insertions(+), 15 deletions(-) rename {config => cmd/config}/emojis.json (100%) diff --git a/cmd/app/emoji.go b/cmd/app/emoji.go index 2dbfe6fb..5b2db76e 100644 --- a/cmd/app/emoji.go +++ b/cmd/app/emoji.go @@ -7,7 +7,7 @@ import ( "io" "net/http" "os" - "path" + "path/filepath" "strconv" "strings" @@ -157,8 +157,8 @@ func attachEmojis(a *data, fr FileReader) error { return err } - binPath := path.Dir(e) - filePath := fmt.Sprintf("%s/config/emojis.json", binPath) + binPath := filepath.Dir(e) + filePath := filepath.Join(binPath, "config", "emojis.json") reader, err := fr.ReadFile(filePath) diff --git a/config/emojis.json b/cmd/config/emojis.json similarity index 100% rename from config/emojis.json rename to cmd/config/emojis.json diff --git a/lua/gitlab/emoji.lua b/lua/gitlab/emoji.lua index c7fc644b..342de148 100644 --- a/lua/gitlab/emoji.lua +++ b/lua/gitlab/emoji.lua @@ -10,8 +10,10 @@ local M = { } M.init = function() - local bin_path = state.settings.bin_path - local emoji_path = bin_path + local root_path = state.settings.root_path + local emoji_path = root_path + .. state.settings.file_separator + .. "cmd" .. state.settings.file_separator .. "config" .. state.settings.file_separator diff --git a/lua/gitlab/server.lua b/lua/gitlab/server.lua index aa739b45..6e77c8ac 100644 --- a/lua/gitlab/server.lua +++ b/lua/gitlab/server.lua @@ -80,8 +80,10 @@ end M.build = function(override) local file_path = u.current_file_path() local parent_dir = vim.fn.fnamemodify(file_path, ":h:h:h:h") - state.settings.bin_path = parent_dir - state.settings.bin = parent_dir .. (u.is_windows() and "\\bin.exe" or "/bin") + + local bin_name = u.is_windows() and "bin.exe" or "bin" + state.settings.root_path = parent_dir + state.settings.bin = parent_dir .. u.path_separator .. "cmd" .. u.path_separator .. bin_name if not override then local binary_exists = vim.loop.fs_stat(state.settings.bin) @@ -90,17 +92,15 @@ M.build = function(override) end end - local cmd = u.is_windows() and "cd %s\\cmd && go build -o bin.exe && move bin.exe ..\\" - or "cd %s/cmd && go build -o bin && mv bin ../bin" + local res = vim + .system({ "go", "build", "-o", bin_name }, { cwd = state.settings.root_path .. u.path_separator .. "cmd" }) + :wait() - local command = string.format(cmd, state.settings.bin_path) - local null = u.is_windows() and " >NUL" or " > /dev/null" - local installCode = os.execute(command .. null) - if installCode ~= 0 then - u.notify("Could not install gitlab.nvim!", vim.log.levels.ERROR) + if res.code ~= 0 then + u.notify(string.format("Failed to install with status code %d:\n%s", res.code, res.stderr), vim.log.levels.ERROR) return false end - u.notify("Gitlab.nvim installed successfully!", vim.log.levels.INFO) + u.notify("Installed successfully!", vim.log.levels.INFO) return true end