Skip to content

Commit b3ecbf6

Browse files
committed
fix: realpath() returns false if the directory does not exists
1 parent e920c44 commit b3ecbf6

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/Commands/BuildCommand.php

Lines changed: 1 addition & 2 deletions
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 realpath(__DIR__.'/../../resources/js/resources/app/'.$path);
43+
return __DIR__.'/../../resources/js/resources/app/'.$path;
4444
}
4545

4646
protected function sourcePath(string $path = ''): string
@@ -79,7 +79,6 @@ public function handle(): void
7979

8080
$this->newLine();
8181
intro('Copying App to build directory...');
82-
8382
$this->copyBundleToBuildDirectory();
8483

8584
$this->newLine();

src/Commands/ResetCommand.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class ResetCommand extends Command
1111
{
12-
protected $signature = 'native:reset';
12+
protected $signature = 'native:reset {--with-app-data : Clear the app data as well}';
1313

1414
protected $description = 'Clear all build and dist files';
1515

@@ -41,6 +41,38 @@ public function handle(): int
4141
$filesystem->remove($builtPath);
4242
}
4343

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+
4459
return 0;
4560
}
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+
}
4678
}

0 commit comments

Comments
 (0)