From 31614e0f58a6312f7dfb89ee851c7c30c8164a5a Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 19 Jan 2023 18:37:13 +0000 Subject: [PATCH] Render a simple template --- box.json.dist | 5 + composer.json | 3 +- composer.lock | 128 +++++++++--------- .../Command/BuildConfigurationCommand.php | 10 +- templates/test.twig | 3 + 5 files changed, 82 insertions(+), 67 deletions(-) create mode 100644 templates/test.twig diff --git a/box.json.dist b/box.json.dist index ad6bd58..3567b71 100644 --- a/box.json.dist +++ b/box.json.dist @@ -1,3 +1,8 @@ { + "directories": [ + "src", + "templates", + "vendor" + ], "main": "build-config.php" } diff --git a/composer.json b/composer.json index 82d290e..ca606f7 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,8 @@ "require": { "twig/twig": "^3.5", "symfony/console": "^6.2", - "symfony/yaml": "^6.2" + "symfony/yaml": "^6.2", + "symfony/filesystem": "^6.2" }, "require-dev": { "humbug/box": "^4.2", diff --git a/composer.lock b/composer.lock index b08b800..ede2809 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "10bdf6712c1d4ee4e01f212c41080a07", + "content-hash": "cd4297546e12f0fef941f564d6d9b4c4", "packages": [ { "name": "psr/container", @@ -222,6 +222,69 @@ ], "time": "2022-11-25T10:21:52+00:00" }, + { + "name": "symfony/filesystem", + "version": "v6.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "50b2523c874605cf3d4acf7a9e2b30b6a440a016" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/50b2523c874605cf3d4acf7a9e2b30b6a440a016", + "reference": "50b2523c874605cf3d4acf7a9e2b30b6a440a016", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides basic utilities for the filesystem", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/filesystem/tree/v6.2.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-20T13:01:27+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.27.0", @@ -2734,69 +2797,6 @@ ], "time": "2022-11-25T10:21:52+00:00" }, - { - "name": "symfony/filesystem", - "version": "v6.2.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/filesystem.git", - "reference": "50b2523c874605cf3d4acf7a9e2b30b6a440a016" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/50b2523c874605cf3d4acf7a9e2b30b6a440a016", - "reference": "50b2523c874605cf3d4acf7a9e2b30b6a440a016", - "shasum": "" - }, - "require": { - "php": ">=8.1", - "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-mbstring": "~1.8" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Filesystem\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Provides basic utilities for the filesystem", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/filesystem/tree/v6.2.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-11-20T13:01:27+00:00" - }, { "name": "symfony/finder", "version": "v6.2.3", diff --git a/src/Console/Command/BuildConfigurationCommand.php b/src/Console/Command/BuildConfigurationCommand.php index 79253d6..e6f41d4 100644 --- a/src/Console/Command/BuildConfigurationCommand.php +++ b/src/Console/Command/BuildConfigurationCommand.php @@ -9,7 +9,10 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; 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', @@ -25,8 +28,11 @@ final class BuildConfigurationCommand extends Command $io = new SymfonyStyle($input, $output); $io->info("Building configuration for {$buildYaml['name']}."); - // Parse its contents. - // Generate the appropriate configuration files. + $twig = new Environment(new FilesystemLoader([__DIR__.'/../../../templates'])); + $output = $twig->render('test.twig', $buildYaml); + + $fs = new Filesystem(); + $fs->dumpFile('test.txt', $output); // return Command::SUCCESS; } diff --git a/templates/test.twig b/templates/test.twig new file mode 100644 index 0000000..f350cfe --- /dev/null +++ b/templates/test.twig @@ -0,0 +1,3 @@ +name: {{ name }} +type: {{ type }} +language: {{ language }}