1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cerbero\LaravelEnum\Commands; |
6
|
|
|
|
7
|
|
|
use Cerbero\LaravelEnum\Enums; |
8
|
|
|
use Cerbero\LaravelEnum\Services\TypeScript; |
9
|
|
|
use Illuminate\Console\Command; |
10
|
|
|
|
11
|
|
|
use function Cerbero\Enum\normalizeEnums; |
12
|
|
|
use function Cerbero\LaravelEnum\output; |
13
|
|
|
use function Laravel\Prompts\multiselect; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The console command to synchronize enums in TypeScript. |
17
|
|
|
*/ |
18
|
|
|
final class EnumTsCommand extends Command |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* The console command description. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $description = 'Synchronize enums in TypeScript'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The name and signature of the console command. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $signature = 'enum:ts |
33
|
|
|
{enums?* : The enums to synchronize} |
34
|
|
|
{--a|all : Whether all enums should be synchronized} |
35
|
|
|
{--f|force : Whether existing enums should be overwritten}'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Handle the command. |
39
|
|
|
*/ |
40
|
3 |
|
public function handle(): int |
41
|
|
|
{ |
42
|
3 |
|
if (! $enums = $this->enums()) { |
43
|
2 |
|
$this->info('No enums to annotate.'); |
44
|
|
|
|
45
|
2 |
|
return self::SUCCESS; |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
$succeeded = true; |
49
|
1 |
|
$force = !! $this->option('force'); |
50
|
|
|
|
51
|
1 |
|
foreach($enums as $enum) { |
52
|
1 |
|
$succeeded = output($this->output, $enum, fn() => (new TypeScript($enum))->sync($force)) && $succeeded; |
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
return $succeeded ? self::SUCCESS : self::FAILURE; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Retrieve the enums to annotate. |
60
|
|
|
* |
61
|
|
|
* @return list<class-string<\UnitEnum>> |
|
|
|
|
62
|
|
|
*/ |
63
|
3 |
|
private function enums(): array |
64
|
|
|
{ |
65
|
|
|
/** @var list<class-string<\UnitEnum>> */ |
66
|
|
|
return match (true) { |
67
|
3 |
|
! empty($enums = (array) $this->argument('enums')) => normalizeEnums($enums), |
68
|
2 |
|
empty($enums = [...Enums::namespaces()]) => [], |
69
|
1 |
|
$this->option('all') => $enums, |
70
|
|
|
/** @phpstan-ignore argument.type */ |
71
|
3 |
|
default => multiselect('Enums to synchronize:', $enums, required: true, hint: 'Press space to select.'), |
72
|
|
|
}; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths