Skip to content

Commit f62b4e1

Browse files
authored
Merge pull request #14 from jaguarch/master
throw an exception error if the package isn't initialized
2 parents 72d0bf3 + aa771c6 commit f62b4e1

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/Decorator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ class Decorator implements ViewDecoratorInterface
88
{
99
public static function decorate(string $html): string
1010
{
11-
# Check if vite is running or manifest is ready.
12-
if (Vite::isReady() && env('VITE_AUTO_INJECTING'))
11+
# Check whether vite is running or manifest is ready.
12+
if (env('VITE_AUTO_INJECTING'))
1313
{
14+
if (Vite::isReady() === false)
15+
{
16+
throw new \Exception('CodeignIter Vite package is installed, but not initialized. did you run "php spark vite:init" ?');
17+
}
18+
1419
# First inject app div
1520
$html = str_replace('<body>', "<body>\n\t<div id=\"app\">", $html);
1621
# Close the div

src/Vite.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,25 @@ public static function getReactTag(): ?string
8686
}
8787

8888
/**
89-
* Check if the vite is running or manifest does exist.
89+
* Check whether vite is running or manifest does exist.
9090
*
9191
* @return bool true if vite is runnig or if manifest does exist, otherwise false;
9292
*/
9393
public static function isReady(): bool
9494
{
95-
# Check if vite is running.
9695
$entryFile = env('VITE_ORIGIN') . '/' . env('VITE_RESOURCES_DIR') . '/' . env('VITE_ENTRY_FILE');
9796

9897
switch (true)
9998
{
10099
case @file_get_contents($entryFile):
101100
$result = true;
102101
break;
103-
case !empty(self::$manifest):
102+
case is_file(self::$manifest):
104103
$result = true;
105104
break;
106105

107106
default:
108107
$result = false;
109-
break;
110108
}
111109

112110
return $result;

0 commit comments

Comments
 (0)