Skip to content

Commit

Permalink
feat(dev): add dev utility to generate snapshot for stable releases
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Apr 1, 2024
1 parent a5cf6a0 commit 5081890
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions lua/astronvim/dev.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
local M = {}

local astrocore = require "astrocore"

--- Helper function to generate AstroNvim snapshots (For internal use only)
---@param write? false write to AstroNvim if in `dev` mode, false to force no write
---@return table # The plugin specification table of the snapshot
function M.generate_snapshot(write)
local astronvim = assert(astrocore.get_plugin "AstroNvim")
if write ~= false then write = astronvim.dev end
local file
local prev_snapshot = require "astronvim.lazy_snapshot"
for _, plugin in ipairs(prev_snapshot) do
prev_snapshot[plugin[1]] = plugin
end
local plugins = assert(require("lazy").plugins())
table.sort(plugins, function(l, r) return l[1] < r[1] end)
local function git_commit(dir)
local commit = assert(astrocore.cmd({ "git", "-C", dir, "rev-parse", "HEAD" }, false))
if commit then return vim.trim(commit) end
end
if write then
file = assert(io.open(astronvim.dir .. "/lua/astronvim/lazy_snapshot.lua", "w"))
file:write "return {\n"
end
local snapshot = vim.tbl_map(function(plugin)
plugin = { plugin[1], commit = git_commit(plugin.dir), version = plugin.version }
if prev_snapshot[plugin[1]] and prev_snapshot[plugin[1]].version then
plugin.version = prev_snapshot[plugin[1]].version
end
if file then
file:write((" { %q, "):format(plugin[1]))
if plugin.version then
file:write(("version = %q"):format(plugin.version))
else
file:write(("commit = %q"):format(plugin.commit))
end
file:write ", optional = true },\n"
end
return plugin
end, plugins)
if file then
file:write "}\n"
file:close()
end
return snapshot
end

return M

0 comments on commit 5081890

Please sign in to comment.