|
14 | 14 | namespace Guanguans\Notify\Foundation\Support;
|
15 | 15 |
|
16 | 16 | use Composer\Script\Event;
|
| 17 | +use Guanguans\Notify\Foundation\Message; |
| 18 | +use Illuminate\Support\Collection; |
17 | 19 | use Rector\Config\RectorConfig;
|
18 | 20 | use Rector\DependencyInjection\LazyContainerFactory;
|
19 | 21 | use Symfony\Component\Finder\Finder;
|
|
27 | 29 | final class ComposerScripts
|
28 | 30 | {
|
29 | 31 | /**
|
| 32 | + * @noinspection PhpDuplicatedCharacterInStrFunctionCallInspection |
30 | 33 | * @noinspection PhpUnused
|
| 34 | + * |
| 35 | + * @throws \JsonException |
| 36 | + * @throws \ReflectionException |
| 37 | + * |
| 38 | + * @return int<0, 0> |
| 39 | + */ |
| 40 | + public static function generateIdeJson(Event $event): int |
| 41 | + { |
| 42 | + self::requireAutoload($event); |
| 43 | + |
| 44 | + collect( |
| 45 | + Finder::create() |
| 46 | + ->in(__DIR__.'/../../../src') |
| 47 | + ->exclude('Foundation') |
| 48 | + ->path('/Messages/') |
| 49 | + ->name([ |
| 50 | + 'Message.php', |
| 51 | + '*Message.php', |
| 52 | + ]) |
| 53 | + ->sortByName() |
| 54 | + ->files() |
| 55 | + ) |
| 56 | + ->mapWithKeys(static function (SplFileInfo $fileInfo): array { |
| 57 | + $class = \sprintf( |
| 58 | + '\\Guanguans\\Notify\\%s', |
| 59 | + str_replace('/', '\\', rtrim($fileInfo->getRelativePathname(), '.php')) |
| 60 | + ); |
| 61 | + |
| 62 | + return [$class => new \ReflectionClass($class)]; |
| 63 | + }) |
| 64 | + ->filter(static fn (\ReflectionClass $reflectionClass): bool => $reflectionClass->isSubclassOf(Message::class)) |
| 65 | + ->map(static function (\ReflectionClass $reflectionClass, string $class): array { |
| 66 | + $defined = Utils::definedFor($class); |
| 67 | + |
| 68 | + asort($defined); |
| 69 | + |
| 70 | + return array_values($defined); |
| 71 | + }) |
| 72 | + ->map(static fn (array $defined, string $class): array => [ |
| 73 | + 'complete' => 'staticStrings', |
| 74 | + 'condition' => [ |
| 75 | + [ |
| 76 | + 'classFqn' => [ |
| 77 | + $class, |
| 78 | + ], |
| 79 | + 'newClassFqn' => [ |
| 80 | + $class, |
| 81 | + ], |
| 82 | + 'methodNames' => [ |
| 83 | + 'make', |
| 84 | + ], |
| 85 | + 'parameters' => [ |
| 86 | + 1, |
| 87 | + ], |
| 88 | + 'place' => 'arrayKey', |
| 89 | + ], |
| 90 | + ], |
| 91 | + 'options' => [ |
| 92 | + 'strings' => $defined, |
| 93 | + ], |
| 94 | + ]) |
| 95 | + ->pipe(static fn (Collection $completions): Collection => collect([ |
| 96 | + '$schema' => 'https://laravel-ide.com/schema/laravel-ide-v2.json', |
| 97 | + 'completions' => $completions->values()->all(), |
| 98 | + ])) |
| 99 | + ->tap(static function (Collection $ide): void { |
| 100 | + file_put_contents( |
| 101 | + __DIR__.'/../../../ide.json', |
| 102 | + json_encode($ide, \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES) |
| 103 | + ); |
| 104 | + }); |
| 105 | + |
| 106 | + $event->getIO()->write('<info>Generate ide.json successfully.</info>'); |
| 107 | + |
| 108 | + return 0; |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * @noinspection PhpUnused |
| 113 | + * |
| 114 | + * @return int<0, 0> |
31 | 115 | */
|
32 | 116 | public static function platformLint(Event $event): int
|
33 | 117 | {
|
@@ -91,27 +175,27 @@ public static function platformLint(Event $event): int
|
91 | 175 | $composerContents = file_get_contents(__DIR__.'/../../../composer.json');
|
92 | 176 |
|
93 | 177 | if (!str_contains($composerContents, $platformsDescriptionContents)) {
|
94 |
| - $event->getIO()->writeError("The description of composer.json must contain: \n```\n$platformsDescriptionContents\n```"); |
| 178 | + $event->getIO()->writeError("<error>The description of composer.json must contain: \n```\n$platformsDescriptionContents\n```</error>"); |
95 | 179 |
|
96 | 180 | exit(1);
|
97 | 181 | }
|
98 | 182 |
|
99 | 183 | if (!str_contains($composerContents, $platformsKeywordContents)) {
|
100 |
| - $event->getIO()->writeError("The keywords of composer.json must contain: \n```\n$platformsKeywordContents\n```"); |
| 184 | + $event->getIO()->writeError("<error>The keywords of composer.json must contain: \n```\n$platformsKeywordContents\n```</error>"); |
101 | 185 |
|
102 | 186 | exit(1);
|
103 | 187 | }
|
104 | 188 |
|
105 | 189 | $readmeContents = file_get_contents(__DIR__.'/../../../README.md');
|
106 | 190 |
|
107 | 191 | if (!str_contains($readmeContents, $platformsDescriptionContents)) {
|
108 |
| - $event->getIO()->writeError("The description of README.md must contain: \n```\n$platformsDescriptionContents\n```"); |
| 192 | + $event->getIO()->writeError("<error>The description of README.md must contain: \n```\n$platformsDescriptionContents\n```</error>"); |
109 | 193 |
|
110 | 194 | exit(1);
|
111 | 195 | }
|
112 | 196 |
|
113 | 197 | if (!str_contains($readmeContents, $platformsLinkContents)) {
|
114 |
| - $event->getIO()->writeError("The links of README.md must contain: \n```\n$platformsLinkContents\n```"); |
| 198 | + $event->getIO()->writeError("<error>The links of README.md must contain: \n```\n$platformsLinkContents\n```</error>"); |
115 | 199 |
|
116 | 200 | exit(1);
|
117 | 201 | }
|
|
0 commit comments