|
9 | 9 |
|
10 | 10 | class ResetCommand extends Command
|
11 | 11 | {
|
12 |
| - protected $signature = 'native:reset'; |
| 12 | + protected $signature = 'native:reset {--with-app-data : Clear the app data as well}'; |
13 | 13 |
|
14 | 14 | protected $description = 'Clear all build and dist files';
|
15 | 15 |
|
@@ -41,6 +41,38 @@ public function handle(): int
|
41 | 41 | $filesystem->remove($builtPath);
|
42 | 42 | }
|
43 | 43 |
|
| 44 | + if ($this->option('with-app-data')) { |
| 45 | + |
| 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']; |
| 50 | + |
| 51 | + $appDataPath = $this->appDataDirectory($appName); |
| 52 | + $this->line('Clearing: '.$appDataPath); |
| 53 | + |
| 54 | + if ($filesystem->exists($appDataPath)) { |
| 55 | + $filesystem->remove($appDataPath); |
| 56 | + } |
| 57 | + } |
| 58 | + |
44 | 59 | return 0;
|
45 | 60 | }
|
| 61 | + |
| 62 | + protected function appDataDirectory(string $name): string |
| 63 | + { |
| 64 | + /* |
| 65 | + * Platform Location |
| 66 | + * macOS ~/Library/Application Support |
| 67 | + * Linux $XDG_CONFIG_HOME or ~/.config |
| 68 | + * Windows %APPDATA% |
| 69 | + */ |
| 70 | + |
| 71 | + return match (PHP_OS_FAMILY) { |
| 72 | + 'Darwin' => $_SERVER['HOME'].'/Library/Application Support/'.$name, |
| 73 | + 'Linux' => $_SERVER['XDG_CONFIG_HOME'] ?? $_SERVER['HOME'].'/.config/'.$name, |
| 74 | + 'Windows' => $_SERVER['APPDATA'].'/'.$name, |
| 75 | + default => $_SERVER['HOME'].'/.config/'.$name, |
| 76 | + }; |
| 77 | + } |
46 | 78 | }
|
0 commit comments