Skip to content

Commit 279b806

Browse files
committed
refactor: update watch configuration and improve file extension handling
1 parent 12aaf6d commit 279b806

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

config/nutgram.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@
2323
// Set log channel
2424
'log_channel' => env('TELEGRAM_LOG_CHANNEL', 'null'),
2525

26-
// Watch paths used by the "nutgram:run --watch" command
27-
'watch_paths' => [
28-
app_path('Telegram'),
26+
// Watch options used by the "nutgram:run --watch" command
27+
'watch' => [
28+
29+
// The paths to watch for changes
30+
'paths' => [
31+
app_path('Telegram'),
32+
],
33+
34+
// The extensions to watch for changes
35+
'extensions' => [
36+
'php',
37+
],
2938
],
3039
];

src/Console/RunCommand.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function handle(Nutgram $bot): int
3333

3434
$this->info('Watching for changes...');
3535

36-
if(!$this->startAsyncRun()){
36+
if (!$this->startAsyncRun()) {
3737
return Command::FAILURE;
3838
}
3939

@@ -49,20 +49,20 @@ protected function startAsyncRun(): bool
4949
->setTimeout(null);
5050

5151
$this->runProcess->start(function (string $type, string $output) {
52-
if(Process::isTtySupported() && !$this->option('without-tty')) {
52+
if (Process::isTtySupported() && !$this->option('without-tty')) {
5353
$this->output->write($output);
5454
}
5555
});
5656

57-
return ! $this->runProcess->isTerminated();
57+
return !$this->runProcess->isTerminated();
5858
}
5959

6060
protected function listenForChanges(): self
6161
{
62-
Watch::paths(...config('nutgram.watch_paths', []))
62+
Watch::paths(...config('nutgram.watch.paths', []))
6363
->setIntervalTime(200 * 1000)
6464
->onAnyChange(function (string $event, string $path) {
65-
if ($this->isPhpFile($path)) {
65+
if ($this->hasValidExtension($path)) {
6666
$this->restartAsyncRun();
6767
}
6868
})
@@ -71,9 +71,11 @@ protected function listenForChanges(): self
7171
return $this;
7272
}
7373

74-
protected function isPhpFile(string $path): bool
74+
protected function hasValidExtension(string $path): bool
7575
{
76-
return str_ends_with(strtolower($path), '.php');
76+
return collect(config('nutgram.watch.extensions', ['php']))
77+
->map(fn (string $ext) => sprintf(".%s", strtolower($ext)))
78+
->contains(fn (string $ext) => str_ends_with(strtolower($path), $ext));
7779
}
7880

7981
protected function restartAsyncRun(): self

0 commit comments

Comments
 (0)