diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..178135c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dist/ diff --git a/packages/commands/src/Toolbox/Catalog.php b/packages/commands/src/Toolbox/Catalog.php index 6e5bbbf..f3aff6a 100644 --- a/packages/commands/src/Toolbox/Catalog.php +++ b/packages/commands/src/Toolbox/Catalog.php @@ -26,9 +26,24 @@ final class Catalog return $this->cache; } + if (!is_dir($this->packagesDir)) { + return $this->cache = []; + } + $packages = []; - foreach (glob($this->packagesDir . '/*/duckbrain.json') ?: [] as $manifestPath) { - $manifest = Manifest::fromFile($manifestPath); + // Se enumera con DirectoryIterator (no glob) para que funcione también + // bajo el stream wrapper `phar://` del instalador autocontenido. + foreach (new \DirectoryIterator($this->packagesDir) as $entry) { + if (!$entry->isDir() || $entry->isDot()) { + continue; + } + + $manifestPath = $entry->getPathname() . '/duckbrain.json'; + if (!is_file($manifestPath)) { + continue; + } + + $manifest = Manifest::fromFile($manifestPath); $packages[$manifest->name] = $manifest; } diff --git a/packages/commands/src/Toolbox/Commands/Command.php b/packages/commands/src/Toolbox/Commands/Command.php index ec039c0..a67d151 100644 --- a/packages/commands/src/Toolbox/Commands/Command.php +++ b/packages/commands/src/Toolbox/Commands/Command.php @@ -69,7 +69,7 @@ abstract class Command implements CommandInterface protected function toolboxDir(array $options): string { - return rtrim($this->option($options, 'toolbox', getcwd() ?: '.') ?? '.', '/'); + return rtrim($this->option($options, 'toolbox') ?? Config::toolboxDir(), '/'); } protected function rootCore(array $options, string $root): ?string diff --git a/packages/commands/src/Toolbox/Config.php b/packages/commands/src/Toolbox/Config.php index bbf229b..776743d 100644 --- a/packages/commands/src/Toolbox/Config.php +++ b/packages/commands/src/Toolbox/Config.php @@ -22,6 +22,30 @@ final class Config ?: 'git@git.kj2.me:kj/duckbrain.git'; } + /** + * Raíz del toolbox (la que contiene `packages/`). Prioridad: variable de + * entorno, raíz del phar si corre dentro de uno, raíz del repositorio, cwd. + */ + public static function toolboxDir(): string + { + $override = self::env('DUCKBRAIN_TOOLBOX_DIR'); + if ($override !== '') { + return rtrim($override, '/'); + } + + $phar = \Phar::running(true); + if ($phar !== '') { + return rtrim($phar, '/'); + } + + $repo = \dirname(__DIR__, 4); + if (is_dir($repo . '/packages')) { + return $repo; + } + + return getcwd() ?: '.'; + } + public static function updateUrl(): string { return self::env('DUCKBRAIN_UPDATE_URL')