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

[5.x] Add install:collaboration command #9760

Merged
merged 59 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
e231329
Install Laravel Prompts
duncanmcclean Mar 11, 2024
7f64276
Enhance `starter-kits:install` command with Prompts
duncanmcclean Mar 11, 2024
ed49494
Enhance `addons:discover` command
duncanmcclean Mar 11, 2024
17f7544
Enhance `assets:generate-presets` command
duncanmcclean Mar 11, 2024
bf3ad6d
Enhance `assets:meta` command
duncanmcclean Mar 11, 2024
2dd5938
Enhance `eloquent:import-groups` and `eloquent:import-roles` commands
duncanmcclean Mar 11, 2024
be0c0bd
Enhance `eloquent:import-users`
duncanmcclean Mar 11, 2024
83d0f27
Enhance `install:ssg` command
duncanmcclean Mar 11, 2024
b01b77d
Enhance `make:user` command
duncanmcclean Mar 11, 2024
d03b40a
Enhance `multisite` command
duncanmcclean Mar 12, 2024
0d6ea06
Enhance `site:clear` command
duncanmcclean Mar 12, 2024
9f15968
Revert "Enhance `addons:discover` command"
duncanmcclean Mar 12, 2024
eeac710
Starter Kit Installer: Use confirm prompt for super user question
duncanmcclean Mar 14, 2024
9ad06f3
Finish enhancing the `starter-kit:install` command
duncanmcclean Mar 14, 2024
55c744b
improve make:user info message
duncanmcclean Mar 14, 2024
b769f64
skip tests for now until i figure out what to do with them
duncanmcclean Mar 14, 2024
8238ac6
Enhance `addons:discover`
duncanmcclean Mar 14, 2024
d0ed1a3
Don't show progress bar when there's no assets to generate presets for
duncanmcclean Mar 14, 2024
e289e09
assets:meta show warning when site has no assets
duncanmcclean Mar 14, 2024
e6329c2
Enhance `auth:migration` command
duncanmcclean Mar 14, 2024
c5a5b7c
wip
duncanmcclean Mar 14, 2024
9870008
Enhance `make:addon`
duncanmcclean Mar 14, 2024
82e73de
Remove duplicate info
duncanmcclean Mar 14, 2024
511b093
Console validation errors should display nicer
duncanmcclean Mar 14, 2024
979a976
wip
duncanmcclean Mar 14, 2024
7d631f8
Enhance some more things
duncanmcclean Mar 14, 2024
b25a2b8
Fix styling
duncanmcclean Mar 14, 2024
e8b6d1d
wip
duncanmcclean Mar 14, 2024
85711a6
Merge branch 'laravel-prompts' of github.com:statamic/cms into larave…
duncanmcclean Mar 14, 2024
d09bf97
Fix styling
duncanmcclean Mar 14, 2024
2541170
skip make:addon tests for now
duncanmcclean Mar 14, 2024
e9f6f1c
Merge branch 'laravel-prompts' of github.com:statamic/cms into larave…
duncanmcclean Mar 14, 2024
c741bbe
Merge remote-tracking branch 'origin/master' into laravel-prompts
duncanmcclean Mar 14, 2024
9d354a7
does this fix the tests? (wish they were broken locally too)
duncanmcclean Mar 14, 2024
74151b0
don't skip these tests
duncanmcclean Mar 14, 2024
ed87480
turns out prompts works fine with tests, i just needed to tweak some …
duncanmcclean Mar 14, 2024
c17481b
Fix styling
duncanmcclean Mar 14, 2024
c367259
fix more expectations
duncanmcclean Mar 14, 2024
07f7159
Merge branch 'laravel-prompts' of github.com:statamic/cms into larave…
duncanmcclean Mar 14, 2024
3216fd8
these shouldn't be commented out
duncanmcclean Mar 14, 2024
f16211f
Refactor error handling in make:addon command
duncanmcclean Mar 15, 2024
1fd4b00
Fix prompts interactivity in tests
duncanmcclean Mar 15, 2024
5342049
Fix styling
duncanmcclean Mar 15, 2024
e528507
Update Laravel Echo
duncanmcclean Mar 19, 2024
e669386
Generate the Echo config in PHP
duncanmcclean Mar 19, 2024
94e5c91
Merge branch 'laravel-reverb-support' into install-collaboration-command
duncanmcclean Mar 19, 2024
5f9c109
Merge remote-tracking branch 'origin/laravel-prompts' into install-co…
duncanmcclean Mar 19, 2024
97a90fe
Add `install:collaboration` command
duncanmcclean Mar 19, 2024
e6e3e2e
Revert "Merge remote-tracking branch 'origin/laravel-prompts' into in…
duncanmcclean Mar 19, 2024
bae1cd0
Revert "Merge branch 'laravel-reverb-support' into install-collaborat…
duncanmcclean Mar 19, 2024
97cf512
adjust version constraints so PR can be reviewed independently
duncanmcclean Mar 19, 2024
829f7aa
Fix styling
duncanmcclean Mar 19, 2024
92c1180
Avoid re-enabling broadcasting if it's already enabled
duncanmcclean Mar 19, 2024
1e49f27
It's Pusher here, not Reverb.
duncanmcclean Mar 25, 2024
bfc0593
Merge remote-tracking branch 'origin/master' into install-collaborati…
duncanmcclean Apr 2, 2024
d3ce972
Merge remote-tracking branch 'origin/master' into install-collaborati…
duncanmcclean Apr 11, 2024
852dab6
Merge branch 'master' into install-collaboration-command
jasonvarga Apr 15, 2024
e76d887
Prevent running composer scripts when requiring `statamic/collaboration`
duncanmcclean Apr 15, 2024
a304199
dont commit the dev branch
jasonvarga Apr 15, 2024
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
204 changes: 204 additions & 0 deletions src/Console/Commands/InstallCollaboration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
<?php

