-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathWhisky.php
60 lines (48 loc) · 1.69 KB
/
Whisky.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace ProjektGopher\Whisky;
use Illuminate\Support\Facades\File;
class Whisky
{
public static function base_path(string $path = ''): string
{
$code_path = "vendor/projektgopher/whisky/{$path}";
return Platform::normalizePath(match (true) {
self::dogfooding() => base_path($path),
self::isRunningGlobally() => Platform::getGlobalComposerHome().'/'.$code_path,
default => Platform::cwd($code_path),
});
}
public static function bin_path(): string
{
return Platform::normalizePath(match (true) {
self::dogfooding() => Platform::cwd('whisky'),
self::isRunningGlobally() => Platform::getGlobalComposerBinDir().'/whisky',
default => Platform::cwd('vendor/bin/whisky'),
});
}
public static function dogfooding(): bool
{
return Platform::cwd() === Platform::normalizePath(base_path());
}
public static function isInstalledGlobally(): bool
{
return File::exists(Platform::getGlobalComposerBinDir().'/whisky');
}
public static function isRunningGlobally(): bool
{
return str_starts_with(base_path(), 'phar://'.Platform::getGlobalComposerHome());
}
public static function isInstalledLocally(): bool
{
return File::exists(Platform::cwd('vendor/projektgopher/whisky'));
}
public static function isRunningLocally(): bool
{
return str_starts_with(base_path(), 'phar://'.Platform::cwd('vendor/bin'));
}
public static function readConfig(string $key): string|array|null
{
$cfg = FileJson::make(Platform::cwd('whisky.json'))->read();
return data_get($cfg, $key);
}
}