|
| 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 | +} |
0 commit comments