namespace Statamic\Console\Commands;

use Facades\Statamic\Console\Processes\Composer;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Str;
use Statamic\Console\EnhancesCommands;
use Statamic\Console\RunsInPlease;
use Symfony\Component\Process\PhpExecutableFinder;

use function Laravel\Prompts\select;
use function Laravel\Prompts\spin;

class InstallCollaboration extends Command
{
use EnhancesCommands, RunsInPlease;

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'statamic:install:collaboration';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Installs the Statamic Collaboration addon and enables broadcasting in Laravel.';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if (! Composer::isInstalled('statamic/collaboration')) {
spin(
fn () => Composer::withoutQueue()->throwOnFailure()->require('statamic/collaboration'),
duncanmcclean marked this conversation as resolved.
Show resolved Hide resolved
'Installing the statamic/collaboration addon...'
);

$this->components->info('Installed statamic/collaboration addon');
}

$this->enableBroadcasting();
$this->installBroadcastingDriver();
}

protected function enableBroadcasting(): void
{
if (in_array(\Illuminate\Broadcasting\BroadcastServiceProvider::class, array_keys(app()->getLoadedProviders()))) {
$this->components->warn('Broadcasting is already enabled.');

return;
}

if (version_compare(app()->version(), '11', '<')) {
$this->enableBroadcastServiceProvider();
$this->components->info('Broadcasting enabled successfully.');

return;
}

spin(
callback: function () {
Process::run([
(new PhpExecutableFinder())->find(false) ?: 'php',
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
'install:broadcasting',
'--without-reverb',
'--without-node',
]);
},
message: 'Enabling broadcasting...'
);

$this->components->info('Broadcasting enabled successfully.');
}

