Skip to content

Commit

Permalink
Merge pull request #74 from danjohnson95/main
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot authored Dec 28, 2023
2 parents d0715a3 + a6c4ae4 commit e94a7ba
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Commands/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function handle()
Process::path(__DIR__.'/../../resources/js/')
->env($this->getEnvironmentVariables())
->forever()
->tty(PHP_OS_FAMILY != 'Windows')
->tty(PHP_OS_FAMILY != 'Windows' && !$this->option('no-interaction'))
->run($buildCommand, function (string $type, string $output) {
echo $output;
});
Expand Down
11 changes: 8 additions & 3 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ class InstallCommand extends Command
public function handle(): void
{
intro('Publishing NativePHP Service Provider...');

$withoutInteraction = $this->option('no-interaction');

$this->callSilent('vendor:publish', ['--tag' => 'nativephp-provider']);
$this->callSilent('vendor:publish', ['--tag' => 'nativephp-config']);

$installer = $this->getInstaller($this->option('installer'));
$installer = $this->getInstaller($this->option('installer'), $withoutInteraction);

Check failure on line 28 in src/Commands/InstallCommand.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Native\Electron\Commands\InstallCommand::getInstaller() invoked with 2 parameters, 1 required.

$this->installNPMDependencies(force: $this->option('force'), installer: $installer, withoutInteraction: $withoutInteraction);

$this->installNPMDependencies(force: $this->option('force'), installer: $installer);
$shouldPromptForServe = ! $withoutInteraction && ! $this->option('force');

if (! $this->option('force') && confirm('Would you like to start the NativePHP development server', false)) {
if ($shouldPromptForServe && confirm('Would you like to start the NativePHP development server', false)) {
$this->call('native:serve', ['--installer' => $installer]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/PublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function handle()
Process::path(__DIR__.'/../../resources/js/')
->env($this->getEnvironmentVariables())
->forever()
->tty(PHP_OS_FAMILY != 'Windows')
->tty(PHP_OS_FAMILY != 'Windows' && !$this->option('no-interaction'))
->run('npm run publish:mac-arm', function (string $type, string $output) {
echo $output;
});
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/ExecuteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait ExecuteCommand
{
use LocatesPhpBinary;

protected function executeCommand(string $command, bool $skip_queue = false, string $type = 'install'): void
protected function executeCommand(string $command, bool $skip_queue = false, string $type = 'install', bool $withoutInteraction = false): void
{
$envs = [
'install' => [
Expand All @@ -29,7 +29,7 @@ protected function executeCommand(string $command, bool $skip_queue = false, str
Process::path(__DIR__.'/../../resources/js/')
->env($envs[$type])
->forever()
->tty(PHP_OS_FAMILY != 'Windows')
->tty(!$withoutInteraction && PHP_OS_FAMILY != 'Windows')
->run($command, function (string $type, string $output) {
if ($this->getOutput()->isVerbose()) {
echo $output;
Expand Down
14 changes: 8 additions & 6 deletions src/Traits/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,28 @@ trait Installer
{
use ExecuteCommand;

protected function installNPMDependencies(bool $force, ?string $installer = 'npm'): void
protected function installNPMDependencies(bool $force, ?string $installer = 'npm', bool $withoutInteraction = false): void
{
if ($force || confirm('Would you like to install the NativePHP NPM dependencies?', true)) {
$shouldPrompt = $force || $withoutInteraction;

if ($shouldPrompt || confirm('Would you like to install the NativePHP NPM dependencies?', true)) {
note('Installing NPM dependencies (This may take a while)...');

if (! $installer) {
$this->installDependencies();
$this->installDependencies(withoutInteraction: $withoutInteraction);
} else {
$this->installDependencies(installer: $installer);
$this->installDependencies(installer: $installer, withoutInteraction: $withoutInteraction);
}
$this->output->newLine();
}
}

protected function installDependencies(?string $installer): void
protected function installDependencies(?string $installer = null, bool $withoutInteraction = false): void
{
[$installer, $command] = $this->getInstallerAndCommand(installer: $installer);

note("Installing NPM dependencies using the {$installer} package manager...");
$this->executeCommand(command: $command);
$this->executeCommand(command: $command, withoutInteraction: $withoutInteraction);
}

protected function getInstallerAndCommand(?string $installer, $type = 'install'): array
Expand Down

0 comments on commit e94a7ba

Please sign in to comment.