mirror of
https://github.com/opdavies/versa.git
synced 2025-02-08 18:35:03 +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: '.',
|
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 {
|
$application->setCode(function (InputInterface $input): int {
|
||||||
$extraArgs = $input->getOption('extra-args');
|
$extraArgs = $input->getOption('extra-args');
|
||||||
$workingDir = $input->getOption('working-dir');
|
$workingDir = $input->getOption('working-dir');
|
||||||
|
@ -52,11 +66,25 @@ $application->setCode(function (InputInterface $input): int {
|
||||||
// TODO: only allow defined commands - build, install, test, run.
|
// TODO: only allow defined commands - build, install, test, run.
|
||||||
switch ($input->getArgument('command')) {
|
switch ($input->getArgument('command')) {
|
||||||
case 'build':
|
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')) {
|
switch ($input->getOption('type')) {
|
||||||
case ProjectType::Sculpin->value:
|
case ProjectType::Sculpin->value:
|
||||||
$process = new Process(command: array_filter(['./vendor/bin/sculpin', 'generate', $extraArgs]));
|
$process = buildProcess(
|
||||||
$process->setTty(true);
|
command: ['./vendor/bin/sculpin', 'generate'],
|
||||||
$process->setWorkingDirectory($workingDir);
|
extraArgs: $extraArgs,
|
||||||
|
workingDir: $workingDir,
|
||||||
|
);
|
||||||
$process->run();
|
$process->run();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -64,26 +92,32 @@ $application->setCode(function (InputInterface $input): int {
|
||||||
|
|
||||||
case 'install':
|
case 'install':
|
||||||
// TODO: Composer in Docker Compose?
|
// TODO: Composer in Docker Compose?
|
||||||
$process = new Process(command: array_filter(['composer', 'install', $extraArgs]));
|
$process = buildProcess(
|
||||||
$process->setTty(true);
|
command: ['composer', 'install'],
|
||||||
$process->setWorkingDirectory($workingDir);
|
extraArgs: $extraArgs,
|
||||||
|
workingDir: $workingDir,
|
||||||
|
);
|
||||||
$process->run();
|
$process->run();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'run':
|
case 'run':
|
||||||
if ($isDockerCompose) {
|
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->setTimeout(null);
|
||||||
$process->setTty(true);
|
|
||||||
$process->setWorkingDirectory($workingDir);
|
|
||||||
$process->run();
|
$process->run();
|
||||||
} else {
|
} else {
|
||||||
switch ($input->getOption('type')) {
|
switch ($input->getOption('type')) {
|
||||||
case ProjectType::Sculpin->value:
|
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->setTimeout(null);
|
||||||
$process->setTty(true);
|
|
||||||
$process->setWorkingDirectory($workingDir);
|
|
||||||
$process->run();
|
$process->run();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -93,10 +127,11 @@ $application->setCode(function (InputInterface $input): int {
|
||||||
case 'test':
|
case 'test':
|
||||||
// TODO: PHPUnit, Pest or ParaTest.
|
// TODO: PHPUnit, Pest or ParaTest.
|
||||||
// TODO: commands in Docker Compose?
|
// TODO: commands in Docker Compose?
|
||||||
$process = new Process(command: array_filter(['./vendor/bin/phpunit', $extraArgs]));
|
$process = buildProcess(
|
||||||
$process->setTty(true);
|
command: ['./vendor/bin/phpunit'],
|
||||||
$process->setWorkingDirectory($workingDir);
|
extraArgs: $extraArgs,
|
||||||
$process->run();
|
workingDir: $workingDir,
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue