♻️ refactor(full-scope)!: major revision refactoring

Code layout has been changed and improoved. Annotations are added for documentation. Automated through utility functions and data tables

BREAKING CHANGE: Tested from clean. Now properly uses LuaRocks to install dependencies.
This commit is contained in:
2024-09-04 16:07:12 -04:00
parent b2731cff01
commit 273580f533
48 changed files with 1962 additions and 750 deletions
+15 -8
View File
@@ -1,8 +1,11 @@
---@module "utils.cache_stats"
--- This module provides a function to update the cached statistics.
-- ╭─────────────────────────────────────────────────────────╮
-- │ Cache Stats │
-- ╰─────────────────────────────────────────────────────────╯
local M = {}
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
-- Options can be set with:
-- vim.g.stats_wakatime = true|false (default: true)
@@ -14,6 +17,10 @@ local M = {}
local config_dir = vim.fn.stdpath("config") --[[@as string]]
local cache_script = vim.fs.joinpath(config_dir, "scripts", "update_cache.sh")
-- Path to the Neovim cache directory
_G.cache_stats_dir = -- Cache directory
vim.fn.stdpath("cache") --[[@as string]]
-- Flag to check if the script has already been run
local script_run_once = false
@@ -32,13 +39,9 @@ for _, player in ipairs(vim.g.stats_ignored_players or {}) do
table.insert(ignored_players, player)
end
if vim.g.stats_music == nil then
vim.g.stats_music = true
end
if vim.g.stats_wakatime == nil then
vim.g.stats_wakatime = true
end
-- Set the default values for the options
vim.g.stats_music = vim.g.stats_music or true
vim.g.stats_wakatime = vim.g.stats_wakatime or true
--- Function to run the cache script
---@return boolean|number pid The pid of the script
@@ -47,6 +50,10 @@ function M.setup_script()
-- Build the arguments for the cache script
local args = { cache_script }
-- Add the --cache-dir option
table.insert(args, "--cache-dir")
table.insert(args, _G.cache_stats_dir)
-- Add the --ignore option with the ignored players
if #ignored_players > 0 then
table.insert(args, "--ignore")
@@ -77,7 +84,7 @@ function M.setup_script()
return false
end
-- Run the setup script only once
-- Run the setup script
M.setup_script()
return M