8000 feat: Better reset command · NativePHP/electron@d28ed6b · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit d28ed6b

Browse files
committed
feat: Better reset command
1 parent cba4063 commit d28ed6b

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/Commands/ResetCommand.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
namespace Native\Electron\Commands;
44

55
use Illuminate\Console\Command;
6+
use Native\Electron\Traits\SetsAppName;
67
use Symfony\Component\Filesystem\Filesystem;
78

89
use function Laravel\Prompts\intro;
910

1011
class ResetCommand extends Command
1112
{
13+
use SetsAppName;
14+
1215
protected $signature = 'native:reset {--with-app-data : Clear the app data as well}';
1316

1417
protected $description = 'Clear all build and dist files';
@@ -43,18 +46,17 @@ public function handle(): int
4346

4447
if ($this->option('with-app-data')) {
4548

46-
// Fetch last generated app name
47-
$packageJsonPath = __DIR__.'/../../resources/js/package.json';
48-
$packageJson = json_decode(file_get_contents($packageJsonPath), true);
49-
$appName = $packageJson['name'];
49+
foreach ([true, false] as $developmentMode) {
50+
$appName = $this->setAppName($developmentMode);
5051

51-
// Eh, just in case, I don't want to delete all user data by accident.
52-
if (! empty($appName)) {
53-
$appDataPath = $this->appDataDirectory($appName);
54-
$this->line('Clearing: '.$appDataPath);
52+
// Eh, just in case, I don't want to delete all user data by accident.
53+
if ( ! empty($appName)) {
54+
$appDataPath = $this->appDataDirectory($appName);
55+
$this->line('Clearing: '.$appDataPath);
5556

56-
if ($filesystem->exists($appDataPath)) {
57-
$filesystem->remove($appDataPath);
57+
if ($filesystem->exists($appDataPath)) {
58+
$filesystem->remove($appDataPath);
59+
}
5860
}
5961
}
6062
}

src/Traits/SetsAppName.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
trait SetsAppName
66
{
7-
protected function setAppName($developmentMode = false): void
7+
protected function setAppName($developmentMode = false): string
88
{
99
$packageJsonPath = __DIR__.'/../../resources/js/package.json';
1010
$packageJson = json_decode(file_get_contents($packageJsonPath), true);
@@ -23,5 +23,7 @@ protected function setAppName($developmentMode = false): void
2323
$packageJson['name'] = $name;
2424

2525
file_put_contents($packageJsonPath, json_encode($packageJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
26+
27+
return $name;
2628
}
2729
}

0 commit comments

Comments
 (0)
0