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