-
Notifications
You must be signed in to change notification settings - Fork 21
/
generate-config.php
45 lines (34 loc) · 1.55 KB
/
generate-config.php
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
<?php
$items = json_decode(file_get_contents(__DIR__ . '/generatable.json'), true);
$packageJson = json_decode(file_get_contents(__DIR__ . '/package.json'), true);
$config = [];
usort($items, function($a, $b) {
return $a['type'] <=> $b['type'];
});
foreach ($items as $item) {
$type = $item['type'];
$features = $item['features'] ?? ['diagnostics', 'hover', 'link', 'completion'];
foreach ($features as $feature) {
$config["Laravel.{$type}.{$feature}"] = [
'type' => 'boolean',
'default' => true,
'generated' => true,
'description' => match($feature) {
'diagnostics' => "Enable diagnostics for {$type}.",
'hover' => "Enable hover information for {$type}.",
'link' => "Enable linking for {$type}.",
default => null,
},
];
}
}
$currentConfig = $packageJson['contributes']['configuration']['properties'] ?? [];
$customConfig = array_filter($currentConfig, function($value, $key) {
return ($value['generated'] ?? false) === false;
}, ARRAY_FILTER_USE_BOTH);
$packageJson['contributes']['configuration']['properties'] = array_merge($customConfig, $config);
file_put_contents(__DIR__ . '/package.json', json_encode($packageJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
$keys = array_map(function($key) {
return str_replace('Laravel.', '', $key);
}, array_keys($config));
file_put_contents(__DIR__ . '/src/support/generated-config.ts', "export type GeneratedConfigKey = '" . implode("' | '", $keys) . "';");