-
-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathInstallCommand.php
More file actions
89 lines (66 loc) · 2.76 KB
/
InstallCommand.php
File metadata and controls
89 lines (66 loc) · 2.76 KB
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
84
85
86
87
88
89
<?php
namespace Native\Electron\Commands;
use Illuminate\Console\Command;
use Native\Electron\Traits\Installer;
use RuntimeException;
use Symfony\Component\Console\Attribute\AsCommand;
use function Laravel\Prompts\confirm;
use function Laravel\Prompts\info;
use function Laravel\Prompts\intro;
use function Laravel\Prompts\note;
use function Laravel\Prompts\outro;
#[AsCommand(
name: 'native:install',
description: 'Install all of the NativePHP resources',
)]
class InstallCommand extends Command
{
use Installer;
protected $signature = 'native:install
{--force : Overwrite existing files by default}
{--installer=npm : The package installer to use: npm, yarn or pnpm}';
public function handle(): void
{
intro('Publishing NativePHP Service Provider...');
$withoutInteraction = $this->option('no-interaction');
$this->call('vendor:publish', ['--tag' => 'nativephp-provider']);
$this->call('vendor:publish', ['--tag' => 'nativephp-config']);
$this->installComposerScript();
$installer = $this->getInstaller($this->option('installer'));
$this->installNPMDependencies(
force: $this->option('force'),
installer: $installer,
withoutInteraction: $withoutInteraction
);
$shouldPromptForServe = ! $withoutInteraction && ! $this->option('force');
if ($shouldPromptForServe && confirm('Would you like to start the NativePHP development server', false)) {
$this->call('native:serve', [
'--installer' => $installer,
'--no-dependencies',
'--no-interaction' => $withoutInteraction,
]);
}
outro('NativePHP scaffolding installed successfully.');
}
private function installComposerScript()
{
info('Installing `composer native:dev` script alias...');
$composer = json_decode(file_get_contents(base_path('composer.json')));
throw_unless($composer, RuntimeException::class, "composer.json couldn't be parsed");
$composerScripts = $composer->scripts ?? (object) [];
if ($composerScripts->{'native:dev'} ?? false) {
note('native:dev script already installed... skipping.');
return;
}
$composerScripts->{'native:dev'} = [
'Composer\\Config::disableProcessTimeout',
'npx concurrently -k -c "#93c5fd,#c4b5fd" "php artisan native:serve --no-interaction" "npm run dev" --names=app,vite',
];
data_set($composer, 'scripts', $composerScripts);
file_put_contents(
base_path('composer.json'),
json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).PHP_EOL
);
note('native:dev script installed!');
}
}