78 lines
2.2 KiB
Plaintext
78 lines
2.2 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('shop')
|
|
|
|
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]
|
|
}
|
|
}
|
|
|
|
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 && new_entry.commit) {
|
|
log.console(" " + pkg + " " + old_commit.substring(0, 8) + " -> " + new_entry.commit.substring(0, 8))
|
|
shop.fetch(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()
|