Skip to content

Commit eff93e3

Browse files
committed
update: Synchronize the latest version of Monitor
1 parent aaaa8b5 commit eff93e3

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

src/Built/Factory.php

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212

1313
namespace Laravel\Ripple\Built;
1414

15+
use FilesystemIterator;
1516
use Illuminate\Foundation\Application;
17+
use Illuminate\Support\Facades\Config;
18+
use RecursiveDirectoryIterator;
19+
use RecursiveIteratorIterator;
1620
use Ripple\File\File;
1721
use Ripple\File\Monitor;
1822

19-
use function base_path;
20-
use function file_exists;
23+
use function is_dir;
24+
use function array_shift;
25+
use function is_file;
2126

2227
class Factory
2328
{
@@ -98,15 +103,41 @@ public static function defaultServicesToWarm(): array
98103
*/
99104
public static function createMonitor(): Monitor
100105
{
101-
$monitor = File::getInstance()->monitor();
102-
$monitor->add(base_path('/app'));
103-
$monitor->add(base_path('/bootstrap'));
104-
$monitor->add(base_path('/config'));
105-
$monitor->add(base_path('/routes'));
106-
$monitor->add(base_path('/resources'));
107-
if (file_exists(base_path('/.env'))) {
108-
$monitor->add(base_path('/.env'));
106+
$monitor = File::getInstance()->monitor();
107+
$watchPaths = Config::get('ripple.WATCH_PATHS', []);
108+
109+
$after = [];
110+
111+
foreach ($watchPaths as $path) {
112+
if (is_file($path)) {
113+
$monitor->add($path);
114+
}
115+
116+
if (is_dir($path)) {
117+
$iterator = new RecursiveIteratorIterator(
118+
new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS),
119+
RecursiveIteratorIterator::SELF_FIRST
120+
);
121+
122+
/*** @var \SplFileInfo $file */
123+
foreach ($iterator as $file) {
124+
if ($file->isDir()) {
125+
$after[] = $file->getPathname();
126+
}
127+
128+
if ($file->isFile()) {
129+
$monitor->add($file->getPathname());
130+
}
131+
}
132+
133+
$after[] = $path;
134+
}
135+
136+
while ($path = array_shift($after)) {
137+
$monitor->add($path);
138+
}
109139
}
140+
110141
return $monitor;
111142
}
112143
}

src/Config/ripple.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@
1717
'HTTP_LISTEN' => Env::get('RIP_HTTP_LISTEN', 'http://127.0.0.1:8000'),
1818
'HTTP_WORKERS' => Env::get('RIP_HTTP_WORKERS', 1),
1919
'WATCH' => Env::get('RIP_WATCH', 1),
20+
'WATCH_PATHS' => [
21+
\base_path('/app'),
22+
\base_path('/bootstrap'),
23+
\base_path('/config'),
24+
\base_path('/routes'),
25+
\base_path('/resources'),
26+
\base_path('/.env')
27+
]
2028
];

src/Virtual/server.bin.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ function app(?string $abstract = null, array $parameters = []): mixed
141141
Output::writeln("[{$date}] {$file} has been modified");
142142
}
143143
};
144+
144145
$hotReloadWatch = Factory::createMonitor();
146+
$hotReloadWatch->onTouch = static fn () => \__rip_restart($projectChannel);
147+
$hotReloadWatch->onRemove = static fn () => \__rip_restart($projectChannel);
145148
$hotReloadWatch->onModify = $hotReload;
146-
$hotReloadWatch->onTouch = $hotReload;
147-
$hotReloadWatch->onRemove = $hotReload;
148149
if (RIP_WATCH) {
149150
$hotReloadWatch->run();
150151
}

0 commit comments

Comments
 (0)