-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreadme.gen
More file actions
executable file
·122 lines (94 loc) · 3.67 KB
/
Copy pathreadme.gen
File metadata and controls
executable file
·122 lines (94 loc) · 3.67 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env php
<?php
define('VERSION', '~1.0@dev');
define('COMPOSER', __DIR__ . '/composer.json');
define('COMMON', __DIR__ . '/COMMON.md');
define('README', __DIR__ . '/README.md');
$packages = json_decode(file_get_contents(__DIR__ . '/packages.json'), true);
$lines = $aliases = $components = [];
foreach ($packages as $group => $package) {
$lines[] = sprintf('## %s', $group);
$lines[] = '';
foreach ($package['sub'] as $component) {
array_push($lines, ...gComponent($component['name'], $component['desc'] ?? '', $component['feat'] ?? []));
array_push($lines, "\n");
$components[] = $component['name'];
}
}
$lines[] = '';
foreach ($aliases as $key => $url) {
$lines[] = sprintf('[%s]: %s', $key, $url);
}
file_put_contents(README, str_replace('{{GEN}}', implode("\n", $lines), file_get_contents(COMMON)));
$composer = json_decode(file_get_contents(COMPOSER), true);
$composer['require'] = [];
foreach ($components as $name) {
$composer['require']["carno-php/{$name}"] = VERSION;
}
$json = json_encode($composer, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
$json = preg_replace('/^( +?)\\1(?=[^ ])/m', '$1', $json);
file_put_contents(COMPOSER, $json);
exec('composer normalize');
echo 'DONE';
function gComponent(string $name, string $desc, array $features) : array
{
$lines = [];
$lines[] = sprintf('#### [%s][%s]', $name, glFeature('url', $name));
if ($desc) {
$lines[] = '';
$lines[] = $desc;
}
$lines[] = '';
array_unshift($features, 'packagist');
foreach ($features as $feature) {
$lines[] = sprintf('[![][%s]][%s]', glFeature($feature, $name), glTarget($feature, $name));
}
return $lines;
}
function glFeature(string $type, string $name) : string
{
global $aliases;
switch ($type) {
case 'url':
$aliases[$key = "src-url-{$name}"] = "https://github.com/carno-php/{$name}";
return $key;
case 'travis':
$aliases[$key = "bud-ico-{$name}"] = "https://img.shields.io/travis/com/carno-php/{$name}/master.svg?style=flat-square";
return $key;
case 'travis-org':
$aliases[$key = "bud-ico-{$name}"] = "https://img.shields.io/travis/carno-php/{$name}/master.svg?style=flat-square";
return $key;
case 'coveralls':
$aliases[$key = "cov-ico-{$name}"] = "https://img.shields.io/coveralls/carno-php/{$name}/master.svg?style=flat-square";
return $key;
case 'packagist':
$aliases[$key = "pkg-ico-{$name}"] = "https://img.shields.io/packagist/v/carno-php/{$name}.svg?style=flat-square";
return $key;
case 'scrutinizer':
$aliases[$key = "scr-ico-{$name}"] = "https://img.shields.io/scrutinizer/g/carno-php/{$name}.svg?style=flat-square";
return $key;
}
return '';
}
function glTarget(string $type, string $name) : string
{
global $aliases;
switch ($type) {
case 'travis':
$aliases[$key = "bud-lnk-{$name}"] = "https://travis-ci.com/carno-php/{$name}";
return $key;
case 'travis-org':
$aliases[$key = "bud-lnk-{$name}"] = "https://travis-ci.org/carno-php/{$name}";
return $key;
case 'coveralls':
$aliases[$key = "cov-lnk-{$name}"] = "https://coveralls.io/r/carno-php/{$name}";
return $key;
case 'packagist':
$aliases[$key = "pkg-lnk-{$name}"] = "https://packagist.org/packages/carno-php/{$name}";
return $key;
case 'scrutinizer':
$aliases[$key = "scr-lnk-{$name}"] = "https://scrutinizer-ci.com/g/carno-php/{$name}/";
return $key;
}
return '';
}