protected function installBroadcastingDriver(): void
{
$driver = select(
label: 'Which broadcasting driver would you like to use?',
options: ['Laravel Reverb', 'Pusher', 'Other'],
);

if ($driver === 'Laravel Reverb') {
spin(
callback: function () {
Composer::withoutQueue()->throwOnFailure()->require('laravel/reverb', '@beta');

Process::run([
(new PhpExecutableFinder())->find(false) ?: 'php',
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
'reverb:install',
]);
},
message: 'Installing Laravel Reverb...'
);

$this->components->info('Laravel Reverb installed successfully.');
}

if ($driver === 'Pusher') {
spin(
callback: function () {
Composer::withoutQueue()->throwOnFailure()->require('pusher/pusher-php-server');

$this->addPusherEnvironmentVariables();
$this->updateBroadcastingDriver('pusher');
},
message: 'Installing Pusher...'
);

$this->components->info("Pusher installed successfully. Don't forget to add your Pusher credentials to your .env file.");
}

if ($driver === 'Other') {
$this->components->warn("You'll need to install and configure your own broadcasting driver.");
}
}

/**
* Uncomment the "BroadcastServiceProvider" in the application configuration.
* Copied from Laravel's BroadcastingInstallCommand to support Laravel 10 applications.
*
* @return void
*/
protected function enableBroadcastServiceProvider()
{
$config = ($filesystem = new Filesystem)->get(app()->configPath('app.php'));

if (str_contains($config, '// App\Providers\BroadcastServiceProvider::class')) {
$filesystem->replaceInFile(
'// App\Providers\BroadcastServiceProvider::class',
'App\Providers\BroadcastServiceProvider::class',
app()->configPath('app.php'),
);
}
}

protected function updateBroadcastingDriver(string $driver): void
{
if (File::missing($env = app()->environmentFile())) {
return;
}

File::put(
$env,
Str::of(File::get($env))->replaceMatches('/(BROADCAST_(?:DRIVER|CONNECTION))=\w*/', function (array $matches) use ($driver) {
return $matches[1].'='.$driver;
})
);
}

/**
* Add the Pusher variables to the environment file.
*/
protected function addPusherEnvironmentVariables(): void
{
if (File::missing($env = app()->environmentFile())) {
return;
}

$contents = File::get($env);

$variables = Arr::where([
'PUSHER_APP_ID' => 'PUSHER_APP_ID=',
'PUSHER_APP_KEY' => 'PUSHER_APP_KEY=',
'PUSHER_APP_SECRET' => 'PUSHER_APP_SECRET=',
'PUSHER_HOST' => 'PUSHER_HOST=',
'PUSHER_PORT' => 'PUSHER_PORT=443',
'PUSHER_SCHEME' => 'PUSHER_SCHEME=https',
'PUSHER_APP_CLUSTER' => 'PUSHER_APP_CLUSTER=mt1',
'PUSHER_NEW_LINE' => null,
'VITE_PUSHER_APP_KEY' => 'VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"',
'VITE_PUSHER_HOST' => 'VITE_PUSHER_HOST="${PUSHER_HOST}"',
'VITE_PUSHER_PORT' => 'VITE_PUSHER_PORT="${PUSHER_PORT}"',
'VITE_PUSHER_SCHEME' => 'VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"',
'VITE_PUSHER_APP_CLUSTER' => 'VITE_REVERB_APP_CLUSTER="${PUSHER_APP_CLUSTER}"',
], function ($value, $key) use ($contents) {
return ! Str::contains($contents, PHP_EOL.$key);
});

$variables = trim(implode(PHP_EOL, $variables));

if ($variables === '') {
return;
}

File::append(
$env,
Str::endsWith($contents, PHP_EOL) ? PHP_EOL.$variables.PHP_EOL : PHP_EOL.PHP_EOL.$variables.PHP_EOL,
);
}
}
1 change: 1 addition & 0 deletions src/Providers/ConsoleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ConsoleServiceProvider extends ServiceProvider
Commands\AssetsMeta::class,
Commands\GlideClear::class,
Commands\Install::class,
Commands\InstallCollaboration::class,
Commands\InstallEloquentDriver::class,
Commands\InstallSsg::class,
Commands\FlatCamp::class,
Expand Down
Loading