diff --git a/versa b/versa index d6370a2..7ce555b 100755 --- a/versa +++ b/versa @@ -41,6 +41,20 @@ $application->addOption( default: '.', ); +/** + * @param non-empty-array $command + * @param string $workingDir + * @param ?string $extraArgs + */ +function buildProcess(array $command, string $workingDir, ?string $extraArgs = null): Process +{ + $process = new Process(command: array_filter([...$command, $extraArgs])); + $process->setTty(true); + $process->setWorkingDirectory($workingDir); + + return $process; +} + $application->setCode(function (InputInterface $input): int { $extraArgs = $input->getOption('extra-args'); $workingDir = $input->getOption('working-dir'); @@ -52,11 +66,25 @@ $application->setCode(function (InputInterface $input): int { // TODO: only allow defined commands - build, install, test, run. switch ($input->getArgument('command')) { case 'build': + switch ($input->getOption('type')) { + case ProjectType::Drupal->value: + if ($isDockerCompose) { + $process = buildProcess( + command: ['docker', 'compose', 'build'], + extraArgs: $extraArgs, + workingDir: $workingDir, + ); + $process->run(); + } + break; + } switch ($input->getOption('type')) { case ProjectType::Sculpin->value: - $process = new Process(command: array_filter(['./vendor/bin/sculpin', 'generate', $extraArgs])); - $process->setTty(true); - $process->setWorkingDirectory($workingDir); + $process = buildProcess( + command: ['./vendor/bin/sculpin', 'generate'], + extraArgs: $extraArgs, + workingDir: $workingDir, + ); $process->run(); break; } @@ -64,26 +92,32 @@ $application->setCode(function (InputInterface $input): int { case 'install': // TODO: Composer in Docker Compose? - $process = new Process(command: array_filter(['composer', 'install', $extraArgs])); - $process->setTty(true); - $process->setWorkingDirectory($workingDir); + $process = buildProcess( + command: ['composer', 'install'], + extraArgs: $extraArgs, + workingDir: $workingDir, + ); $process->run(); break; case 'run': if ($isDockerCompose) { - $process = new Process(command: array_filter(['docker', 'compose', 'up', $extraArgs])); + $process = buildProcess( + command: ['docker', 'compose', 'up'], + extraArgs: $extraArgs, + workingDir: $workingDir, + ); $process->setTimeout(null); - $process->setTty(true); - $process->setWorkingDirectory($workingDir); $process->run(); } else { switch ($input->getOption('type')) { case ProjectType::Sculpin->value: - $process = new Process(command: array_filter(['./vendor/bin/sculpin', 'generate', '--server', '--watch', $extraArgs])); + $process = buildProcess( + command: ['./vendor/bin/sculpin', 'generate', '--server', '--watch'], + extraArgs: $extraArgs, + workingDir: $workingDir, + ); $process->setTimeout(null); - $process->setTty(true); - $process->setWorkingDirectory($workingDir); $process->run(); break; } @@ -93,10 +127,11 @@ $application->setCode(function (InputInterface $input): int { case 'test': // TODO: PHPUnit, Pest or ParaTest. // TODO: commands in Docker Compose? - $process = new Process(command: array_filter(['./vendor/bin/phpunit', $extraArgs])); - $process->setTty(true); - $process->setWorkingDirectory($workingDir); - $process->run(); + $process = buildProcess( + command: ['./vendor/bin/phpunit'], + extraArgs: $extraArgs, + workingDir: $workingDir, + ); break; }