-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
platform-lint
executable file
·118 lines (96 loc) · 3.55 KB
/
platform-lint
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
#!/usr/bin/env php
<?php
declare(strict_types=1);
/**
* Copyright (c) 2021-2024 guanguans<ityaozm@gmail.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/guanguans/notify
*/
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
require __DIR__.'/vendor/autoload.php';
(static function (): void {
$echo = static function ($messages, int $color = 0): void {
echo \sprintf("\033[{$color}m%s\033[0m\n", implode(\PHP_EOL, (array) $messages).\PHP_EOL);
};
$success = static function ($messages) use ($echo): void {
$echo($messages, 32);
exit(0);
};
$error = static function ($messages) use ($echo): void {
$echo($messages, 31);
exit(1);
};
$platforms = array_values(array_map(
static fn (SplFileInfo $splFileInfo): string => $splFileInfo->getBasename(),
iterator_to_array(
Finder::create()
->in(__DIR__.'/src')
->exclude('Foundation')
->depth(0)
// ->sortByName()
// ->sort(static fn (
// SplFileInfo $a,
// SplFileInfo $b
// ) => strcmp(strtolower($a->getFilename()), strtolower($b->getFilename())))
->sort(static fn (
SplFileInfo $a,
SplFileInfo $b
): int => strtolower($a->getFilename()) <=> strtolower($b->getFilename()))
->directories(),
),
));
$deprecatedPlatforms = [
'Gitter',
'NowPush',
];
$platformsDescriptionContents = implode('、', $platforms);
$platformsKeywordContents = trim(
array_reduce(
$platforms,
static fn (string $carry, string $platform): string => $carry." \"$platform\",\n",
''
),
",\n"
);
$platformsLinkContents = trim(
array_reduce(
$platforms,
static function (string $carry, string $platform) use ($deprecatedPlatforms): string {
return $carry.(
\in_array($platform, $deprecatedPlatforms, true)
? "* [~~$platform~~](./src/$platform/README.md)\n"
: "* [$platform](./src/$platform/README.md)\n"
);
},
''
),
"\n"
);
file_put_contents(
__DIR__.'/tests.platforms',
implode(\PHP_EOL, [
$platformsDescriptionContents,
$platformsKeywordContents,
$platformsLinkContents,
])
);
$composerContents = file_get_contents(__DIR__.'/composer.json');
if (!str_contains($composerContents, $platformsDescriptionContents)) {
$error("The description of composer.json must contain: \n```\n$platformsDescriptionContents\n```");
}
if (!str_contains($composerContents, $platformsKeywordContents)) {
$error("The keywords of composer.json must contain: \n```\n$platformsKeywordContents\n```");
}
$readmeContents = file_get_contents(__DIR__.'/README.md');
if (!str_contains($readmeContents, $platformsDescriptionContents)) {
$error("The description of README.md must contain: \n```\n$platformsDescriptionContents\n```");
}
if (!str_contains($readmeContents, $platformsLinkContents)) {
$error("The links of README.md must contain: \n```\n$platformsLinkContents\n```");
}
$success('Platforms lint successfully.');
})();