From 1886f10211dcfaa68cca2bda3ef45cece916e03b Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Wed, 3 Dec 2025 19:03:01 -0600 Subject: [PATCH] add list and ls functions --- scripts/list.ce | 96 +++++++++++++++++-------------------------------- scripts/ls.ce | 34 ++++++++++++++++++ scripts/shop.cm | 56 +++++++++++++++++++++++++++-- 3 files changed, 120 insertions(+), 66 deletions(-) create mode 100644 scripts/ls.ce diff --git a/scripts/list.ce b/scripts/list.ce index 5a07844d..8d855cd1 100644 --- a/scripts/list.ce +++ b/scripts/list.ce @@ -1,75 +1,43 @@ +// 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") - return +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) { - 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") - } +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) } } -$_.stop() \ No newline at end of file +$_.stop() diff --git a/scripts/ls.ce b/scripts/ls.ce new file mode 100644 index 00000000..d2752a57 --- /dev/null +++ b/scripts/ls.ce @@ -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() diff --git a/scripts/shop.cm b/scripts/shop.cm index e55131f6..c026909c 100644 --- a/scripts/shop.cm +++ b/scripts/shop.cm @@ -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 \ No newline at end of file