Skip to content

Commit

Permalink
Updated createViewFiles method.
Browse files Browse the repository at this point in the history
  • Loading branch information
JakyeRU committed Dec 28, 2022
1 parent a283207 commit 93d0262
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/Console/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Validator;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Process\Process;

class InstallCommand extends Command
Expand All @@ -27,6 +28,7 @@ class InstallCommand extends Command
private ?string $clientId;
private ?string $clientSecret;
private ?string $prefix;
private ?bool $darkMode;

/**
* Execute the console command.
Expand All @@ -39,14 +41,15 @@ public function handle()
$this->clientId = $this->ask('What is your Discord application\'s client id?');
$this->clientSecret = $this->ask('What is your Discord application\'s client secret?');
$this->prefix = $this->ask('What route prefix should Larascord use?', 'larascord');
$this->darkMode = $this->confirm('Do you want to install laravel/breeze with dark mode?', true);

// Validating the user's input
try {$this->validateInput();} catch (\Exception $e) {$this->error($e->getMessage()); return;}

// Installing laravel/breeze
$this->info('Installing Larascord...');
$this->requireComposerPackages('laravel/breeze:^1.16', '-q');
if ($this->confirm('Do you want to install laravel/breeze with dark mode?', true)) {
if ($this->darkMode) {
shell_exec('php artisan breeze:install --dark');
} else {
shell_exec('php artisan breeze:install');
Expand Down Expand Up @@ -184,6 +187,14 @@ public function createViewFiles()
{
(new Filesystem())->ensureDirectoryExists(resource_path('views'));
(new Filesystem())->copyDirectory(__DIR__ . '/../../resources/views', resource_path('views'));

if (!$this->darkMode) {
$this->removeDarkClasses((new Finder())
->in(resource_path('views'))
->name('*.blade.php')
->notName('welcome.blade.php')
);
}
}

/**
Expand Down Expand Up @@ -233,4 +244,17 @@ protected function requireComposerPackages($packages)
$this->output->write($output);
});
}

/**
* Remove Tailwind dark classes from the given files.
*
* @param \Symfony\Component\Finder\Finder $finder
* @return void
*/
protected function removeDarkClasses(Finder $finder)
{
foreach ($finder as $file) {
file_put_contents($file->getPathname(), preg_replace('/\sdark:[^\s"\']+/', '', $file->getContents()));
}
}
}

0 comments on commit 93d0262

Please sign in to comment.