-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathViewBuildCommand.php
More file actions
40 lines (28 loc) · 995 Bytes
/
Copy pathViewBuildCommand.php
File metadata and controls
40 lines (28 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace Leaf\Console;
use Leaf\Sprout\Command;
class ViewBuildCommand extends Command
{
protected $signature = 'view:build {--pm=npm}';
protected $description = 'Build your frontend assets';
protected function handle(): int
{
if (!sprout()->npm()->json()) {
$this->writeln('<error>No package.json found in the current directory.</error>');
return 1;
}
if (!sprout()->npm()->hasDependencies()) {
$this->writeln('<info>Installing dependencies...</info>');
if (!sprout()->npm($this->option('pm'))->install()->isSuccessful()) {
$this->writeln('<error>❌ Failed to install dependencies.</error>');
return 1;
}
}
$this->writeln('<info>Building assets...</info>');
return sprout()
->npm($this->option('pm'))
->runScript('build')
->isSuccessful() ? 0 : 1;
}
}