fromDirectory($this->argument('path')); $publish = function () use ($installer, $manifest): void { $installer->install($manifest->directory, (bool) $this->option('enable')); $this->components->info('Published '.$manifest->id.'.'); }; if (! $manifest->hasUi()) { $publish(); return self::SUCCESS; } $build = Process::path($manifest->directory)->timeout(300)->run(['npm', 'run', 'build']); if ($build->failed()) { $this->error($build->output().$build->errorOutput()); return self::FAILURE; } $publish(); if ($this->option('watch')) { $assets->watchDevelopment($manifest->id); try { $buffer = ''; $process = Process::path($manifest->directory)->forever()->start(['npm', 'run', 'dev'], function (string $type, string $output) use (&$buffer, $publish): void { $this->output->write($output); $buffer .= $output; if (preg_match('/built in [^\r\n]+[\r\n]/', $buffer)) { $buffer = ''; try { $publish(); } catch (InvalidExtensionException $exception) { $this->components->error($exception->getMessage()); } } $buffer = mb_substr($buffer, -8192); }); $this->trap([SIGINT, SIGTERM], function () use ($process): void { $process->signal(SIGTERM); }); return $process->wait()->exitCode() ?? self::FAILURE; } finally { $assets->stopDevelopment($manifest->id); } } } catch (InvalidExtensionException $invalidExtensionException) { $this->components->error($invalidExtensionException->getMessage()); return self::FAILURE; } return self::SUCCESS; } }