Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow compiling packages in a CI environment #74

Merged
merged 6 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

$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