Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ testbench.yaml
vendor
node_modules
.DS_Store
!tests/Build
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@
},
"autoload": {
"psr-4": {
"Native\\Desktop\\": "src/Desktop",
"Native\\Electron\\": "src/Electron"
"Native\\Desktop\\": "src"
}
},
"autoload-dev": {
Expand Down Expand Up @@ -92,8 +91,7 @@
"extra": {
"laravel": {
"providers": [
"Native\\Desktop\\NativeServiceProvider",
"Native\\Electron\\ElectronServiceProvider"
"Native\\Desktop\\NativeServiceProvider"
],
"aliases": {
"ChildProcess": "Native\\Desktop\\Facades\\ChildProcess",
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ parameters:


excludePaths:
- ./src/Desktop/NativeServiceProvider.php
- ./src/NativeServiceProvider.php
Binary file added resources/electron/build/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
50 changes: 50 additions & 0 deletions src/Builder/Builder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Native\Desktop\Builder;

use Native\Desktop\Builder\Concerns\CleansEnvFile;
use Native\Desktop\Builder\Concerns\CopiesBundleToBuildDirectory;
use Native\Desktop\Builder\Concerns\CopiesCertificateAuthority;
use Native\Desktop\Builder\Concerns\CopiesToBuildDirectory;
use Native\Desktop\Builder\Concerns\HasPreAndPostProcessing;
use Native\Desktop\Builder\Concerns\LocatesPhpBinary;
use Native\Desktop\Builder\Concerns\PrunesVendorDirectory;
use Symfony\Component\Filesystem\Path;

class Builder
{
use CleansEnvFile;
use CopiesBundleToBuildDirectory;
use CopiesCertificateAuthority;
use CopiesToBuildDirectory;
use HasPreAndPostProcessing;
use LocatesPhpBinary;
use PrunesVendorDirectory;

public function __construct(
private string $buildPath,
private ?string $sourcePath = null,
) {

$this->sourcePath = $sourcePath
? $sourcePath
: base_path();
}

public static function make(
string $buildPath,
?string $sourcePath = null
) {
return new self($buildPath, $sourcePath);
}

public function buildPath(string $path = ''): string
{
return Path::join($this->buildPath, $path);
}

public function sourcePath(string $path = ''): string
{
return Path::join($this->sourcePath, $path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
/**
* This trait is responsible for cleaning any sensitive information from the .env file
* and also injects some defaults that need to be set as soon as possible.
*
* TODO: When more drivers/adapters are added, this should be relocated
*/

namespace Native\Electron\Traits;
namespace Native\Desktop\Builder\Concerns;

trait CleansEnvFile
{
abstract protected function buildPath(string $path = ''): string;
abstract public function buildPath(string $path = ''): string;

public array $overrideKeys = [
'LOG_CHANNEL',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Native\Electron\Traits;
namespace Native\Desktop\Builder\Concerns;

use Symfony\Component\Filesystem\Filesystem;

Expand All @@ -12,7 +12,7 @@ trait CopiesBundleToBuildDirectory

protected static string $bundlePath = 'build/__nativephp_app_bundle';

protected function hasBundled(): bool
public function hasBundled(): bool
{
return (new Filesystem)->exists($this->sourcePath(self::$bundlePath));
}
Expand All @@ -21,9 +21,9 @@ public function copyBundleToBuildDirectory(): bool
{
$filesystem = new Filesystem;

$this->line('Copying secure app bundle to build directory...');
$this->line('From: '.realpath(dirname($this->sourcePath(self::$bundlePath))));
$this->line('To: '.realpath(dirname($this->buildPath(self::$bundlePath))));
echo 'Copying secure app bundle to build directory...'.PHP_EOL;
echo 'From: '.realpath(dirname($this->sourcePath(self::$bundlePath))).PHP_EOL;
echo 'To: '.realpath(dirname($this->buildPath(self::$bundlePath))).PHP_EOL;

// Clean and create build directory
$filesystem->remove($this->buildPath());
Expand All @@ -36,7 +36,7 @@ public function copyBundleToBuildDirectory(): bool
foreach ($filesToCopy as $file) {
$filesystem->copy($this->sourcePath($file), $this->buildPath($file), true);
}
// $this->keepRequiredDirectories();
$this->keepRequiredDirectories();

return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
<?php

namespace Native\Electron\Traits;
namespace Native\Desktop\Builder\Concerns;

use Composer\InstalledVersions;
use Native\Electron\ElectronServiceProvider;
use Symfony\Component\Filesystem\Path;

use function Laravel\Prompts\error;
use function Laravel\Prompts\intro;
use function Laravel\Prompts\warning;

trait CopiesCertificateAuthority
{
protected function copyCertificateAuthorityCertificate(): void
abstract public function buildPath(string $path = ''): string;

public function copyCertificateAuthority(string $path): void
{
try {
intro('Copying latest CA Certificate...');

$vendorDirectory = realpath(InstalledVersions::getRootPackage()['install_path'].'/vendor');
$phpBinaryDirectory = $vendorDirectory.'/nativephp/php-bin/';

Expand All @@ -31,7 +29,7 @@ protected function copyCertificateAuthorityCertificate(): void

$copied = copy(
$certFilePath,
Path::join(ElectronServiceProvider::ELECTRON_PATH, 'resources', $certificateFileName)
"{$path}/{$certificateFileName}"
);

if (! $copied) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
/**
* This trait is responsible for copying over the app to the build directory.
* It skips any ignored paths/globs during the copy step
*
* TODO: When more drivers/adapters are added, this should be relocated
*/

namespace Native\Electron\Traits;
namespace Native\Desktop\Builder\Concerns;

use RecursiveCallbackFilterIterator;
use RecursiveDirectoryIterator;
Expand All @@ -19,9 +17,9 @@

trait CopiesToBuildDirectory
{
abstract protected function buildPath(string $path = ''): string;
abstract public function buildPath(string $path = ''): string;

abstract protected function sourcePath(string $path = ''): string;
abstract public function sourcePath(string $path = ''): string;

public function copyToBuildDirectory(): bool
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Native\Electron\Traits;
namespace Native\Desktop\Builder\Concerns;

use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Process;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

namespace Native\Electron\Traits;
namespace Native\Desktop\Builder\Concerns;

trait LocatesPhpBinary
{
abstract public function sourcePath(string $path = ''): string;

/**
* @return string The path to the binary package directory
*/
Expand All @@ -19,6 +21,6 @@ protected function binaryPackageDirectory(): string
*/
public function phpBinaryPath(): string
{
return $this->binaryPackageDirectory().'bin/';
return $this->sourcePath($this->binaryPackageDirectory().'bin/');
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
<?php

/**
* TODO: When more drivers/adapters are added, this should be relocated
*/

namespace Native\Electron\Traits;
namespace Native\Desktop\Builder\Concerns;

use Illuminate\Support\Facades\Process;
use Symfony\Component\Filesystem\Filesystem;

trait PrunesVendorDirectory
{
abstract protected function buildPath(string $path = ''): string;
abstract public function buildPath(string $path = ''): string;

protected function pruneVendorDirectory()
public function pruneVendorDirectory()
{
Process::path($this->buildPath())
->timeout(300)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Native\Desktop\Contracts;

use Native\Desktop\DTOs\QueueConfig;
use Native\Desktop\DataObjects\QueueConfig;

interface QueueWorker
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Native\Desktop\DTOs;
namespace Native\Desktop\DataObjects;

class QueueConfig
{
Expand Down
File renamed without changes.
File renamed without changes.
Loading