add list and ls functions

This commit is contained in:
2025-12-03 19:03:01 -06:00
parent c8ce152ade
commit 1886f10211
3 changed files with 120 additions and 66 deletions

View File

@@ -1,74 +1,42 @@
// list installed packages
// if args[0] is a package, list its dependencies
var shop = use('shop')
var io = use('fd')
// Initialize shop if needed
if (!shop.init()) {
log.error("Failed to initialize .cell directory")
var ctx = null
var pkg_name = "Local"
var target_alias = null
if (args && args.length > 0) {
target_alias = args[0]
// Resolve alias from local config
ctx = shop.get_normalized_module(target_alias, null)
if (!ctx) {
log.console("Package '" + target_alias + "' not found in dependencies.")
$_.stop()
return
}
pkg_name = target_alias + " (" + ctx + ")"
}
// Load configuration
var config = shop.load_config()
if (!config) {
log.console("No modules installed (no cell.toml found)")
return
var deps = shop.dependencies(ctx)
if (target_alias) {
log.console("Dependencies for " + pkg_name + ":")
} else {
log.console("Installed Packages (Local):")
}
// List dependencies
if (!config.dependencies || Object.keys(config.dependencies).length == 0) {
log.console("No modules installed")
return
}
var aliases = []
for (var k in deps) aliases.push(k)
aliases.sort()
log.console("Installed modules:")
log.console("")
// Display each dependency
for (var alias in config.dependencies) {
var locator = config.dependencies[alias]
var parsed = shop.parse_locator(locator)
if (parsed) {
if (aliases.length == 0) {
log.console(" (none)")
} else {
for (var i = 0; i < aliases.length; i++) {
var alias = aliases[i]
var locator = deps[alias]
log.console(" " + alias + " -> " + locator)
// Check if module directory exists
var module_dir = '.cell/modules/' + alias + '@' + parsed.version
if (io.is_dir(module_dir)) {
log.console(" ✓ Downloaded to " + module_dir)
} else {
log.console(" ✗ Not downloaded (run 'cell get " + locator + "')")
}
// Check if vendored
var vendor_dir = 'modules/' + alias + '@' + parsed.version
if (io.is_dir(vendor_dir)) {
log.console(" ✓ Vendored to " + vendor_dir)
}
// Check if compiled
var build_dir = '.cell/build/' + alias + '@' + parsed.version
if (io.is_dir(build_dir)) {
log.console(" ✓ Compiled to " + build_dir)
}
} else {
log.console(" " + alias + " -> " + locator + " (invalid locator)")
}
log.console("")
}
// Show patches if any
if (config.patches && Object.keys(config.patches).length > 0) {
log.console("Patches:")
for (var alias in config.patches) {
var patch_file = config.patches[alias]
log.console(" " + alias + " -> " + patch_file)
if (io.is_file('.cell/' + patch_file)) {
log.console(" ✓ Patch file exists")
} else {
log.console(" ✗ Patch file missing")
}
}
}

34
scripts/ls.ce Normal file
View File

@@ -0,0 +1,34 @@
// list modules and actors in a package
// if args[0] is a package alias, list that one
// otherwise, list the local one
var shop = use('shop')
var ctx = null
var pkg_name = "Local"
if (args && args.length > 0) {
var alias = args[0]
ctx = shop.get_normalized_module(alias, null)
if (!ctx) {
log.console("Package '" + alias + "' not found in dependencies.")
$_.stop()
return
}
pkg_name = alias + " (" + ctx + ")"
}
var modules = shop.list_modules(ctx)
log.console("Modules in " + pkg_name + ":")
modules.sort()
if (modules.length == 0) {
log.console(" (none)")
} else {
for (var i = 0; i < modules.length; i++) {
log.console(" " + modules[i])
}
}
$_.stop()

View File

@@ -1071,13 +1071,65 @@ Shop.build = function() {
// Get all declared dependencies as a map of alias -> locator
Shop.get_dependencies = function() {
var config = Shop.load_config()
return Shop.dependencies(null)
}
// Get dependencies for a specific context (package canonical path)
// If ctx is null, returns dependencies for the local project
Shop.dependencies = function(ctx) {
var config = Shop.load_config(ctx)
if (!config || !config.dependencies) {
return {}
}
return config.dependencies
}
// List all .cm and .ce files in a package
// If ctx is null, lists local files
// If ctx is a canonical path, lists files in that module
Shop.list_modules = function(ctx) {
var dir
if (ctx) {
dir = '.cell/modules/' + ctx
} else {
dir = '.'
}
var files = []
// Helper to walk directory
var walk = function(current_dir, current_prefix) {
var list = fd.readdir(current_dir)
if (!list) return
for (var i = 0; i < list.length; i++) {
var item = list[i]
if (item == '.' || item == '..') continue
if (item.startsWith('.')) continue // Skip hidden files/dirs like .cell, .git
if (item == 'build' || item == 'build_dbg' || item == 'build_release' || item == 'build_web' || item == 'build_fast') continue
var full_path = current_dir + "/" + item
var rel_path = current_prefix ? current_prefix + "/" + item : item
var st = fd.stat(full_path)
if (st.isDirectory) {
walk(full_path, rel_path)
} else {
if (rel_path.endsWith('.cm') || rel_path.endsWith('.ce')) {
files.push(rel_path)
}
}
}
}
if (fd.is_dir(dir)) {
walk(dir, "")
}
return files
}
// Resolve a module path given a package context
// Returns { path, package_name } or null if not found
// Resolution order:
@@ -1142,5 +1194,5 @@ Shop.resolve_module = function(module_name, package_name, is_file_fn) {
return null
}
Shop.get_normalized_module = get_normalized_module
return Shop