|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Zikula package. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright Zikula Foundation - https://ziku.la/ |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Command\Command; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
|
|
19
|
|
|
class GenerateVendorDocCommand extends Command |
|
20
|
|
|
{ |
|
21
|
|
|
protected function configure() |
|
22
|
|
|
{ |
|
23
|
|
|
$this |
|
24
|
|
|
->setName('build:generate_vendor_doc') |
|
25
|
|
|
->setDescription('Generates a file containing all the vendors and the installed version.') |
|
26
|
|
|
->addOption('write-to', null, InputOption::VALUE_REQUIRED, 'Where to dump the generated file.'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
30
|
|
|
{ |
|
31
|
|
|
$output->writeln('Reading composer vendors.'); |
|
32
|
|
|
$packages = json_decode(file_get_contents('composer.lock'), true); |
|
33
|
|
|
$packages = $packages['packages']; |
|
34
|
|
|
|
|
35
|
|
|
$output->writeln('Generating output'); |
|
36
|
|
|
|
|
37
|
|
|
$typeOrder = [ |
|
38
|
|
|
'zikula-module' => 'Zikula Modules', |
|
39
|
|
|
'zikula-theme' => 'Zikula Themes', |
|
40
|
|
|
'symfony-bundle' => 'Symfony Bundles', |
|
41
|
|
|
'component' => 'Web Components', |
|
42
|
|
|
'library' => 'Other PHP libraries', |
|
43
|
|
|
'composer-installer' => 'Composer Installers', |
|
44
|
|
|
'composer-plugin' => 'Composer Plugins', |
|
45
|
|
|
'symfony-pack' => 'Symfony Packages' |
|
46
|
|
|
]; |
|
47
|
|
|
$types = array_keys($typeOrder); |
|
48
|
|
|
usort($packages, function($a, $b) use ($types) { |
|
49
|
|
|
return array_search($a['type'], $types) - array_search($b['type'], $types); |
|
50
|
|
|
}); |
|
51
|
|
|
|
|
52
|
|
|
$content = " |
|
53
|
|
|
--- |
|
54
|
|
|
currentMenu: vendor-info |
|
55
|
|
|
--- |
|
56
|
|
|
# Vendor information |
|
57
|
|
|
"; |
|
58
|
|
|
|
|
59
|
|
|
$currentType = ''; |
|
60
|
|
|
$authors = []; |
|
61
|
|
|
foreach ($packages as $package) { |
|
62
|
|
|
if ($currentType !== $package['type']) { |
|
63
|
|
|
if ('' !== $currentType) { |
|
64
|
|
|
$content .= "\n"; |
|
65
|
|
|
} |
|
66
|
|
|
$content .= '## ' . $typeOrder[$package['type']] . "\n\n"; |
|
67
|
|
|
$content .= str_repeat('-', mb_strlen($typeOrder[$package['type']])) . "\n"; |
|
68
|
|
|
$currentType = $package['type']; |
|
69
|
|
|
} |
|
70
|
|
|
$content .= "- **" . $package['name'] . "** `" . $package['version'] . "`"; |
|
71
|
|
|
if (isset($package['license'])) { |
|
72
|
|
|
$content .= ", License: `" . implode(', ', $package['license']) . "`\n"; |
|
73
|
|
|
} else { |
|
74
|
|
|
$content .= "\n"; |
|
75
|
|
|
} |
|
76
|
|
|
if (isset($package['description'])) { |
|
77
|
|
|
$content .= " *" . $package['description'] . "*\n"; |
|
78
|
|
|
} |
|
79
|
|
|
if (isset($package['authors'])) { |
|
80
|
|
|
$authors = array_merge($authors, $package['authors']); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$content .= "\n\n"; |
|
85
|
|
|
$content .= "These are the main authors of all of the projects supporting Zikula\n"; |
|
86
|
|
|
$content .= "-------------------------------------------------------------------\n"; |
|
87
|
|
|
|
|
88
|
|
|
$tmp = []; |
|
89
|
|
|
foreach ($authors as $k => $author) { |
|
90
|
|
|
if (in_array($author['name'], $tmp)) { |
|
91
|
|
|
unset($authors[$k]); |
|
92
|
|
|
continue; |
|
93
|
|
|
} |
|
94
|
|
|
$tmp[] = $author['name']; |
|
95
|
|
|
} |
|
96
|
|
|
foreach ($authors as $author) { |
|
97
|
|
|
$content .= "- **" . $author['name'] . "**"; |
|
98
|
|
|
if (isset($author['homepage'])) { |
|
99
|
|
|
$content .= " " . $author['homepage']; |
|
100
|
|
|
} |
|
101
|
|
|
if (isset($author['email'])) { |
|
102
|
|
|
$content .= " *" . $author['email'] . "*"; |
|
103
|
|
|
} |
|
104
|
|
|
$content .= "\n"; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$output->writeln('Dumping vendors to ' . $input->getOption('write-to')); |
|
108
|
|
|
|
|
109
|
|
|
file_put_contents($input->getOption('write-to'), $content); |
|
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
return 0; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|