Skip to content

Commit 28d4b78

Browse files
committed
Dump contents as dir tree
We now dump in a directory structure: tool tool1 tool1.json tool2 tool2.json plugin plugin1 plugin1.json plugin1-1.0.0.0.php plugin1-2.0.0.0.php plugin2 plugin2.json plugin2-1.0.0.0.php
1 parent 1f42aea commit 28d4b78

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/JsonRepositoryWriter.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,30 @@ public function save(): void
9191
}
9292
$data['includes'][] = $content;
9393
}
94+
unset($tool, $content);
9495

9596
foreach ($this->plugins as $plugin) {
9697
if (null === $content = $this->processPlugin($plugin)) {
9798
continue;
9899
}
99100
$data['includes'][] = $content;
100101
}
102+
unset($plugin, $content);
101103

102104
$this->dumpFile('repository.json', $data);
105+
unset($data);
103106

104107
$flipped = array_flip($this->dumpedFileNames);
105108
foreach (glob($this->baseDir . '/*') as $filename) {
106-
if (!array_key_exists($filename, $flipped)) {
109+
if (!is_dir($filename) && !array_key_exists($filename, $flipped)) {
107110
$this->filesystem->remove($filename);
108111
}
109112
}
110113
}
111114

112115
private function processTool(ToolInterface $tool): ?array
113116
{
114-
$fileName = $tool->getName() . '-tool.json';
117+
$fileName = sprintf('tool/%1$s/%1$s.json', $tool->getName());
115118
$fileNameAbsolute = $this->baseDir . '/' . $fileName;
116119
if ($tool->isEmpty()) {
117120
return null;
@@ -175,18 +178,18 @@ private function encodeToolRequirements(ToolRequirements $requirements): stdClas
175178

176179
private function processPlugin(PluginInterface $plugin): ?array
177180
{
178-
$fileName = $plugin->getName() . '-plugin.json';
181+
$fileName = sprintf('plugin/%1$s/%1$s.json', $plugin->getName());
179182
$fileNameAbsolute = $this->baseDir . '/' . $fileName;
180183
if ($plugin->isEmpty()) {
181184
return null;
182185
}
183186
$data = [];
184187
foreach ($plugin as $version) {
185188
// if file plugin, copy file - dump it otherwise.
186-
$pluginFile = $plugin->getName() . '-' . $version->getVersion() . '.php';
189+
$pluginFile = sprintf('%1$s-%2$s.php', $plugin->getName(), $version->getVersion());
187190
$signatureFile = $pluginFile . '.asc';
188191
if ($version instanceof PhpFilePluginVersion) {
189-
$this->copyFile($version->getFilePath(), $pluginFile);
192+
$this->copyFile($version->getFilePath(), sprintf('plugin/%1$s/%2$s', $plugin->getName(), $pluginFile));
190193
}
191194

192195
$serialized = [

tests/JsonRepositoryWriterTest.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public function testWrite(): void
8282
$writer->save();
8383

8484
$this->assertFileExists($tempDir . '/repository.json');
85-
$this->assertFileExists($tempDir . '/tool1-tool.json');
86-
$this->assertFileExists($tempDir . '/tool2-tool.json');
85+
$this->assertFileExists($tempDir . '/tool/tool1/tool1.json');
86+
$this->assertFileExists($tempDir . '/tool/tool2/tool2.json');
8787
self::assertFileDoesNotExist($tempDir . '/file-to-remove.txt');
8888

8989
$this->assertRepositoryFileMatches([
@@ -115,7 +115,7 @@ public function testWrite(): void
115115
],
116116
],
117117
],
118-
], $tempDir . '/tool1-tool.json');
118+
], $tempDir . '/tool/tool1/tool1.json');
119119
$this->assertRepositoryFileMatches([
120120
'tools' => [
121121
'tool2' => [
@@ -145,22 +145,22 @@ public function testWrite(): void
145145
],
146146
],
147147
],
148-
], $tempDir . '/tool2-tool.json');
148+
], $tempDir . '/tool/tool2/tool2.json');
149149

150150
$this->assertSame([
151151
'includes' => [
152152
[
153-
'url' => 'tool1-tool.json',
153+
'url' => 'tool/tool1/tool1.json',
154154
'checksum' => [
155155
'type' => 'sha-512',
156-
'value' => hash_file('sha512', $tempDir . '/tool1-tool.json'),
156+
'value' => hash_file('sha512', $tempDir . '/tool/tool1/tool1.json'),
157157
],
158158
],
159159
[
160-
'url' => 'tool2-tool.json',
160+
'url' => 'tool/tool2/tool2.json',
161161
'checksum' => [
162162
'type' => 'sha-512',
163-
'value' => hash_file('sha512', $tempDir . '/tool2-tool.json'),
163+
'value' => hash_file('sha512', $tempDir . '/tool/tool2/tool2.json'),
164164
],
165165
],
166166
],

0 commit comments

Comments
 (0)