mirror of
https://github.com/opdavies/build-configs.git
synced 2025-03-13 05:26:56 +00:00
Refactor
This commit is contained in:
parent
31614e0f58
commit
014b6dabeb
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue