-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathResetCommand.php
83 lines (63 loc) · 2.52 KB
/
ResetCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Native\Electron\Commands;
use Illuminate\Console\Command;
use Native\Electron\Traits\SetsAppName;
use Symfony\Component\Filesystem\Filesystem;
use function Laravel\Prompts\intro;
class ResetCommand extends Command
{
use SetsAppName;
protected $signature = 'native:reset {--with-app-data : Clear the app data as well}';
protected $description = 'Clear all build and dist files';
public function handle(): int
{
intro('Clearing build and dist directories...');
// Removing and recreating the native serve resource path
$nativeServeResourcePath = realpath(__DIR__.'/../../resources/js/resources/app/');
$this->line('Clearing: '.$nativeServeResourcePath);
$filesystem = new Filesystem;
$filesystem->remove($nativeServeResourcePath);
$filesystem->mkdir($nativeServeResourcePath);
// Removing the bundling directories
$bundlingPath = base_path('build/');
$this->line('Clearing: '.$bundlingPath);
if ($filesystem->exists($bundlingPath)) {
$filesystem->remove($bundlingPath);
}
// Removing the built path
$builtPath = base_path('dist/');
$this->line('Clearing: '.$builtPath);
if ($filesystem->exists($builtPath)) {
$filesystem->remove($builtPath);
}
if ($this->option('with-app-data')) {
foreach ([true, false] as $developmentMode) {
$appName = $this->setAppName($developmentMode);
// Eh, just in case, I don't want to delete all user data by accident.
if (! empty($appName)) {
$appDataPath = $this->appDataDirectory($appName);
$this->line('Clearing: '.$appDataPath);
if ($filesystem->exists($appDataPath)) {
$filesystem->remove($appDataPath);
}
}
}
}
return 0;
}
protected function appDataDirectory(string $name): string
{
/*
* Platform Location
* macOS ~/Library/Application Support
* Linux $XDG_CONFIG_HOME or ~/.config
* Windows %APPDATA%
*/
return match (PHP_OS_FAMILY) {
'Darwin' => $_SERVER['HOME'].'/Library/Application Support/'.$name,
'Linux' => $_SERVER['XDG_CONFIG_HOME'] ?? $_SERVER['HOME'].'/.config/'.$name,
'Windows' => $_SERVER['APPDATA'].'/'.$name,
default => $_SERVER['HOME'].'/.config/'.$name,
};
}
}