Skip to content

Commit cbe4fa5

Browse files
Update flex endpoint format
1 parent 5a7ff1b commit cbe4fa5

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

src/GenerateFlexEndpointCommand.php

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5454
$version = substr($package, 1 + strrpos($package, '/'));
5555
$package = substr($package, 0, -1 - \strlen($version));
5656

57-
$this->generatePackageJson($repository, $sourceBranch, $contrib, $package, $version, $manifest, $tree, $outputDir);
57+
$this->generatePackageJson($package, $version, $manifest, $tree, $outputDir);
5858

5959
foreach ($manifest['aliases'] ?? [] as $alias) {
6060
$aliases[$alias] = $package;
@@ -78,16 +78,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7878
'aliases' => $aliases,
7979
'recipes' => $recipes,
8080
'versions' => $contrib ? [] : HttpClient::create()->request('GET', 'https://flex.symfony.com/versions.json')->toArray(),
81-
'git_url' => sprintf('https://github.com/%s.git', $repository),
82-
'tree_template' => sprintf('https://github.com/%s/tree/{tree}/{package}/{version}', $repository),
83-
'recipe_template' => sprintf('https://api.github.com/repos/%s/contents/{package_dotted}.{version}.json?ref=%s', $repository, $flexBranch),
81+
'branch' => $sourceBranch,
8482
'is_contrib' => $contrib,
83+
'_links' => [
84+
'repository' => sprintf('github.com/%s', $repository),
85+
'origin_template' => sprintf('{package}:{version}@github.com/%s:%s', $repository, $sourceBranch),
86+
'recipe_template' => sprintf('https://api.github.com/repos/%s/contents/{package_dotted}.{version}.json?ref=%s', $repository, $flexBranch),
87+
],
8588
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
8689

8790
return 0;
8891
}
8992

90-
private function generatePackageJson(string $repository, string $sourceBranch, bool $contrib, string $package, string $version, array $manifest, string $tree, string $outputDir)
93+
private function generatePackageJson(string $package, string $version, array $manifest, string $tree, string $outputDir)
9194
{
9295
$files = [];
9396
$it = new \RecursiveDirectoryIterator($package.'/'.$version);
@@ -107,35 +110,18 @@ private function generatePackageJson(string $repository, string $sourceBranch, b
107110
continue;
108111
}
109112
$contents = file_get_contents($path);
110-
$isUtf8 = preg_match('//u', $contents);
111113
$files[$file] = [
112-
'contents' => $isUtf8 ? $contents : base64_encode($contents),
114+
'contents' => preg_match('//u', $contents) ? explode("\n", $contents) : base64_encode($contents),
113115
'executable' => is_executable($path),
114-
'encoding' => $isUtf8 ? '' : 'base64',
115116
];
116117
}
117118

118119
file_put_contents(sprintf('%s/%s.%s.json', $outputDir, str_replace('/', '.', $package), $version), json_encode([
119-
'locks' => [
120-
$package => [
121-
'version' => $version,
122-
'recipe' => [
123-
'repo' => $version,
124-
'branch' => $sourceBranch,
125-
'version' => $version,
126-
'ref' => $tree,
127-
],
128-
],
129-
],
130120
'manifests' => [
131121
$package => [
132-
'repository' => sprintf('github.com/%s', $repository),
133-
'package' => $package,
134-
'version' => $version,
135122
'manifest' => $manifest,
136123
'files' => $files,
137-
'origin' => sprintf('%s:%[email protected]/%s:%s', $package, $version, $repository, $sourceBranch),
138-
'is_contrib' => $contrib,
124+
'ref' => $tree,
139125
],
140126
],
141127
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));

0 commit comments

Comments
 (0)