A package updater module for CC-Misc utilities that checks for and installs updates programmatically using the GitHub API. Features: Check for available updates, programmatic package installation and updates, version comparison, dependency resolution, batch update operations, JSON API integration, project file management, interactive UI mode, and detailed logging for debugging.
Recommended: Install via installer (handles dependencies automatically):
This pattern downloads and runs libraries at runtime, automatically installing any that are missing:
-- Auto-install and require libraries
local libs = {"updater"} -- Add more libraries as needed
local libDir = (fs.exists("disk") and "disk/lib/" or "/lib/")
local allExist = true
for _, lib in ipairs(libs) do
if not fs.exists(libDir .. lib .. ".lua") then
allExist = false
break
end
end
if not allExist then
shell.run("wget", "run", "https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua", table.unpack(libs))
end
local updater = require(libDir .. "updater")
-- Use the library
-- (your code here)
Alternative: Direct download via wget:
This example shows how to download and use libraries with automatic installation:
-- Auto-install and require libraries
local libs = {"updater"} -- Add more libraries as needed
local libDir = (fs.exists("disk") and "disk/lib/" or "/lib/")
local allExist = true
for _, lib in ipairs(libs) do
if not fs.exists(libDir .. lib .. ".lua") then
allExist = false
break
end
end
if not allExist then
shell.run("wget", "run", "https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua", table.unpack(libs))
end
local updater = require(libDir .. "updater")
-- Use the library
local updater = require("updater")
-- Check for updates
local updates = updater.checkUpdates()
for _, update in ipairs(updates) do
print(update.name .. ": " .. update.current .. " -> " .. update.latest)
end
-- Update a specific package
updater.update("s")
-- Update all packages
updater.updateAll()
-- Enable verbose mode for debugging
updater.setVerbose(true)
-- Project mode (for application updaters)
updater.withProject("AutoCrafter")
.withRequiredLibs({"s", "tables", "log"})
.withOptionalLibs({"formui", "cmd"})
.withFiles({
{url = "https://...", path = "server.lua", required = true},
{url = "https://...", path = "lib/ui.lua", required = true},
})
.run()
module.setVerbose(enabled)Enable or disable verbose output
enabled (boolean): Whether to enable verbose outputmodule.getLog()Get the current log entries
module.getLibraries()Get information about all available libraries
module.getLibraryInfo(name)Get information about a specific library
name (string): Library namemodule.checkUpdates()Check for updates to installed libraries
module.hasUpdate(name)Check if a specific library has an update available
name (string): Library namemodule.update(name, silent?)Install or update a library
name (string): Library namesilent? (boolean): Suppress output messagesmodule.updateAll(silent?)Update all installed libraries that have updates available
silent? (boolean): Suppress output messagesmodule.listInstalled()List all installed libraries with their versions
module.install(name, silent?)Install a new library with its dependencies
name (string): Library namesilent? (boolean): Suppress output messagesmodule.getLogFile()Get the log file path for the current day
module.fetchJSON(url)Fetch JSON data from URL (exported version)
url (string): URL to fetchmodule.downloadFile(url, filepath, name)Download and install a file (exported version)
url (string): The URL to download fromfilepath (string): The local file path to save toname (string?): Optional name for loggingProjectBuilder:withName(name)Set the project name
name (string): Project name (displayed in header)ProjectBuilder:withDiskPrefix(prefix)Set the disk prefix for file paths
prefix (string): Disk prefix (e.g., "disk/")ProjectBuilder:withRequiredLibs(libs)Add required libraries (must be installed)
libs (table): Array of library namesProjectBuilder:withOptionalLibs(libs)Add optional libraries (can be toggled)
libs (table): Array of library namesProjectBuilder:withFiles(files)Add project files to manage
files (table): Array of {url, path, required?, name?, category?, isConfig?}ProjectBuilder:run()Interactive UI for project updater
module.withProject(name)Start project mode with optional name
name (string?): Project name