From 3b0c4da42660754aa17ad18451e2e520b2f40568 Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Mon, 15 Jun 2026 21:45:12 +0200 Subject: Write JSON file from build.lua --- lua/aotrix/build.lua | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'lua/aotrix/build.lua') diff --git a/lua/aotrix/build.lua b/lua/aotrix/build.lua index 605b736..ffd0bcd 100644 --- a/lua/aotrix/build.lua +++ b/lua/aotrix/build.lua @@ -1,4 +1,5 @@ local CURRENT_COMMAND = nil +local data_path = vim.fn.stdpath("data") ---@param command string|nil ---@return nil @@ -16,14 +17,35 @@ function executeCommandInTerminal(command) end end +function writeJsonToFile(json, filePath) + local file, error = io.open(filePath, 'r') + local content = file:read("*a") + if file ~= nil then + local decoded_json = vim.json.decode(content) + print(decoded_json["first_element"]) + end + -- local file, error = io.open(filePath, 'w') + -- if file then + -- file:write(tostring(json)) + -- file:close() + -- else + -- print("error:", error) + -- end +end + +function appendCommandsFromDirectory(commands, directory) + encoded_json = vim.json.encode({first_element = 1, second_element = 2}) + personal_commands_path = string.format("%s/personal_commands.json", + data_path) + writeJsonToFile(encoded_json, personal_commands_path) +end + local COMMANDS = {} +appendCommandsFromDirectory(COMMANDS, vim.fn.getcwd()) local personalCommands = require("aotrix.personal_commands") - COMMANDS.AddCommand = { command = function() CURRENT_COMMAND = personalCommands.createCommand(COMMANDS).command - encoded_json = vim.json.encode({first_element = 1, second_element = 2}) - print(encoded_json) return CURRENT_COMMAND() end, description = function() return "Add temporary command" end -- cgit v1.2.3