Skip to content

Commit

Permalink
Add native:dev script on install
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhamp committed Nov 4, 2024
1 parent 7dbde63 commit bdcf52e
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
use Native\Electron\Traits\Installer;

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;

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}';
protected $signature = 'native:install
{--force : Overwrite existing files by default}
{--installer=npm : The package installer to use: npm, yarn or pnpm}';

protected $description = 'Install all of the NativePHP resources';

Expand All @@ -26,9 +30,15 @@ public function handle(): void
$this->call('vendor:publish', ['--tag' => 'nativephp-provider']);
$this->call('vendor:publish', ['--tag' => 'nativephp-config']);

$this->installComposerScript();

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

Check failure on line 35 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,
withoutInteraction: $withoutInteraction
);

$shouldPromptForServe = ! $withoutInteraction && ! $this->option('force');

Expand All @@ -38,4 +48,28 @@ public function handle(): void

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");

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

View workflow job for this annotation

GitHub Actions / phpstan

Class Native\Electron\Commands\RuntimeException not found.

$composerScripts = $composer->scripts ?? (object) [];

$composerScripts->{'native:dev'} = [
'Composer\\Config::disableProcessTimeout',
'npx concurrently -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!');
}
}

0 comments on commit bdcf52e

Please sign in to comment.