-
-
Notifications
You must be signed in to change notification settings - Fork 355
/
Copy pathux-toolkit-kit-lint
executable file
·61 lines (53 loc) · 2.08 KB
/
ux-toolkit-kit-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
#!/usr/bin/env php
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if ('cli' !== \PHP_SAPI) {
throw new Exception('This script must be run from the command line.');
}
use Symfony\Component\Console\Application;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\Service\ServiceLocatorTrait;
use Symfony\Contracts\Service\ServiceProviderInterface;
use Symfony\UX\Toolkit\Command\LintKitCommand;
use Symfony\UX\Toolkit\Dependency\DependenciesResolver;
use Symfony\UX\Toolkit\Kit\KitFactory;
use Symfony\UX\Toolkit\Registry\GitHubRegistry;
use Symfony\UX\Toolkit\Registry\LocalRegistry;
use Symfony\UX\Toolkit\Registry\RegistryFactory;
use Symfony\UX\Toolkit\Registry\Type;
function includeIfExists(string $file): bool
{
return file_exists($file) && include $file;
}
if (
!includeIfExists(__DIR__ . '/../../../autoload.php') &&
!includeIfExists(__DIR__ . '/../vendor/autoload.php')
) {
fwrite(STDERR, 'Install dependencies using Composer.'.PHP_EOL);
exit(1);
}
if (!class_exists(Application::class)) {
fwrite(STDERR, 'You need the "symfony/console" component in order to run the UX Toolkit kit linter.'.PHP_EOL);
exit(1);
}
$filesystem = new Filesystem();
$kitFactory = new KitFactory($filesystem, new DependenciesResolver($filesystem));
$registryFactory = new RegistryFactory(new class([
Type::Local->value => fn () => new LocalRegistry($kitFactory, $filesystem, getcwd() ?? throw new \RuntimeException('The current working directory could not be determined.')),
Type::GitHub->value => fn () => new GitHubRegistry($kitFactory, $filesystem, class_exists(HttpClient::class) ? HttpClient::create() : null),
]) implements ServiceProviderInterface {
use ServiceLocatorTrait;
});
(new Application())->add($command = new LintKitCommand($registryFactory))
->getApplication()
->setDefaultCommand($command->getName(), true)
->run()
;