mirror of
https://github.com/opdavies/versa.git
synced 2025-02-02 07:57:32 +00:00
Extract a method to create the Process
This commit is contained in:
parent
a0ff721782
commit
ec9ddbaf9c
67
versa
67
versa
|
@ -41,6 +41,20 @@ $application->addOption(
|
|||
default: '.',
|
||||
);
|
||||
|
||||
/**
|
||||
* @param non-empty-array<int, non-empty-string> $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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue