Skip to content

Commit

Permalink
Unbroken previous change for removing publish command
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Utzinger committed Jun 1, 2024
1 parent a066072 commit 8c671a2
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 22 deletions.
30 changes: 8 additions & 22 deletions src/Commands/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
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;

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
Expand Down Expand Up @@ -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')) {
Expand All @@ -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()
Expand Down Expand Up @@ -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']
};
}
}
49 changes: 49 additions & 0 deletions src/Commands/PublishCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Native\Electron\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Native\Electron\Concerns\LocatesPhpBinary;
use Native\Electron\Traits\OsAndArch;

use function Laravel\Prompts\confirm;
use function Laravel\Prompts\select;

class PublishCommand extends Command
{
use LocatesPhpBinary;
use OsAndArch;

protected $signature = 'native:publish
{os? : The operating system to build for (linux, mac, win)}
{arch? : The Processor Architecture to build for (-x64, -x86, -arm64)}';

public function handle(): void
{
$this->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);
}
}
1 change: 1 addition & 0 deletions src/ElectronServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function configurePackage(Package $package): void
InstallCommand::class,
DevelopCommand::class,
BuildCommand::class,
PublishCommand::class,
QueueWorkerCommand::class,
]);
}
Expand Down
22 changes: 22 additions & 0 deletions src/Traits/OsAndArch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace Native\Electron\Traits;

trait OsAndArch {
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']
};
}
}

0 comments on commit 8c671a2

Please sign in to comment.