|
10 | 10 |
|
11 | 11 | namespace Deployer\Command; |
12 | 12 |
|
| 13 | +use Maml\Maml; |
13 | 14 | use Symfony\Component\Console\Command\Command; |
14 | 15 | use Symfony\Component\Console\Input\InputInterface; |
15 | 16 | use Symfony\Component\Console\Input\InputOption; |
@@ -72,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
72 | 73 | $io = new SymfonyStyle($input, $output); |
73 | 74 | $recipePath = $input->getOption('path'); |
74 | 75 |
|
75 | | - $language = $io->choice('Select recipe language', ['php', 'yaml'], 'php'); |
| 76 | + $language = $io->choice('Select recipe language', ['php', 'maml'], 'php'); |
76 | 77 | if (empty($recipePath)) { |
77 | 78 | $recipePath = "deploy.$language"; |
78 | 79 | } |
@@ -148,7 +149,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
148 | 149 | $hosts = []; |
149 | 150 | } |
150 | 151 |
|
151 | | - file_put_contents($recipePath, $this->$language($template, $project, $repository, $hosts)); |
| 152 | + |
| 153 | + $code = match ($language) { |
| 154 | + 'php' => $this->php($template, $project, $repository, $hosts), |
| 155 | + 'maml' => $this->maml($template, $project, $repository, $hosts), |
| 156 | + default => $default, |
| 157 | + }; |
| 158 | + |
| 159 | + file_put_contents($recipePath, $code); |
152 | 160 |
|
153 | 161 | $this->telemetry(); |
154 | 162 | $output->writeln(sprintf( |
@@ -191,51 +199,33 @@ private function php(string $template, string $project, string $repository, arra |
191 | 199 | PHP; |
192 | 200 | } |
193 | 201 |
|
194 | | - private function yaml(string $template, string $project, string $repository, array $hosts): string |
| 202 | + private function maml(string $template, string $project, string $repository, array $hosts): string |
195 | 203 | { |
196 | | - $h = ""; |
197 | | - foreach ($hosts as $host) { |
198 | | - $h .= " $host:\n" |
199 | | - . " remote_user: deployer\n" |
200 | | - . " deploy_path: '~/{$project}'\n"; |
201 | | - } |
202 | | - |
203 | | - $additionalConfigs = $this->getAdditionalConfigs($template); |
204 | | - |
205 | | - return <<<YAML |
206 | | - import: |
207 | | - - recipe/$template.php |
| 204 | + $recipe = [ |
| 205 | + "import" => [ |
| 206 | + "recipe/$template.php", |
| 207 | + ], |
| 208 | + "config" => [ |
| 209 | + "repository" => "$repository", |
| 210 | + ], |
| 211 | + "hosts" => [], |
| 212 | + "tasks" => [ |
| 213 | + "example" => [ |
| 214 | + [ |
| 215 | + "run" => "date", |
| 216 | + ], |
| 217 | + ], |
| 218 | + ], |
| 219 | + ]; |
208 | 220 |
|
209 | | - config: |
210 | | - repository: '$repository' |
211 | | - $additionalConfigs |
212 | | - hosts: |
213 | | - $h |
214 | | - tasks: |
215 | | - build: |
216 | | - - run: uptime |
217 | | -
|
218 | | - after: |
219 | | - deploy:failed: deploy:unlock |
220 | | -
|
221 | | - YAML; |
222 | | - } |
223 | | - |
224 | | - private function getAdditionalConfigs(string $template): string |
225 | | - { |
226 | | - if ($template !== 'common') { |
227 | | - return ''; |
| 221 | + foreach ($hosts as $host) { |
| 222 | + $recipe['hosts'][$host] = [ |
| 223 | + "remote_user" => "deployer", |
| 224 | + "deploy_path" => "~/$project", |
| 225 | + ]; |
228 | 226 | } |
229 | 227 |
|
230 | | - return <<<YAML |
231 | | - shared_files: |
232 | | - - .env |
233 | | - shared_dirs: |
234 | | - - uploads |
235 | | - writable_dirs: |
236 | | - - uploads |
237 | | - |
238 | | - YAML; |
| 228 | + return Maml::stringify($recipe); |
239 | 229 | } |
240 | 230 |
|
241 | 231 | private function recipes(): array |
|
0 commit comments