-
Notifications
You must be signed in to change notification settings - Fork 103
/
generate-json.php
43 lines (36 loc) · 1.54 KB
/
generate-json.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
$pluginDirectories = new CallbackFilterIterator(
new DirectoryIterator(__DIR__ . '/plugins'),
static function (DirectoryIterator $fileInfo) {
return $fileInfo->isDir() && ! $fileInfo->isDot();
}
);
$plugins = [];
/** @var SplFileInfo $directory */
foreach ($pluginDirectories as $directory) {
$file = $directory->getPathname() . '/src/manifest.json';
if (!is_readable($file)) {
fwrite(STDERR, sprintf('Cannot access manifest "%s"' . PHP_EOL, $file));
continue;
}
$manifest = json_decode(file_get_contents($file), true, 50);
if (json_last_error() !== JSON_ERROR_NONE) {
fwrite(STDERR, sprintf('Skipped file "%s": %s' . PHP_EOL, $file, json_last_error_msg()));
continue;
}
$plugin = $manifest['information'];
$plugin['name'] = $plugin['name'] ?? sprintf('(name missing in %s manifest)', $directory->getBaseName());
if (in_array($plugin['name'], ['mkt-queue-sync', 'routeros-packet-manager', 'routeros-suspension'], true)) {
continue;
}
$plugin['zipUrl'] = sprintf(
'https://github.com/Ubiquiti-App/UCRM-plugins/raw/master/plugins/%s/%s.zip',
$plugin['name'],
$plugin['name']
);
fwrite(STDERR, sprintf("\t%s\t%s\t\t%s\n", $plugin['version'] ?? '(no version)', $plugin['name'], $plugin['url'] ?? '(URL missing)'));
$plugins[$plugin['name']] = $plugin;
}
ksort($plugins);
fwrite(STDERR, 'Plugins found: ' . count($plugins) . "\n");
echo json_encode(['plugins' => array_values(array_filter($plugins))], JSON_PRETTY_PRINT) . PHP_EOL;