Files
cell/list.ce
2026-01-15 18:16:34 -06:00

171 lines
4.0 KiB
Plaintext

// cell list [<scope>] - List packages and dependencies
//
// Usage:
// cell list List dependencies of current package
// cell list shop List all packages in shop with status
// cell list <locator> List dependency tree for a package
var shop = use('internal/shop')
var pkg = use('package')
var link = use('link')
var fd = use('fd')
var mode = 'local'
var target_pkg = null
if (args && args.length > 0) {
if (args[0] == 'shop') {
mode = 'shop'
} else if (args[0] == '--help' || args[0] == '-h') {
log.console("Usage: cell list [<scope>]")
log.console("")
log.console("List packages and dependencies.")
log.console("")
log.console("Scopes:")
log.console(" (none) List dependencies of current package")
log.console(" shop List all packages in shop with status")
log.console(" <locator> List dependency tree for a package")
$stop()
} else {
mode = 'package'
target_pkg = args[0]
// Resolve local 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
}
}
}
}
var links = link.load()
var lock = shop.load_lock()
function print_deps(ctx, indent) {
indent = indent || ""
var deps
try {
deps = pkg.dependencies(ctx)
} catch (e) {
log.console(indent + " (could not read dependencies)")
return
}
if (!deps) {
log.console(indent + " (none)")
return
}
var aliases = []
for (var k in deps) aliases.push(k)
aliases.sort()
if (aliases.length == 0) {
log.console(indent + " (none)")
return
}
for (var i = 0; i < aliases.length; i++) {
var alias = aliases[i]
var locator = deps[alias]
var link_target = links[locator]
var lock_entry = lock[locator]
var line = indent + " " + alias
if (alias != locator) {
line += " -> " + locator
}
// Add status indicators
var status = []
if (link_target) {
status.push("linked -> " + link_target)
}
if (lock_entry && lock_entry.commit) {
status.push("@" + lock_entry.commit.substring(0, 8))
}
if (lock_entry && lock_entry.type == 'local') {
status.push("local")
}
if (!lock_entry) {
status.push("not installed")
}
if (status.length > 0) {
line += " [" + text(status, ", ") + "]"
}
log.console(line)
}
}
if (mode == 'local') {
log.console("Dependencies:")
print_deps(null)
} else if (mode == 'package') {
log.console("Dependencies for " + target_pkg + ":")
print_deps(target_pkg)
} else if (mode == 'shop') {
log.console("Shop packages:")
log.console("")
var packages = shop.list_packages()
if (packages.length == 0) {
log.console(" (none)")
} else {
packages.sort()
// Group by type
var local_pkgs = []
var linked_pkgs = []
var remote_pkgs = []
for (var p of packages) {
if (p == 'core') continue
var lock_entry = lock[p]
var link_target = links[p]
if (link_target) {
linked_pkgs.push(p)
} else if (lock_entry && lock_entry.type == 'local') {
local_pkgs.push(p)
} else {
remote_pkgs.push(p)
}
}
if (linked_pkgs.length > 0) {
log.console("Linked packages:")
for (var p of linked_pkgs) {
var target = links[p]
log.console(" " + p + " -> " + target)
}
log.console("")
}
if (local_pkgs.length > 0) {
log.console("Local packages:")
for (var p of local_pkgs) {
log.console(" " + p)
}
log.console("")
}
if (remote_pkgs.length > 0) {
log.console("Remote packages:")
for (var p of remote_pkgs) {
var lock_entry = lock[p]
var commit = lock_entry && lock_entry.commit ? " @" + lock_entry.commit.substring(0, 8) : ""
log.console(" " + p + commit)
}
log.console("")
}
log.console("Total: " + text(packages.length) + " package(s)")
}
}
$stop()