Skip to content

Commit

Permalink
Add option for processing packages with its sub-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
costasovo committed Oct 17, 2018
1 parent b9b070f commit ab0af7b
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Console/Commands/Compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@
use CoenJacobs\Mozart\Mover;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class Compose extends Command
{
protected function configure()
{
$this->setName('compose');
$this->addOption(
'with_dependencies',
null,
InputOption::VALUE_OPTIONAL,
'Process also sub-dependencies.',
false
);
$this->setDescription('Composes all dependencies as a package inside a WordPress plugin.');
$this->setHelp('');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$with_dependencies = $input->getOption('with_dependencies') !== false;
$workingDir = getcwd();

$config = json_decode(file_get_contents($workingDir . '/composer.json'));
Expand All @@ -27,10 +36,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
$mover = new Mover($workingDir, $config);
$mover->deleteTargetDirs();

foreach ($config->packages as $package_slug) {
$packages = new \ArrayIterator($config->packages);
$processed_packages = [];

foreach ($packages as $package_slug) {
$package = new Package($workingDir . '/vendor/' . $package_slug);
$package->findAutoloaders();
$mover->movePackage($package);
if (!$with_dependencies) {
continue;
}
$package->findDependencies($workingDir . '/vendor');
$processed_packages[] = $package;
foreach ($package->dependencies as $dependency) {
if (!in_array($dependency, $packages->getArrayCopy())) {
$packages->append($dependency);
};
}
}

$mover->replaceClassmapNames();
Expand Down

0 comments on commit ab0af7b

Please sign in to comment.