|
14 | 14 | use Symfony\Component\Console\Input\InputArgument;
|
15 | 15 | use Symfony\Component\Console\Input\InputInterface;
|
16 | 16 | use Symfony\Component\Console\Output\OutputInterface;
|
17 |
| -use Symfony\Component\HttpClient\HttpClient; |
18 | 17 |
|
19 | 18 | #[AsCommand(name: 'generate:flex-endpoint', description: 'Generates the json files required by Flex')]
|
20 | 19 | class GenerateFlexEndpointCommand extends Command
|
@@ -56,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|
56 | 55 |
|
57 | 56 | // stdin usually generated by `git ls-tree HEAD */*/*`
|
58 | 57 |
|
59 |
| - while (false !== $line = fgets(STDIN)) { |
| 58 | + while (false !== $line = fgets(\STDIN)) { |
60 | 59 | [$tree, $package] = explode("\t", trim($line));
|
61 | 60 | [,, $tree] = explode(' ', $tree);
|
62 | 61 |
|
@@ -98,8 +97,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|
98 | 97 | 'repository' => sprintf('github.com/%s', $repository),
|
99 | 98 | 'origin_template' => sprintf('{package}:{version}@github.com/%s:%s', $repository, $sourceBranch),
|
100 | 99 | 'recipe_template' => sprintf('https://raw.githubusercontent.com/%s/%s/{package_dotted}.{version}.json', $repository, $flexBranch),
|
| 100 | + 'archived_recipes_template' => sprintf('https://raw.githubusercontent.com/%s/%s/archived/{package_dotted}/{ref}.json', $repository, $flexBranch), |
101 | 101 | ],
|
102 |
| - ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n"); |
| 102 | + ], \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES)."\n"); |
103 | 103 |
|
104 | 104 | return 0;
|
105 | 105 | }
|
@@ -138,15 +138,26 @@ private function generatePackageJson(string $package, string $version, array $ma
|
138 | 138 |
|
139 | 139 | ksort($files, \SORT_NATURAL);
|
140 | 140 |
|
141 |
| - file_put_contents(sprintf('%s/%s.%s.json', $outputDir, str_replace('/', '.', $package), $version), json_encode([ |
142 |
| - 'manifests' => [ |
143 |
| - $package => [ |
144 |
| - 'manifest' => $manifest, |
145 |
| - 'files' => $files, |
146 |
| - 'ref' => $tree, |
| 141 | + $contents = json_encode( |
| 142 | + [ |
| 143 | + 'manifests' => [ |
| 144 | + $package => [ |
| 145 | + 'manifest' => $manifest, |
| 146 | + 'files' => $files, |
| 147 | + 'ref' => $tree, |
| 148 | + ], |
147 | 149 | ],
|
148 | 150 | ],
|
149 |
| - ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n"); |
| 151 | + \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES |
| 152 | + )."\n"; |
| 153 | + file_put_contents(sprintf('%s/%s.%s.json', $outputDir, str_replace('/', '.', $package), $version), $contents); |
| 154 | + |
| 155 | + // save another version for the archives |
| 156 | + $archivedPath = sprintf('%s/archived/%s.%s/%s.json', $outputDir, str_replace('/', '.', $package), $version, $tree); |
| 157 | + if (!file_exists(\dirname($archivedPath))) { |
| 158 | + mkdir(\dirname($archivedPath), 0777, true); |
| 159 | + } |
| 160 | + file_put_contents($archivedPath, $contents); |
150 | 161 |
|
151 | 162 | return true;
|
152 | 163 | }
|
|
0 commit comments