47 lines
1.3 KiB
Markdown
47 lines
1.3 KiB
Markdown
---
|
|
created: 2025-07-09 10:20
|
|
updated: 2025-07-09 10:20
|
|
---
|
|
```bash
|
|
php artisan make:command AuditDependenciesCommand
|
|
```
|
|
|
|
```php
|
|
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Exception;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Process;
|
|
use Spatie\LaravelIgnition\Facades\Flare;
|
|
|
|
class AuditDependenciesCommand extends Command
|
|
{
|
|
protected $signature = 'app:audit-dependencies';
|
|
|
|
public function handle(): void
|
|
{
|
|
$composer = Process::run('composer audit');
|
|
|
|
if (!blank($composer->output())) {
|
|
$this->warn('Composer audit found vulnerabilities');
|
|
Log::warning('Composer audit found vulnerabilities', ['output' => $composer->output()]);
|
|
Flare::report(new Exception('Composer audit found vulnerabilities'));
|
|
}
|
|
|
|
$npm = Process::run('npm audit');
|
|
|
|
if (trim($npm->output()) !== "found 0 vulnerabilities") {
|
|
$this->warn('NPM audit found vulnerabilities');
|
|
Log::warning('NPM audit found vulnerabilities', ['output' => $npm->output()]);
|
|
Flare::report(new Exception('NPM audit found vulnerabilities'));
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
```php kernel
|
|
$schedule->command(\App\Console\Commands\AuditDependenciesCommand::class)->daily();
|
|
``` |