Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Feb 23, 2021
1 parent ef2b3f9 commit b78093b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
Empty file modified bin/sail 100644 → 100755
Empty file.
39 changes: 29 additions & 10 deletions src/Console/InstallCommand.php
Expand Up @@ -11,7 +11,7 @@ class InstallCommand extends Command
*
* @var string
*/
protected $signature = 'sail:install';
protected $signature = 'sail:install {--services= : The services that should be included in the installation}';

/**
* The console command description.
Expand All @@ -27,21 +27,37 @@ class InstallCommand extends Command
*/
public function handle()
{
$services = $this->choice('Which services would you like to install?', [
'mysql',
'pgsql',
'redis',
'selenium',
'mailhog',
'meilisearch',
], 0, null, true);
if ($this->option('services')) {
$services = $this->option('services') == 'none' ? [] : explode(',', $this->option('services'));
} elseif ($this->option('no-interaction')) {
$services = ['mysql', 'redis', 'selenium', 'mailhog'];
} else {
$services = $this->gatherServicesWithSymfonyMenu();
}

$this->buildDockerCompose($services);
$this->replaceEnvVariables($services);

$this->info('Sail scaffolding installed successfully.');
}

/**
* Gather the desired Sail services using a Symfony menu.
*
* @return array
*/
protected function gatherServicesWithSymfonyMenu()
{
return $this->choice('Which services would you like to install?', [
'mysql',
'pgsql',
'redis',
'selenium',
'mailhog',
'meilisearch',
], 0, null, true);
}

/**
* Build the Docker Compose file.
*
Expand Down Expand Up @@ -74,10 +90,13 @@ protected function buildDockerCompose(array $services)

$dockerCompose = file_get_contents(__DIR__ . '/../../stubs/docker-compose.stub');

$dockerCompose = str_replace('{{depends}}', $depends, $dockerCompose);
$dockerCompose = str_replace('{{depends}}', empty($depends) ? '' : ' '.$depends, $dockerCompose);
$dockerCompose = str_replace('{{services}}', $stubs, $dockerCompose);
$dockerCompose = str_replace('{{volumes}}', $volumes, $dockerCompose);

// Remove empty lines...
$dockerCompose = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $dockerCompose);

file_put_contents($this->laravel->basePath('docker-compose.yml'), $dockerCompose);
}

Expand Down
2 changes: 1 addition & 1 deletion stubs/docker-compose.stub
Expand Up @@ -17,7 +17,7 @@ services:
- '.:/var/www/html'
networks:
- sail
{{depends}}
{{depends}}
{{services}}
networks:
sail:
Expand Down

0 comments on commit b78093b

Please sign in to comment.