99use Illuminate \Support \Facades \Process ;
1010use Illuminate \Support \Number ;
1111use Illuminate \Support \Str ;
12- use Native \Electron \Traits \CleansEnvFile ;
13- use Native \Electron \Traits \CopiesToBuildDirectory ;
1412use Native \Electron \Traits \HandlesZephpyr ;
15- use Native \Electron \Traits \HasPreAndPostProcessing ;
1613use Native \Electron \Traits \InstallsAppIcon ;
17- use Native \Electron \Traits \LocatesPhpBinary ;
1814use Native \Electron \Traits \PatchesPackagesJson ;
19- use Native \Electron \ Traits \ PrunesVendorDirectory ;
15+ use Native \Support \ Bundler ;
2016use Symfony \Component \Console \Attribute \AsCommand ;
2117use Symfony \Component \Finder \Finder ;
2218use ZipArchive ;
2925)]
3026class BundleCommand extends Command
3127{
32- use CleansEnvFile;
33- use CopiesToBuildDirectory;
3428 use HandlesZephpyr;
35- use HasPreAndPostProcessing;
3629 use InstallsAppIcon;
37- use LocatesPhpBinary;
3830 use PatchesPackagesJson;
39- use PrunesVendorDirectory;
4031
4132 protected $ signature = 'native:bundle {--fetch} {--clear} {--without-cleanup} ' ;
4233
@@ -46,6 +37,17 @@ class BundleCommand extends Command
4637
4738 private string $ zipName ;
4839
40+ private Bundler $ bundler ;
41+
42+ public function __construct ()
43+ {
44+ parent ::__construct ();
45+
46+ $ this ->bundler = Bundler::make (
47+ buildPath: base_path ('build/app/ ' )
48+ );
49+ }
50+
4951 public function handle (): int
5052 {
5153 // Remove the bundle
@@ -94,21 +96,19 @@ public function handle(): int
9496 intro ('Copying App to build directory... ' );
9597
9698 // We update composer.json later,
97- $ this ->copyToBuildDirectory ();
99+ $ this ->bundler -> copyToBuildDirectory ();
98100
99101 $ this ->newLine ();
100102 intro ('Cleaning .env file... ' );
101- $ this ->cleanEnvFile ();
103+ $ this ->bundler -> cleanEnvFile ();
102104
103105 $ this ->newLine ();
104106 intro ('Copying app icons... ' );
105107 $ this ->installIcon ();
106108
107109 $ this ->newLine ();
108110 intro ('Pruning vendor directory ' );
109- $ this ->pruneVendorDirectory ();
110-
111- $ this ->cleanEnvFile ();
111+ $ this ->bundler ->pruneVendorDirectory ();
112112
113113 // Check composer.json for symlinked or private packages
114114 if (! $ this ->checkComposerJson ()) {
@@ -161,7 +161,7 @@ private function zipApplication(): bool
161161
162162 private function checkComposerJson (): bool
163163 {
164- $ composerJson = json_decode (file_get_contents ($ this ->buildPath ('composer.json ' )), true );
164+ $ composerJson = json_decode (file_get_contents ($ this ->bundler -> buildPath ('composer.json ' )), true );
165165
166166 // // Fail if there is symlinked packages
167167 // foreach ($composerJson['repositories'] ?? [] as $repository) {
@@ -194,10 +194,10 @@ private function checkComposerJson(): bool
194194
195195 if (count ($ filteredRepo ) !== count ($ composerJson ['repositories ' ])) {
196196 $ composerJson ['repositories ' ] = $ filteredRepo ;
197- file_put_contents ($ this ->buildPath ('composer.json ' ),
197+ file_put_contents ($ this ->bundler -> buildPath ('composer.json ' ),
198198 json_encode ($ composerJson , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ));
199199
200- // Process::path($this->buildPath())
200+ // Process::path($this->bundler-> buildPath())
201201 // ->run('composer install --no-dev', function (string $type, string $output) {
202202 // echo $output;
203203 // });
@@ -228,7 +228,7 @@ private function addFilesToZip(ZipArchive $zip): void
228228 $ finder = (new Finder )->files ()
229229 ->followLinks ()
230230 // ->ignoreVCSIgnored(true) // TODO: Make our own list of ignored files
231- ->in ($ this ->buildPath ())
231+ ->in ($ this ->bundler -> buildPath ())
232232 ->exclude ([
233233 // We add those a few lines below and they are ignored by most .gitignore anyway
234234 'vendor ' ,
@@ -246,39 +246,39 @@ private function addFilesToZip(ZipArchive $zip): void
246246 $ this ->finderToZip ($ finder , $ zip );
247247
248248 // Why do I have to force this? please someone explain.
249- if (file_exists ($ this ->buildPath ('public/build ' ))) {
249+ if (file_exists ($ this ->bundler -> buildPath ('public/build ' ))) {
250250 $ this ->finderToZip (
251251 (new Finder )->files ()
252252 ->followLinks ()
253- ->in ($ this ->buildPath ('public/build ' )), $ zip , 'public/build ' );
253+ ->in ($ this ->bundler -> buildPath ('public/build ' )), $ zip , 'public/build ' );
254254 }
255255
256256 // Add .env file manually because Finder ignores VCS and dot files
257- $ zip ->addFile ($ this ->buildPath ('.env ' ), '.env ' );
257+ $ zip ->addFile ($ this ->bundler -> buildPath ('.env ' ), '.env ' );
258258
259259 // Add auth.json file to support private packages
260260 // WARNING: Only for testing purposes, don't uncomment this
261- // $zip->addFile($this->buildPath('auth.json'), 'auth.json');
261+ // $zip->addFile($this->bundler-> buildPath('auth.json'), 'auth.json');
262262
263263 // Custom binaries
264- $ binaryPath = Str::replaceStart ($ this ->buildPath ('vendor ' ), '' , config ('nativephp.binary_path ' ));
264+ $ binaryPath = Str::replaceStart ($ this ->bundler -> buildPath ('vendor ' ), '' , config ('nativephp.binary_path ' ));
265265
266266 // Add composer dependencies without unnecessary files
267267 $ vendor = (new Finder )->files ()
268268 ->exclude (array_filter ([
269269 'nativephp/php-bin ' ,
270- 'nativephp/electron /resources/electron ' ,
270+ 'nativephp/desktop /resources/electron ' ,
271271 '*/*/vendor ' , // Exclude sub-vendor directories
272272 $ binaryPath ,
273273 ]))
274- ->in ($ this ->buildPath ('vendor ' ));
274+ ->in ($ this ->bundler -> buildPath ('vendor ' ));
275275
276276 $ this ->finderToZip ($ vendor , $ zip , 'vendor ' );
277277
278278 // Add javascript dependencies
279- if (file_exists ($ this ->buildPath ('node_modules ' ))) {
279+ if (file_exists ($ this ->bundler -> buildPath ('node_modules ' ))) {
280280 $ nodeModules = (new Finder )->files ()
281- ->in ($ this ->buildPath ('node_modules ' ));
281+ ->in ($ this ->bundler -> buildPath ('node_modules ' ));
282282
283283 $ this ->finderToZip ($ nodeModules , $ zip , 'node_modules ' );
284284 }
@@ -395,18 +395,8 @@ protected function cleanUp(): void
395395 }
396396 }
397397
398- protected function buildPath (string $ path = '' ): string
399- {
400- return base_path ('build/app/ ' .$ path );
401- }
402-
403398 protected function zipPath (string $ path = '' ): string
404399 {
405400 return base_path ('build/zip/ ' .$ path );
406401 }
407-
408- protected function sourcePath (string $ path = '' ): string
409- {
410- return base_path ($ path );
411- }
412402}
0 commit comments