feat(toolbox): support running from a phar self-contained installer
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/dist/
|
||||
@@ -26,8 +26,23 @@ final class Catalog
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
if (!is_dir($this->packagesDir)) {
|
||||
return $this->cache = [];
|
||||
}
|
||||
|
||||
$packages = [];
|
||||
foreach (glob($this->packagesDir . '/*/duckbrain.json') ?: [] as $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
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user