Add Fractal to versa build
and automatically
...select the language if there is a `package.json` file
This commit is contained in:
parent
c5248bb061
commit
18ce1e84c6
5 changed files with 117 additions and 42 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Console\Command;
|
||||
|
||||
use App\Enum\ProjectLanguage;
|
||||
use App\Enum\ProjectType;
|
||||
use App\Process\Process;
|
||||
use RuntimeException;
|
||||
|
@ -14,6 +15,7 @@ final class BuildCommand extends AbstractCommand
|
|||
{
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$projectLanguage = null;
|
||||
$projectType = null;
|
||||
|
||||
$extraArgs = $input->getOption('extra-args');
|
||||
|
@ -25,6 +27,8 @@ final class BuildCommand extends AbstractCommand
|
|||
// based on its dependencies.
|
||||
// TODO: move this logic to a service so it can be tested.
|
||||
if ($filesystem->exists($workingDir.'/composer.json')) {
|
||||
$projectLanguage = ProjectLanguage::PHP->value;
|
||||
|
||||
$json = json_decode(
|
||||
json: strval(file_get_contents($workingDir.'/composer.json')),
|
||||
associative: true,
|
||||
|
@ -39,40 +43,61 @@ final class BuildCommand extends AbstractCommand
|
|||
} elseif (in_array(needle: 'symfony/framework-bundle', haystack: $dependencies, strict: true)) {
|
||||
$projectType = ProjectType::Symfony->value;
|
||||
}
|
||||
} elseif ($filesystem->exists($workingDir.'/fractal.config.js')) {
|
||||
$projectLanguage = ProjectLanguage::JavaScript->value;
|
||||
$projectType = ProjectType::Fractal->value;
|
||||
}
|
||||
|
||||
// Even if the project type is found automatically, still override it with
|
||||
// the option value if there is one.
|
||||
// Even if the project language or type is found automatically, still
|
||||
// override it with the option value if there is one.
|
||||
$projectLanguage = $input->getOption('language') ?? $projectLanguage;
|
||||
$projectType = $input->getOption('type') ?? $projectType;
|
||||
|
||||
$isDockerCompose = $filesystem->exists($workingDir . '/docker-compose.yaml');
|
||||
|
||||
switch ($projectType) {
|
||||
case ProjectType::Drupal->value:
|
||||
if ($isDockerCompose) {
|
||||
$process = Process::create(
|
||||
command: ['docker', 'compose', 'build'],
|
||||
extraArgs: $extraArgs,
|
||||
workingDir: $workingDir,
|
||||
);
|
||||
switch ($projectLanguage) {
|
||||
case ProjectLanguage::PHP->value:
|
||||
switch ($projectType) {
|
||||
case ProjectType::Drupal->value:
|
||||
if ($isDockerCompose) {
|
||||
$process = Process::create(
|
||||
command: ['docker', 'compose', 'build'],
|
||||
extraArgs: $extraArgs,
|
||||
workingDir: $workingDir,
|
||||
);
|
||||
|
||||
$process->run();
|
||||
$process->run();
|
||||
}
|
||||
break;
|
||||
|
||||
case ProjectType::Symfony->value:
|
||||
// TODO: run humbug/box if added to generate a phar?
|
||||
throw new RuntimeException('No build command set for Symfony projects.');
|
||||
|
||||
case ProjectType::Sculpin->value:
|
||||
$process = Process::create(
|
||||
command: ['./vendor/bin/sculpin', 'generate'],
|
||||
extraArgs: $extraArgs,
|
||||
workingDir: $workingDir,
|
||||
);
|
||||
|
||||
$process->run();
|
||||
break;
|
||||
}
|
||||
|
||||
case ProjectLanguage::JavaScript->value:
|
||||
switch ($projectType) {
|
||||
case ProjectType::Fractal->value:
|
||||
$process = Process::create(
|
||||
command: ['npx', 'fractal', 'build'],
|
||||
extraArgs: $extraArgs,
|
||||
workingDir: $workingDir,
|
||||
);
|
||||
|
||||
$process->run();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ProjectType::Symfony->value:
|
||||
// TODO: run humbug/box if added to generate a phar?
|
||||
throw new RuntimeException('No build command set for Symfony projects.');
|
||||
|
||||
case ProjectType::Sculpin->value:
|
||||
$process = Process::create(
|
||||
command: ['./vendor/bin/sculpin', 'generate'],
|
||||
extraArgs: $extraArgs,
|
||||
workingDir: $workingDir,
|
||||
);
|
||||
|
||||
$process->run();
|
||||
break;
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
|
|
Reference in a new issue