Files
cell/update.ce
2025-12-27 13:51:11 -06:00

93 lines
2.7 KiB
Plaintext

// cell update - Update packages from remote sources
//
// This command checks for updates to all packages and downloads new versions.
// For local packages, ensures the symlink is correct.
// For remote packages, checks the remote for new commits.
//
// Usage:
// cell update - Update all packages
// cell update <package> - Update a specific package
var shop = use('internal/shop')
var fd = use('fd')
var target_pkg = null
// Parse arguments
for (var i = 0; i < args.length; i++) {
if (args[i] == '--help' || args[i] == '-h') {
log.console("Usage: cell update [package]")
log.console("Update packages from remote sources.")
log.console("")
log.console("Arguments:")
log.console(" package Optional package name to update. If omitted, updates all.")
log.console("")
log.console("This command checks for updates to all packages and downloads")
log.console("new versions. For local packages, ensures the symlink is correct.")
$stop()
} else if (!args[i].startsWith('-')) {
target_pkg = args[i]
// Resolve relative paths to absolute paths
if (target_pkg == '.' || target_pkg.startsWith('./') || target_pkg.startsWith('../') || fd.is_dir(target_pkg)) {
var resolved = fd.realpath(target_pkg)
if (resolved) {
target_pkg = resolved
}
}
}
}
function update_and_fetch(pkg)
{
var lock = shop.load_lock()
var old_entry = lock[pkg]
var old_commit = old_entry ? old_entry.commit : null
var new_entry = shop.update(pkg)
if (new_entry) {
if (new_entry.commit) {
var old_str = old_commit ? old_commit.substring(0, 8) : "(new)"
log.console(" " + pkg + " " + old_str + " -> " + new_entry.commit.substring(0, 8))
shop.fetch(pkg)
} else {
// Local package - just ensure symlink is correct
log.console(" " + pkg + " (local)")
}
shop.extract(pkg)
shop.build_package_scripts(pkg)
return true
}
return false
}
if (target_pkg) {
if (update_and_fetch(target_pkg))
log.console("Updated " + target_pkg + ".")
else
log.console(target_pkg + " is up to date.")
} else {
var packages = shop.list_packages()
var pkg_count = packages.length
log.console("Checking for updates (" + text(pkg_count) + " package" + (pkg_count == 1 ? "" : "s") + ")...")
var updated_count = 0
for (var i = 0; i < packages.length; i++) {
var pkg = packages[i]
if (pkg == 'core') continue
if (update_and_fetch(pkg)) {
updated_count++
}
}
if (updated_count > 0) {
log.console("Updated " + text(updated_count) + " package" + (updated_count == 1 ? "" : "s") + ".")
} else {
log.console("All packages are up to date.")
}
}
$stop()