This commit is contained in:
Oliver Davies 2023-01-19 18:53:42 +00:00
parent 31614e0f58
commit 014b6dabeb
2 changed files with 24 additions and 12 deletions

View file

@ -2,13 +2,19 @@
use OliverDaviesLtd\BuildConfiguration\Console\Command\BuildConfigurationCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Filesystem\Filesystem;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
require __DIR__ . '/vendor/autoload.php';
$app = new Application();
$filesystem = new Filesystem();
$twig = new Environment(new FilesystemLoader([__DIR__.'/templates']));
$app->addCommands([
new BuildConfigurationCommand(),
$application = new Application();
$application->addCommands([
new BuildConfigurationCommand($twig, $filesystem),
]);
$app->run();
$application->run();

View file

@ -12,7 +12,6 @@ use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
#[AsCommand(
description: 'Build configuration files',
@ -20,20 +19,27 @@ use Twig\Loader\FilesystemLoader;
)]
final class BuildConfigurationCommand extends Command
{
private const LANGUAGE_PHP = 'php';
public function __construct(
private Environment $twig,
private Filesystem $filesystem,
) {
parent::__construct();
}
public function execute(InputInterface $input, OutputInterface $output)
{
// Find a build.yaml file.
$io = new SymfonyStyle($input, $output);
$buildYaml = Yaml::parseFile(getcwd().'/build.yaml');
$io = new SymfonyStyle($input, $output);
$io->info("Building configuration for {$buildYaml['name']}.");
$twig = new Environment(new FilesystemLoader([__DIR__.'/../../../templates']));
$output = $twig->render('test.twig', $buildYaml);
if ($buildYaml['language'] === self::LANGUAGE_PHP) {
$this->filesystem->dumpFile('Dockerfile', $this->twig->render('php/Dockerfile.twig', $buildYaml));
}
$fs = new Filesystem();
$fs->dumpFile('test.txt', $output);
//
return Command::SUCCESS;
}
}