plakhin / laravel-artisan-watcher
A Laravel Artisan package to watch for file changes and automatically execute commands
Fund package maintenance!
plakhin
Requires
- php: ^8.3
- illuminate/contracts: ^11.0|^12.0
Requires (Dev)
- larastan/larastan: ^3.1
- laravel/pint: ^1.21
- orchestra/testbench: ^9.0|^10.0
- pestphp/pest: ^3.7
- pestphp/pest-plugin-laravel: ^3.1
- pestphp/pest-plugin-type-coverage: ^3.3
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- rector/rector: ^2.0
This package is auto-updated.
Last update: 2025-05-12 00:36:42 UTC
README
Laravel Artisan Watcher
A Laravel package that provides file watching functionality to automatically execute a CLI or Artisan command when files change. This is useful for automatically running tests, linting, or any other command when your files are modified during development.
Warning
Very early alpha — pure proof of concept.
Believe it or not, ~95% of this package’s code is AI-generated under 10 minutes with a single prompt!
For the full story, check out the PR.
Installation
You can install the package via composer:
composer require plakhin/laravel-artisan-watcher --dev
Usage
The package adds an artisan watch
command that you can use to watch for file changes and trigger commands:
# Watch current directory and run tests when PHP files change php artisan watch --command="php artisan test" # Watch a specific directory for changes to JS files php artisan watch app/Http --extensions=js --command="npm run lint" # Watch with custom polling interval (in seconds) php artisan watch --interval=2 --command="php artisan test" # Exclude multiple directories php artisan watch --exclude=vendor,node_modules,storage --command="php artisan test"
Available Options
path
: The directory to watch (default: current directory)--command
: The command to run when files change (required)--interval
: Polling interval in seconds (default: 1)--extensions
: Comma-separated list of file extensions to watch (default: php)--exclude
: Comma-separated list of directories to exclude (default: vendor,node_modules)
Example Use Cases
-
Automatically run tests when files change:
php artisan watch --command="php artisan test"
-
Automatically compile assets when JavaScript or SCSS files change:
php artisan watch resources --extensions=js,scss --command="npm run dev"
-
Run type checking when PHP files change:
php artisan watch --command="php artisan test:types"
Contributing
Contributions are welcome, and are accepted via pull requests. Please review these guidelines before submitting any pull requests.
Process
- Fork the project
- Create a new branch
- Code, test, commit and push
- Open a pull request detailing your changes.
Guidelines
- Please ensure the coding style running
composer lint
. - Please keep the codebase modernized using automated refactors with Rector
composer refactor
. - Send a coherent commit history, making sure each individual commit in your pull request is meaningful.
- You may need to rebase to avoid merge conflicts.
- Please remember to follow SemVer.
Linting
composer lint
Refactoring with Rector
composer refactor
Testing
Run all tests:
composer test
Check code style:
composer test:lint
Check possible code improvements:
composer test:refactor
Check types:
composer test:types
Run Unit tests:
composer test:unit
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.