Skip to content

Commit

Permalink
Use prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Aug 3, 2023
1 parent b962149 commit 26c741b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
],
"require": {
"php": "^8.1",
"nativephp/php-bin": "*",
"illuminate/contracts": "^10.0",
"laravel/prompts": "^0.1.1",
"nativephp/laravel": "*",
"spatie/laravel-package-tools": "^1.14.0",
"illuminate/contracts": "^10.0"
"nativephp/php-bin": "*",
"spatie/laravel-package-tools": "^1.14.0"
},
"require-dev": {
"laravel/pint": "^1.0",
Expand Down
9 changes: 5 additions & 4 deletions src/Commands/DevelopCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Illuminate\Console\Command;
use Native\Electron\Traits\Developer;
use Native\Electron\Traits\Installer;
use function Laravel\Prompts\intro;
use function Laravel\Prompts\note;

class DevelopCommand extends Command
{
Expand All @@ -14,9 +16,9 @@ class DevelopCommand extends Command

public function handle()
{
$this->info('Starting NativePHP dev server…');
intro('Starting NativePHP dev server…');

$this->info('Fetching latest dependencies…');
note('Fetching latest dependencies…');

if (! $this->option('no-dependencies')) {
$this->installNPMDependencies(
Expand All @@ -26,14 +28,13 @@ public function handle()
);
}

$this->info('Starting NativePHP app');
note('Starting NativePHP app');

if (PHP_OS_FAMILY === 'Darwin') {
$this->patchPlist();
}

$this->runDeveloper(installer: $this->option('installer'), skip_queue: $this->option('no-queue'));

}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Console\Command;
use Native\Electron\Traits\Installer;
use function Laravel\Prompts\confirm;
use function Laravel\Prompts\intro;
use function Laravel\Prompts\outro;

class InstallCommand extends Command
{
Expand All @@ -15,18 +18,18 @@ class InstallCommand extends Command

public function handle(): void
{
$this->comment('Publishing NativePHP Service Provider...');
intro('Publishing NativePHP Service Provider...');
$this->callSilent('vendor:publish', ['--tag' => 'nativephp-provider']);
$this->callSilent('vendor:publish', ['--tag' => 'nativephp-config']);

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

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

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

$this->info('NativePHP scaffolding installed successfully.');
outro('NativePHP scaffolding installed successfully.');
}
}
3 changes: 2 additions & 1 deletion src/Commands/QueueWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Str;
use function Laravel\Prompts\intro;

class QueueWorkerCommand extends Command
{
Expand All @@ -27,7 +28,7 @@ protected function getAppDirectory()

public function handle()
{
$this->info('Starting NativePHP queue worker…');
intro('Starting NativePHP queue worker…');

$phpBinary = __DIR__.'/../../resources/js/resources/php/php';

Expand Down
4 changes: 3 additions & 1 deletion src/Traits/Developer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Native\Electron\Traits;

use function Laravel\Prompts\note;

trait Developer
{
use ExecuteCommand;
Expand All @@ -10,7 +12,7 @@ protected function runDeveloper(string $installer, bool $skip_queue): void
{
[$installer, $command] = $this->getInstallerAndCommand(installer: $installer, type: 'dev');

$this->info("Runing the dev script with {$installer}...");
note("Running the dev script with {$installer}...");
$this->executeCommand(command: $command, type: 'serve', skip_queue: $skip_queue);
}
}
3 changes: 2 additions & 1 deletion src/Traits/ExecuteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Facades\Process;
use Native\Electron\Concerns\LocatesPhpBinary;
use function Laravel\Prompts\note;

trait ExecuteCommand
{
Expand All @@ -24,7 +25,7 @@ protected function executeCommand(string $command, bool $skip_queue = false, str
],
];

$this->info('Fetching latest dependencies…');
note('Fetching latest dependencies…');
Process::path(__DIR__.'/../../resources/js/')
->env($envs[$type])
->forever()
Expand Down
17 changes: 10 additions & 7 deletions src/Traits/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

namespace Native\Electron\Traits;

use function Laravel\Prompts\confirm;
use function Laravel\Prompts\error;
use function Laravel\Prompts\note;
use function Laravel\Prompts\select;

trait Installer
{
use ExecuteCommand;

protected function installNPMDependencies(bool $force, ?string $installer = 'npm'): void
{
if ($force || $this->confirm('Would you like to install the NativePHP NPM dependencies?', true)) {
$this->comment('Installing NPM dependencies (This may take a while)...');
if ($force || confirm('Would you like to install the NativePHP NPM dependencies?', true)) {
note('Installing NPM dependencies (This may take a while)...');

if (! $installer) {
$this->installDependencies();
Expand All @@ -24,7 +29,7 @@ protected function installDependencies(?string $installer): void
{
[$installer, $command] = $this->getInstallerAndCommand(installer: $installer);

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

Expand All @@ -38,13 +43,11 @@ protected function getInstallerAndCommand(?string $installer, $type = 'install')

protected function getInstaller(string $installer)
{
$installers = $this->getCommandArrays();

if (! array_key_exists($installer, $this->getCommandArrays())) {
$this->error("Invalid installer ** {$installer} ** provided.");
error("Invalid installer ** {$installer} ** provided.");
$keys = array_keys($this->getCommandArrays());
$techs = implode(', ', $keys);
$installer = $this->choice('Choose one of the following installers: '.$techs, $keys, 0);
$installer = select('Choose one of the following installers: '.$techs, $keys, 0);
}

return $installer;
Expand Down

0 comments on commit 26c741b

Please sign in to comment.