Skip to content

Commit e920c44

Browse files
committed
feat: native:reset command
1 parent 130323a commit e920c44

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

src/Commands/BuildCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BuildCommand extends Command
4040

4141
protected function buildPath(string $path = ''): string
4242
{
43-
return __DIR__.'/../../resources/js/resources/app/'.$path;
43+
return realpath(__DIR__.'/../../resources/js/resources/app/'.$path);
4444
}
4545

4646
protected function sourcePath(string $path = ''): string

src/Commands/ResetCommand.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Native\Electron\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Symfony\Component\Filesystem\Filesystem;
7+
8+
use function Laravel\Prompts\intro;
9+
10+
class ResetCommand extends Command
11+
{
12+
protected $signature = 'native:reset';
13+
14+
protected $description = 'Clear all build and dist files';
15+
16+
public function handle(): int
17+
{
18+
intro('Clearing build and dist directories...');
19+
20+
// Removing and recreating the native serve resource path
21+
$nativeServeResourcePath = realpath(__DIR__.'/../../resources/js/resources/app/');
22+
$this->line('Clearing: '.$nativeServeResourcePath);
23+
24+
$filesystem = new Filesystem;
25+
$filesystem->remove($nativeServeResourcePath);
26+
$filesystem->mkdir($nativeServeResourcePath);
27+
28+
// Removing the bundling directories
29+
$bundlingPath = base_path('build/');
30+
$this->line('Clearing: '.$bundlingPath);
31+
32+
if ($filesystem->exists($bundlingPath)) {
33+
$filesystem->remove($bundlingPath);
34+
}
35+
36+
// Removing the built path
37+
$builtPath = base_path('dist/');
38+
$this->line('Clearing: '.$builtPath);
39+
40+
if ($filesystem->exists($builtPath)) {
41+
$filesystem->remove($builtPath);
42+
}
43+
44+
return 0;
45+
}
46+
}

src/ElectronServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Native\Electron\Commands\DevelopCommand;
99
use Native\Electron\Commands\InstallCommand;
1010
use Native\Electron\Commands\PublishCommand;
11+
use Native\Electron\Commands\ResetCommand;
1112
use Native\Electron\Updater\UpdaterManager;
1213
use Spatie\LaravelPackageTools\Package;
1314
use Spatie\LaravelPackageTools\PackageServiceProvider;
@@ -25,6 +26,7 @@ public function configurePackage(Package $package): void
2526
BuildCommand::class,
2627
PublishCommand::class,
2728
BundleCommand::class,
29+
ResetCommand::class,
2830
]);
2931
}
3032

src/Traits/CopiesBundleToBuildDirectory.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ public function copyBundleToBuildDirectory(): bool
2525
$this->line('From: '.realpath(dirname($this->sourcePath(self::$bundlePath))));
2626
$this->line('To: '.realpath(dirname($this->buildPath(self::$bundlePath))));
2727

28-
(new Filesystem)->copy(
29-
$this->sourcePath(self::$bundlePath),
30-
$this->buildPath(self::$bundlePath),
31-
);
28+
$filesToCopy = [
29+
self::$bundlePath,
30+
'.env',
31+
];
32+
$filesystem = new Filesystem;
33+
foreach ($filesToCopy as $file) {
34+
$filesystem->copy($this->sourcePath($file), $this->buildPath($file), true);
35+
}
3236

3337
return true;
3438
}

0 commit comments

Comments
 (0)