Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

range-of-motion/budget

1057 stars
1 code files
View range-of-motion/budget on GitHub

app/Console/Commands/BudgetInstall.php

Open in GitHub
use Exception;
use Illuminate\Console\Command;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
 
class BudgetInstall extends Command
{
protected $signature = 'budget:install {--node-package-manager=}';
protected $description = 'Runs most of the commands needed to make Budget work';
 
public function __construct()
{
parent::__construct();
}
 
private function executeCommand($command): string
{
$process = new Process($command);
 
$process->run();
 
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
 
return $process->getOutput();
}
 
private function programExists(string $program): bool
{
try {
$this->executeCommand(['which', $program]);
} catch (Exception $e) {
return false;
}
 
return true;
}
 
public function handle(): void
{
$nodePackageManager = $this->option('node-package-manager');
 
if (!$nodePackageManager) {
$nodePackageManager = $this->choice('Which package manager would you like to use for Node.js?', [
'npm',
'yarn',
]);
}
 
if (!$this->programExists($nodePackageManager)) {
$this->error('Could not find "' . $nodePackageManager . '", will not be able to compile front-end assets');
} else {
$this->info('Installing Node.js packages');
$this->executeCommand([$nodePackageManager, 'install']);
 
$this->info('Compiling front-end assets');
$this->executeCommand([$nodePackageManager, 'run', 'production']);
}
 
$this->executeCommand(['cp', '.env.example', '.env']);
$this->executeCommand(['php', 'artisan', 'key:generate']);
$this->executeCommand(['php', 'artisan', 'storage:link']);
 
$this->info('Done!');
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.