Added improvements to composer commands

This commit is contained in:
Jack Wilkinson 2023-09-05 14:46:50 +01:00
parent 5d5dca2e4b
commit a65a6260d1
5 changed files with 33 additions and 8 deletions

View File

@ -3,6 +3,7 @@
namespace System\Classes\Packager;
use System\Classes\Packager\Commands\RemoveCommand;
use System\Classes\Packager\Commands\SearchCommand;
use System\Classes\Packager\Commands\ShowCommand;
use System\Classes\Packager\Commands\UpdateCommand;
use System\Classes\Packager\Commands\RequireCommand;
@ -34,10 +35,11 @@ class Composer
static::$composer = new PackagerComposer();
static::$composer->setWorkDir(base_path());
static::$composer->setCommand('show', new ShowCommand(static::$composer));
static::$composer->setCommand('update', new UpdateCommand(static::$composer));
static::$composer->setCommand('remove', new RemoveCommand(static::$composer));
static::$composer->setCommand('require', new RequireCommand(static::$composer));
static::$composer->setCommand('search', new SearchCommand(static::$composer));
static::$composer->setCommand('show', new ShowCommand(static::$composer));
static::$composer->setCommand('update', new UpdateCommand(static::$composer));
return static::$composer;
}

View File

@ -3,7 +3,7 @@
namespace System\Classes\Packager\Commands;
use Cache;
use System\Classes\Packager\ComposerFactory;
use System\Classes\Packager\Composer;
use Winter\Packager\Commands\BaseCommand;
use Winter\Packager\Exceptions\CommandException;
@ -55,7 +55,7 @@ class RemoveCommand extends BaseCommand
throw new CommandException($message);
}
Cache::forget(ComposerFactory::COMPOSER_CACHE_KEY);
Cache::forget(Composer::COMPOSER_CACHE_KEY);
return $message;
}

View File

@ -3,7 +3,7 @@
namespace System\Classes\Packager\Commands;
use Cache;
use System\Classes\Packager\ComposerFactory;
use System\Classes\Packager\Composer;
use Winter\Packager\Commands\BaseCommand;
use Winter\Packager\Exceptions\CommandException;
@ -62,7 +62,7 @@ class RequireCommand extends BaseCommand
throw new CommandException($message);
}
Cache::forget(ComposerFactory::COMPOSER_CACHE_KEY);
Cache::forget(Composer::COMPOSER_CACHE_KEY);
return $message;
}

View File

@ -0,0 +1,23 @@
<?php
namespace System\Classes\Packager\Commands;
use Cache;
use Winter\Packager\Commands\Search;
use Winter\Packager\Exceptions\CommandException;
class SearchCommand extends Search
{
public function execute()
{
$output = $this->runComposerCommand();
if ($output['code'] !== 0) {
throw new CommandException(implode(PHP_EOL, $output['output']));
}
$this->results = json_decode(implode(PHP_EOL, $output['output']), true) ?? [];
return $this;
}
}

View File

@ -3,7 +3,7 @@
namespace System\Classes\Packager\Commands;
use Cache;
use System\Classes\Packager\ComposerFactory;
use System\Classes\Packager\Composer;
use Winter\Packager\Commands\Update;
class UpdateCommand extends Update
@ -82,7 +82,7 @@ class UpdateCommand extends Update
public function execute()
{
Cache::forget(ComposerFactory::COMPOSER_CACHE_KEY);
Cache::forget(Composer::COMPOSER_CACHE_KEY);
return parent::execute();
}
}