From 8c671a2826d944d5b0d2e9513c34ef62b3b58023 Mon Sep 17 00:00:00 2001 From: Nicolas Utzinger Date: Sat, 1 Jun 2024 15:14:25 +0200 Subject: [PATCH] Unbroken previous change for removing publish command --- src/Commands/BuildCommand.php | 30 ++++++-------------- src/Commands/PublishCommand.php | 49 +++++++++++++++++++++++++++++++++ src/ElectronServiceProvider.php | 1 + src/Traits/OsAndArch.php | 22 +++++++++++++++ 4 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 src/Commands/PublishCommand.php create mode 100644 src/Traits/OsAndArch.php diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index d8cbaf9a..3026373a 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -7,6 +7,7 @@ use Illuminate\Support\Str; use Native\Electron\Concerns\LocatesPhpBinary; use Native\Electron\Facades\Updater; +use Native\Electron\Traits\OsAndArch; use function Laravel\Prompts\confirm; use function Laravel\Prompts\select; @@ -14,10 +15,11 @@ class BuildCommand extends Command { use LocatesPhpBinary; + use OsAndArch; protected $signature = 'native:build {os? : The operating system to build for (all, linux, mac, win)} - {arch? : The Processor Architecture to build for (x64, x86, arm64)} + {arch? : The Processor Architecture to build for (-x64, -x86, -arm64)} {pub? : Publish the app (false, true)}'; public function handle(): void @@ -46,7 +48,7 @@ public function handle(): void // Default params to "build:all" command $arch = ''; - $publish = 'build'; + $publish = false; if ($os != 'all') { // Depends on the currenty available php executables if (! $arch = $this->argument('arch')) { @@ -65,12 +67,13 @@ public function handle(): void $publish = confirm( label: 'Should the App be published?', default: false - ) - ? 'publish' - : 'build' ; + ); } } + // Transform $publish from bool to string + $publish = $publish ? 'publish' : 'build'; + Process::path(__DIR__.'/../../resources/js/') ->env($this->getEnvironmentVariables()) ->forever() @@ -101,21 +104,4 @@ protected function getEnvironmentVariables(): array ); } - protected function getDefaultOs(): string - { - return match (PHP_OS_FAMILY) { - 'Windows' => 'win', - 'Darwin' => 'mac', - 'Linux' => 'linux', - default => 'all', - }; - } - - protected function getArchForOs(string $os): array { - return match ($os) { - 'win' => ['-x64'], - 'mac' => ['-x86', '-arm', 'all'], - 'linux' => ['-x64'] - }; - } } diff --git a/src/Commands/PublishCommand.php b/src/Commands/PublishCommand.php new file mode 100644 index 00000000..5875b231 --- /dev/null +++ b/src/Commands/PublishCommand.php @@ -0,0 +1,49 @@ +info('Building and publishing NativePHP app…'); + + if (! $os = $this->argument('os')) { + // Dependos on available publish commands + $os = select( + label: 'Please select the operating system to build for', + options: ['win', 'linux', 'mac'], + default: $this->getDefaultOs(), + ); + } + + // Depends on the currenty available php executables + if (! $arch = $this->argument('arch')) { + $arch = select( + label: 'Please select Processor Architecture', + options: ($a = $this->getArchForOs($os)), + default: $a[0] + ); + if ($arch == 'all') { + $arch = ''; + } + } + + Artisan::call("native:build", ['os'=>$os, 'arch' => $arch, 'pub' => true ], $this->output); + } +} diff --git a/src/ElectronServiceProvider.php b/src/ElectronServiceProvider.php index c8319937..6e4d193c 100644 --- a/src/ElectronServiceProvider.php +++ b/src/ElectronServiceProvider.php @@ -22,6 +22,7 @@ public function configurePackage(Package $package): void InstallCommand::class, DevelopCommand::class, BuildCommand::class, + PublishCommand::class, QueueWorkerCommand::class, ]); } diff --git a/src/Traits/OsAndArch.php b/src/Traits/OsAndArch.php new file mode 100644 index 00000000..ee3b9082 --- /dev/null +++ b/src/Traits/OsAndArch.php @@ -0,0 +1,22 @@ + 'win', + 'Darwin' => 'mac', + 'Linux' => 'linux', + default => 'all', + }; + } + + protected function getArchForOs(string $os): array { + return match ($os) { + 'win' => ['-x64'], + 'mac' => ['-x86', '-arm', 'all'], + 'linux' => ['-x64'] + }; + } +}