Files
rspade_system/app/RSpade/Commands/Rsx/Manifest_Build_Command.php
root f6fac6c4bc Fix bin/publish: copy docs.dist from project root
Fix bin/publish: use correct .env path for rspade_system
Fix bin/publish script: prevent grep exit code 1 from terminating script

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-21 02:08:33 +00:00

108 lines
3.6 KiB
PHP
Executable File

<?php
/**
* CODING CONVENTION:
* This file follows the coding convention where variable_names and function_names
* use snake_case (underscore_wherever_possible).
*/
namespace App\RSpade\Commands\Rsx;
use App\Console\Commands\FrameworkDeveloperCommand;
use App\RSpade\Core\Manifest\Manifest;
class Manifest_Build_Command extends FrameworkDeveloperCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rsx:manifest:build
{--force : Execute rsx:clean then rsx:manifest:build via PHP exec}
{--clean : Clear all caches before building (forces complete rebuild)}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Build or rebuild the RSX manifest (incremental by default, use --clean for full rebuild)';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
// Handle --force flag: complete clean and rebuild via exec
if ($this->option('force')) {
// Execute rsx:clean
passthru('php artisan rsx:clean');
// Execute rsx:manifest:build without --force to avoid recursion
passthru('php artisan rsx:manifest:build');
// Immediately exit
die();
}
// Check if in production mode with existing manifest
if (config('app.env') === 'production') {
$manifest_file = base_path('storage/rsx-build/manifest_data.php');
if (file_exists($manifest_file)) {
$file_age = time() - filemtime($manifest_file);
// If manifest exists and is older than 5 seconds, block rebuild
if ($file_age > 5) {
$this->error('Production manifest rebuild blocked');
$this->line('');
$this->line('The manifest file exists in production and is ' . round($file_age / 60, 1) . ' minutes old.');
$this->line('Rebuilding the manifest in production is not permitted without explicit confirmation.');
$this->line('');
$this->line('Use --force flag to override this protection and rebuild anyway.');
return 1;
}
}
}
$start_time = microtime(true);
// Reset debug options
Manifest::$_debug_options = [];
// Handle --clean flag: clear caches first
if ($this->option('clean')) {
$this->info('🧹 Clearing caches before build...');
// Clear RSX caches (but not persistent directory)
$this->call('rsx:clean');
Manifest::clear();
}
$this->info('Building RSX manifest...');
// Default behavior: incremental build (don't clear unless --clean was used)
// Manifest::init() handles everything - loading cache and doing incremental updates
Manifest::init();
$stats = Manifest::get_stats();
$elapsed = round((microtime(true) - $start_time) * 1000, 2);
$this->info('Manifest built successfully!');
$this->line('');
$this->line('Summary:');
$this->line(' Build Hash: ' . Manifest::get_build_key());
$this->line(' Total Files: ' . $stats['total_files']);
$this->line(' PHP Classes: ' . $stats['php']);
$this->line(' JS Classes: ' . $stats['js']);
$this->line(' Blade Views: ' . $stats['blade']);
$this->line(' Build Time: ' . $elapsed . 'ms');
// Reset debug options
Manifest::$_debug_options = [];
return 0;
}
}