Skip to content

Commit 130323a

Browse files
committed
feat: bundling a base L12 app works 🎉
1 parent 666f68b commit 130323a

File tree

5 files changed

+66
-18
lines changed

5 files changed

+66
-18
lines changed

‎resources/js/electron-builder.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,7 @@ try {
4040
}
4141

4242
if (isBuilding) {
43-
console.log();
44-
console.log('===================================================================');
45-
console.log(' Building for ' + targetOs);
46-
console.log('===================================================================');
47-
console.log();
48-
console.log('Updater config', updaterConfig);
49-
console.log();
43+
console.log(' • updater config', updaterConfig);
5044
}
5145

5246
export default {

‎src/Commands/BuildCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Illuminate\Support\Str;
88
use Native\Electron\Facades\Updater;
99
use Native\Electron\Traits\CleansEnvFile;
10+
use Native\Electron\Traits\CopiesBundleToBuildDirectory;
1011
use Native\Electron\Traits\CopiesCertificateAuthority;
11-
use Native\Electron\Traits\CopiesToBuildDirectory;
1212
use Native\Electron\Traits\HasPreAndPostProcessing;
1313
use Native\Electron\Traits\InstallsAppIcon;
1414
use Native\Electron\Traits\LocatesPhpBinary;
@@ -22,8 +22,8 @@
2222
class BuildCommand extends Command
2323
{
2424
use CleansEnvFile;
25+
use CopiesBundleToBuildDirectory;
2526
use CopiesCertificateAuthority;
26-
use CopiesToBuildDirectory;
2727
use HasPreAndPostProcessing;
2828
use InstallsAppIcon;
2929
use LocatesPhpBinary;
@@ -79,7 +79,8 @@ public function handle(): void
7979

8080
$this->newLine();
8181
intro('Copying App to build directory...');
82-
$this->copyToBuildDirectory();
82+
83+
$this->copyBundleToBuildDirectory();
8384

8485
$this->newLine();
8586
$this->copyCertificateAuthorityCertificate();

‎src/Commands/BundleCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ private function addFilesToZip(ZipArchive $zip): void
222222

223223
$finder = (new Finder)->files()
224224
// ->followLinks()
225-
->ignoreVCSIgnored(true) // TODO: Make our own list of ignored files
225+
// ->ignoreVCSIgnored(true) // TODO: Make our own list of ignored files
226226
->in($this->buildPath())
227227
->exclude([
228-
// We add those a few lines below
228+
// We add those a few lines below and they are ignored by most .gitignore anyway
229229
'vendor',
230230
'node_modules',
231231

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Native\Electron\Traits;
4+
5+
use Symfony\Component\Filesystem\Filesystem;
6+
7+
use function Laravel\Prompts\warning;
8+
9+
trait CopiesBundleToBuildDirectory
10+
{
11+
use CopiesToBuildDirectory;
12+
13+
protected static string $bundlePath = 'build/__nativephp_app_bundle';
14+
15+
protected function hasBundled(): bool
16+
{
17+
return (new Filesystem)->exists($this->sourcePath(self::$bundlePath));
18+
}
19+
20+
public function copyBundleToBuildDirectory(): bool
21+
{
22+
if ($this->hasBundled()) {
23+
24+
$this->line('Copying secure app bundle to build directory...');
25+
$this->line('From: '.realpath(dirname($this->sourcePath(self::$bundlePath))));
26+
$this->line('To: '.realpath(dirname($this->buildPath(self::$bundlePath))));
27+
28+
(new Filesystem)->copy(
29+
$this->sourcePath(self::$bundlePath),
30+
$this->buildPath(self::$bundlePath),
31+
);
32+
33+
return true;
34+
}
35+
36+
$this->warnUnsecureBuild();
37+
38+
return $this->copyToBuildDirectory();
39+
}
40+
41+
public function warnUnsecureBuild(): void
42+
{
43+
warning('===================================================================');
44+
warning(' * * * INSECURE BUILD * * *');
45+
warning('===================================================================');
46+
warning('Secure app bundle not found! Building with exposed source files.');
47+
warning('See https://nativephp.com/docs/publishing/building#security');
48+
warning('===================================================================');
49+
}
50+
}

‎src/Traits/CopiesToBuildDirectory.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ abstract protected function sourcePath(string $path = ''): string;
2727
// .git and dev directories
2828
'.git',
2929
'dist',
30+
'build',
31+
'temp',
3032
'docker',
3133
'packages',
3234
'**/.github',
@@ -51,13 +53,9 @@ abstract protected function sourcePath(string $path = ''): string;
5153

5254
// Also deleted in PrunesVendorDirectory after fresh composer install
5355
'vendor/bin',
54-
55-
// Exlude build & temp directory
56-
'build',
57-
'temp',
5856
];
5957

60-
public function copyToBuildDirectory()
58+
public function copyToBuildDirectory(): bool
6159
{
6260
$sourcePath = $this->sourcePath();
6361
$buildPath = $this->buildPath();
@@ -73,7 +71,10 @@ public function copyToBuildDirectory()
7371
$filesystem->mkdir($buildPath);
7472

7573
// A filtered iterator that will exclude files matching our skip patterns
76-
$directory = new RecursiveDirectoryIterator($sourcePath, RecursiveDirectoryIterator::SKIP_DOTS | RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
74+
$directory = new RecursiveDirectoryIterator(
75+
$sourcePath,
76+
RecursiveDirectoryIterator::SKIP_DOTS | RecursiveDirectoryIterator::FOLLOW_SYMLINKS
77+
);
7778

7879
$filter = new RecursiveCallbackFilterIterator($directory, function ($current) use ($patterns) {
7980
$relativePath = substr($current->getPathname(), strlen($this->sourcePath()) + 1);
@@ -113,6 +114,8 @@ public function copyToBuildDirectory()
113114
}
114115

115116
$this->keepRequiredDirectories();
117+
118+
return true;
116119
}
117120

118121
private function keepRequiredDirectories()

0 commit comments

Comments
 (0)