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
3 changed files with 34 additions and 14 deletions

View File

@ -1,3 +1,4 @@
local Config = require("lazyvim.config")
local Util = require("lazyvim.util")
---@class lazyvim.util.json
@ -45,4 +46,33 @@ function M.encode(value)
return encode(value, "")
end
function M.save()
local path = vim.fn.stdpath("config") .. "/lazyvim.json"
local f = io.open(path, "w")
if f then
f:write(Util.json.encode(Config.json.data))
f:close()
end
end
function M.migrate()
Util.info("Migrating `lazyvim.json` to version `" .. Config.json.version .. "`")
local json = Config.json
-- v0
if not json.data.version then
if json.data.hashes then
---@diagnostic disable-next-line: no-unknown
json.data.hashes = nil
end
json.data.extras = vim.tbl_map(function(extra)
return "lazyvim.plugins.extras." .. extra
end, json.data.extras or {})
end
json.data.version = Config.json.version
M.save()
end
return M