updater v2.0.0

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.

Installation

Recommended: Install via installer (handles dependencies automatically):

wget run https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua updater
View on GitHub →

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:

wget https://raw.githubusercontent.com/Twijn/cc-misc/main/util/updater.lua

Examples

Using with Runtime Installation

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

Usage Examples

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()

Functions

module.setVerbose(enabled)

View source on GitHub

Enable or disable verbose output

Parameters:

module.getLog()

View source on GitHub

Get the current log entries

Returns: table Array of log entries

module.clearLog()

View source on GitHub

Clear the log

module.getLibraries()

View source on GitHub

Get information about all available libraries

Returns: table|nil List of library info or nil on error

module.getLibraryInfo(name)

View source on GitHub

Get information about a specific library

Parameters:
Returns: table|nil Library info or nil on error

module.checkUpdates()

View source on GitHub

Check for updates to installed libraries

Returns: table List of libraries with available updates

module.hasUpdate(name)

View source on GitHub

Check if a specific library has an update available

Parameters:
Returns: boolean, string|nil, string|nil Has update, current version, latest version

module.update(name, silent?)

View source on GitHub

Install or update a library

Parameters:
Returns: boolean Success

module.updateAll(silent?)

View source on GitHub

Update all installed libraries that have updates available

Parameters:
Returns: number Number of successful updates

module.listInstalled()

View source on GitHub

List all installed libraries with their versions

Returns: table List of {name, version, path} for installed libraries

module.install(name, silent?)

View source on GitHub

Install a new library with its dependencies

Parameters:
Returns: boolean Success

module.showLog()

View source on GitHub

Show the update log in a scrollable view (interactive)

module.getLogFile()

View source on GitHub

Get the log file path for the current day

Returns: string Log file path

module.fetchJSON(url)

View source on GitHub

Fetch JSON data from URL (exported version)

Parameters:
Returns: table|nil Parsed JSON data or nil on error

module.downloadFile(url, filepath, name)

View source on GitHub

Download and install a file (exported version)

Parameters:
Returns: boolean Success

ProjectBuilder:withName(name)

View source on GitHub

Set the project name

Parameters:
Returns: table Builder object for chaining

ProjectBuilder:withDiskPrefix(prefix)

View source on GitHub

Set the disk prefix for file paths

Parameters:
Returns: table Builder object for chaining

ProjectBuilder:withRequiredLibs(libs)

View source on GitHub

Add required libraries (must be installed)

Parameters:
Returns: table Builder object for chaining

ProjectBuilder:withOptionalLibs(libs)

View source on GitHub

Add optional libraries (can be toggled)

Parameters:
Returns: table Builder object for chaining

ProjectBuilder:withFiles(files)

View source on GitHub

Add project files to manage

Parameters:
Returns: table Builder object for chaining

ProjectBuilder:run()

View source on GitHub

Interactive UI for project updater

Returns: boolean Success

module.withProject(name)

View source on GitHub

Start project mode with optional name

Parameters:
Returns: table Builder object for chaining