feat(config): lazyvim.json is now versioned and migrates to a newer version when needed

This commit is contained in:
Folke Lemaitre 2023-10-12 21:45:32 +02:00
parent 8e71968c2b
commit c9892652d2
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 34 additions and 14 deletions

View file

@ -128,6 +128,7 @@ local defaults = {
}
M.json = {
version = 1,
data = {
version = nil, ---@type string?
news = {}, ---@type table<string, string>
@ -144,24 +145,13 @@ function M.json.load()
local ok, json = pcall(vim.json.decode, data, { luanil = { object = true, array = true } })
if ok then
M.json.data = vim.tbl_deep_extend("force", M.json.data, json or {})
if M.json.data.hashes then
---@diagnostic disable-next-line: no-unknown
M.json.data.hashes = nil
M.json.save()
if M.json.data.version ~= M.json.version then
Util.json.migrate()
end
end
end
end
function M.json.save()
local path = vim.fn.stdpath("config") .. "/lazyvim.json"
local f = io.open(path, "w")
if f then
f:write(Util.json.encode(M.json.data))
f:close()
end
end
---@type LazyVimOptions
local options