Skip to content

Commit 4cacc76

Browse files
committed
wip
1 parent c1964bd commit 4cacc76

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

app/Whisky.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function __construct()
1515
public static function cwd(string $path = ''): string
1616
{
1717
if ($path) {
18+
$path = str_replace('/', DIRECTORY_SEPARATOR, $path);
1819
return getcwd() . DIRECTORY_SEPARATOR . $path;
1920
}
2021

@@ -23,9 +24,15 @@ public static function cwd(string $path = ''): string
2324

2425
public static function base_path(string $path = ''): string
2526
{
26-
return Phar::running()
27+
if (! Phar::running()) {
28+
return base_path($path);
29+
}
30+
31+
$path = File::exists(Whisky::cwd("vendor/bin/whisky"))
2732
? Whisky::cwd("vendor/projektgopher/whisky/{$path}")
28-
: base_path($path);
33+
: self::getGlobalComposerHome().'/vendor/projektgopher/whisky/'.$path;
34+
35+
return str_replace('/', DIRECTORY_SEPARATOR, $path);
2936
}
3037

3138
public static function readConfig(string $key): string|array
@@ -36,4 +43,9 @@ public static function readConfig(string $key): string|array
3643

3744
return data_get($cfg, $key);
3845
}
46+
47+
public static function getGlobalComposerHome(): string
48+
{
49+
return rtrim(shell_exec('composer -n config --global home'), "\n");
50+
}
3951
}

bin/run-hook

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,24 @@
44
#########################
55

66
# Get the hook name from the first and only argument
7-
hook=$1
7+
HOOK=$1
8+
9+
# Get the path to the whisky binary:
10+
# First, check if it's in the vendor folder.
11+
# If not, check the global composer folder.
12+
# If not, print an error message and exit.
13+
# This currently only supports windows when using git bash or WSL.
14+
if [ -f "./vendor/bin/whisky" ]; then
15+
WHISKY="./vendor/bin/whisky"
16+
elif [ -f "$(composer -n config --global home)/vendor/bin/whisky" ]; then
17+
WHISKY=$(composer -n config --global home)/vendor/bin/whisky
18+
else
19+
printf "Whisky not found. Please run 'composer install' to install it.\n"
20+
exit 1
21+
fi
822

923
# Get a list of scripts to run sequencially for this hook
10-
SCRIPTS=$(./vendor/bin/whisky scripts "$hook")
24+
SCRIPTS=$($WHISKY scripts "$HOOK")
1125

1226
# Make newlines the only separator
1327
IFS=$'\n'

0 commit comments

Comments
 (0)