feat(toolbox): support running from a phar self-contained installer

This commit is contained in:
kj
2026-10-05 15:28:04 -03:00
parent b7799f9fff
commit 0220e97109
4 changed files with 43 additions and 3 deletions
+1
View File
@@ -0,0 +1 @@
/dist/
+17 -2
View File
@@ -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;
}
@@ -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
+24
View File
@@ -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')