-
-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dev): add dev utility to generate snapshot for stable releases
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |