2023-01-19 18:11:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OliverDaviesLtd\BuildConfiguration\Console\Command;
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2023-01-19 18:37:13 +00:00
|
|
|
use Symfony\Component\Filesystem\Filesystem;
|
2023-01-19 18:11:24 +00:00
|
|
|
use Symfony\Component\Yaml\Yaml;
|
2023-01-19 18:37:13 +00:00
|
|
|
use Twig\Environment;
|
|
|
|
use Twig\Loader\FilesystemLoader;
|
2023-01-19 18:11:24 +00:00
|
|
|
|
|
|
|
#[AsCommand(
|
|
|
|
description: 'Build configuration files',
|
|
|
|
name: 'build-configuration'
|
|
|
|
)]
|
|
|
|
final class BuildConfigurationCommand extends Command
|
|
|
|
{
|
|
|
|
public function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
// Find a build.yaml file.
|
|
|
|
$buildYaml = Yaml::parseFile(getcwd().'/build.yaml');
|
|
|
|
|
|
|
|
$io = new SymfonyStyle($input, $output);
|
|
|
|
$io->info("Building configuration for {$buildYaml['name']}.");
|
|
|
|
|
2023-01-19 18:37:13 +00:00
|
|
|
$twig = new Environment(new FilesystemLoader([__DIR__.'/../../../templates']));
|
|
|
|
$output = $twig->render('test.twig', $buildYaml);
|
|
|
|
|
|
|
|
$fs = new Filesystem();
|
|
|
|
$fs->dumpFile('test.txt', $output);
|
2023-01-19 18:11:24 +00:00
|
|
|
//
|
|
|
|
return Command::SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|