92 lines
2.9 KiB
PHP
Executable file
92 lines
2.9 KiB
PHP
Executable file
#!/usr/bin/env php
|
|
|
|
<?php
|
|
require __DIR__.'/vendor/autoload.php';
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\SingleCommandApplication;
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
use Symfony\Component\Process\Process;
|
|
|
|
$application = new SingleCommandApplication();
|
|
|
|
$application->addArgument(
|
|
name: 'command',
|
|
mode: InputArgument::REQUIRED,
|
|
description: 'The command to run',
|
|
);
|
|
|
|
$application->addOption(
|
|
name: 'extra-args',
|
|
shortcut: 'a',
|
|
mode: InputArgument::OPTIONAL,
|
|
description: 'Any additonal arguments to pass to the command.',
|
|
);
|
|
|
|
$application->addOption(
|
|
name: 'type',
|
|
shortcut: 't',
|
|
mode: InputArgument::OPTIONAL,
|
|
description: 'The project type',
|
|
suggestedValues: ['drupal', 'sculpin'],
|
|
);
|
|
|
|
$application->addOption(
|
|
name: 'working-dir',
|
|
shortcut: 'd',
|
|
mode: InputArgument::OPTIONAL,
|
|
description: 'The project\'s working directory',
|
|
default: '.',
|
|
);
|
|
|
|
$application->setCode(function (InputInterface $input): int {
|
|
$filesystem = new Filesystem();
|
|
|
|
$extraArgs = $input->getOption('extra-args');
|
|
$workingDir = $input->getOption('working-dir');
|
|
|
|
// TODO: only allow defined commands - build, install, test, run.
|
|
switch ($input->getArgument('command')) {
|
|
case 'install':
|
|
// TODO: Composer in Docker Compose?
|
|
$process = new Process(command: array_filter(['composer', 'install', $extraArgs]));
|
|
$process->setTty(true);
|
|
$process->setWorkingDirectory($workingDir);
|
|
$process->run();
|
|
break;
|
|
|
|
case 'run':
|
|
if ($filesystem->exists($workingDir.'/docker-compose.yaml')) {
|
|
$process = new Process(command: array_filter(['docker', 'compose', 'up', $extraArgs]));
|
|
$process->setTimeout(null);
|
|
$process->setTty(true);
|
|
$process->setWorkingDirectory($workingDir);
|
|
$process->run();
|
|
} else {
|
|
switch ($input->getOption('type')) {
|
|
case 'sculpin':
|
|
$process = new Process(command: array_filter(['./vendor/bin/sculpin', 'generate', '--server', '--watch', $extraArgs]));
|
|
$process->setTimeout(null);
|
|
$process->setTty(true);
|
|
$process->setWorkingDirectory($workingDir);
|
|
$process->run();
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
|
|
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();
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
});
|
|
|
|
$application->run();
|