-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
generate-ide-json
executable file
·99 lines (84 loc) · 2.98 KB
/
generate-ide-json
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
#!/usr/bin/env php
<?php
declare(strict_types=1);
/**
* Copyright (c) 2021-2024 guanguans<[email protected]>
*
* 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 Guanguans\Notify\Foundation\Message;
use Guanguans\Notify\Foundation\Support\Utils;
use Illuminate\Support\Collection;
use Symfony\Component\Finder\Finder;
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);
};
$files = Finder::create()
->in(__DIR__.'/src')
->exclude('Foundation')
->path('/Messages/')
->name([
'Message.php',
'*Message.php',
])
->sortByName()
->files();
collect($files)
->mapWithKeys(static function (\Symfony\Component\Finder\SplFileInfo $fileInfo): array {
$class = \sprintf(
'\\Guanguans\\Notify\\%s',
str_replace('/', '\\', rtrim($fileInfo->getRelativePathname(), '.php'))
);
return [$class => new ReflectionClass($class)];
})
->filter(static fn (ReflectionClass $reflectionClass): bool => $reflectionClass->isSubclassOf(Message::class))
->map(static function (ReflectionClass $reflectionClass, string $class): array {
$defined = Utils::definedFor($class);
asort($defined);
return array_values($defined);
})
->map(static fn (array $defined, string $class): array => [
'complete' => 'staticStrings',
'condition' => [
[
'classFqn' => [
$class,
],
'newClassFqn' => [
$class,
],
'methodNames' => [
'make',
],
'parameters' => [
1,
],
'place' => 'arrayKey',
],
],
'options' => [
'strings' => $defined,
],
])
->pipe(static fn (Collection $completions): Collection => collect([
'$schema' => 'https://laravel-ide.com/schema/laravel-ide-v2.json',
'completions' => $completions->values()->all(),
]))
->tap(static function (Collection $ide): void {
file_put_contents(__DIR__.'/ide.json', json_encode($ide, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES));
});
$success('Generate ide.json successfully.');
})();