1: <?php
2:
3: namespace LaravelUi5\Core\Commands\Concerns;
4:
5: use Illuminate\Support\Facades\File;
6: use LogicException;
7: use Symfony\Component\Process\Process;
8:
9: trait RunsUi5Build
10: {
11: protected function runBuild(string $path): void
12: {
13: $packageJson = $path . '/package.json';
14:
15: if (!File::exists($packageJson)) {
16: throw new LogicException(
17: "Cannot run UI5 build: package.json not found in {$path}"
18: );
19: }
20:
21: $data = json_decode(
22: file_get_contents($packageJson),
23: true
24: );
25:
26: if (!isset($data['scripts']['build'])) {
27: throw new LogicException(
28: "Cannot run UI5 build: no build script defined in package.json"
29: );
30: }
31:
32: $builder = $data['scripts']['build'];
33:
34: $process = Process::fromShellCommandline(
35: $builder,
36: $path
37: );
38:
39: $process->setTimeout(null);
40: $process->run(function ($type, $buffer) {
41: echo $buffer;
42: });
43:
44: if (!$process->isSuccessful()) {
45: throw new LogicException('UI5 build failed.');
46: }
47: }
48: }
49: