From e0379c2d6c78f28e53cfb5b60f7802d16ce22e3d Mon Sep 17 00:00:00 2001 From: Joshua Mitchener <64335706+thejmitchener@users.noreply.github.com> Date: Mon, 11 Nov 2024 17:25:06 -0500 Subject: [PATCH] Added merge strategies, refactor commands (#7) * Added merge strategies for CSS, JS, package.json, composer.json, and package-lock.json files. Modified ConfigureEnvCommand to copy .env.example to .env and generate a new key if .env doesn't exist. Removed unnecessary file existence checks in InstallGitDotFilesCommand, InstallPrettierCommand, InstallTailwindCssCommand, and InstallViteCommand. * Ignore certain files and directories during export, and merge specific file types using ours strategy. --- .gitattributes | 4 +++ src/Commands/ConfigureEnvCommand.php | 13 ++++------ src/Commands/InstallGitDotFilesCommand.php | 7 ----- src/Commands/InstallPrettierCommand.php | 10 -------- src/Commands/InstallTailwindCssCommand.php | 20 --------------- src/Commands/InstallViteCommand.php | 10 -------- stubs/.gitattributes.stub | 30 +++++++++++++++++++--- 7 files changed, 36 insertions(+), 58 deletions(-) diff --git a/.gitattributes b/.gitattributes index 29249db..5280247 100644 --- a/.gitattributes +++ b/.gitattributes @@ -20,5 +20,9 @@ /phpstan-baseline.neon export-ignore # Merge ours +# *.css merge=ours +# *.js merge=ours +# package.json merge=ours # package-lock.json merge=ours +# composer.json merge=ours # composer.lock merge=ours diff --git a/src/Commands/ConfigureEnvCommand.php b/src/Commands/ConfigureEnvCommand.php index bc41bf6..03551ab 100644 --- a/src/Commands/ConfigureEnvCommand.php +++ b/src/Commands/ConfigureEnvCommand.php @@ -14,16 +14,13 @@ class ConfigureEnvCommand extends Command public function handle(): void { - $envPath = base_path('.env'); - - // Check if --force option is passed - if (! $this->option('force')) { - $this->warn('No --force option provided. Use --force to overwrite the .env file.'); - - return; + if (! file_exists(base_path('.env'))) { + shell_exec('cp .env.example .env'); + shell_exec('php artisan key:generate'); } - // Modify the .env file contents + $envPath = base_path('.env'); + $this->modifyEnvFile($envPath); shell_exec('herd secure'); diff --git a/src/Commands/InstallGitDotFilesCommand.php b/src/Commands/InstallGitDotFilesCommand.php index 61c689a..87e3296 100644 --- a/src/Commands/InstallGitDotFilesCommand.php +++ b/src/Commands/InstallGitDotFilesCommand.php @@ -38,13 +38,6 @@ public function handle() $stubsPath = __DIR__.'/../../stubs/'; foreach ($files as $filename => $destinationPath) { - // Check if file exists at the destination - if (File::exists($destinationPath) && ! $this->option('force')) { - $this->info("{$filename} already exists. Use --force to overwrite."); - - continue; - } - // Check if the stub file exists $stubFilePath = $stubsPath.$filename; if (! File::exists($stubFilePath)) { diff --git a/src/Commands/InstallPrettierCommand.php b/src/Commands/InstallPrettierCommand.php index 0b4bf15..f6afe85 100644 --- a/src/Commands/InstallPrettierCommand.php +++ b/src/Commands/InstallPrettierCommand.php @@ -64,16 +64,6 @@ private function publishConfig(string $configFileName, bool $force = false): voi if ($force || $this->option('force')) { \File::copy($stubPath, $destinationPath); $this->info("$configFileName has been installed or overwritten successfully."); - } elseif (\File::exists($destinationPath)) { - if ($this->confirm("$configFileName already exists. Do you want to overwrite it?", false)) { - \File::copy($stubPath, $destinationPath); - $this->info("$configFileName has been overwritten successfully."); - } else { - $this->warn("Skipping $configFileName installation."); - } - } else { - \File::copy($stubPath, $destinationPath); - $this->info("$configFileName has been installed successfully."); } } diff --git a/src/Commands/InstallTailwindCssCommand.php b/src/Commands/InstallTailwindCssCommand.php index d03d738..ea89890 100644 --- a/src/Commands/InstallTailwindCssCommand.php +++ b/src/Commands/InstallTailwindCssCommand.php @@ -53,16 +53,6 @@ protected function publishConfig(string $configFileName, bool $force = false): v if ($force || $this->option('force')) { \File::copy($stubPath, $destinationPath); $this->info("$configFileName has been installed or overwritten successfully."); - } elseif (\File::exists($destinationPath)) { - if ($this->confirm("$configFileName already exists. Do you want to overwrite it?", false)) { - \File::copy($stubPath, $destinationPath); - $this->info("$configFileName has been overwritten successfully."); - } else { - $this->warn("Skipping $configFileName installation."); - } - } else { - \File::copy($stubPath, $destinationPath); - $this->info("$configFileName has been installed successfully."); } } @@ -78,16 +68,6 @@ protected function publishAppCss(bool $force): void if ($force || $this->option('force')) { \File::copy($stubPath, $destinationPath); $this->info('css/app.css file has been installed or overwritten successfully.'); - } elseif (\File::exists($destinationPath)) { - if ($this->confirm('css/app.css already exists. Do you want to overwrite it?', false)) { - \File::copy($stubPath, $destinationPath); - $this->info('css/app.css file has been overwritten successfully.'); - } else { - $this->warn('Skipping css/app.css installation.'); - } - } else { - \File::copy($stubPath, $destinationPath); - $this->info('css/app.css file has been installed successfully.'); } } diff --git a/src/Commands/InstallViteCommand.php b/src/Commands/InstallViteCommand.php index 44fdf19..2df9541 100644 --- a/src/Commands/InstallViteCommand.php +++ b/src/Commands/InstallViteCommand.php @@ -54,16 +54,6 @@ protected function publishConfig(string $configFileName, bool $force = false): v if ($force || $this->option('force')) { \File::copy($stubPath, $destinationPath); $this->info("$configFileName has been installed or overwritten successfully."); - } elseif (\File::exists($destinationPath)) { - if ($this->confirm("$configFileName already exists. Do you want to overwrite it?", false)) { - \File::copy($stubPath, $destinationPath); - $this->info("$configFileName has been overwritten successfully."); - } else { - $this->warn("Skipping $configFileName installation."); - } - } else { - \File::copy($stubPath, $destinationPath); - $this->info("$configFileName has been installed successfully."); } } diff --git a/stubs/.gitattributes.stub b/stubs/.gitattributes.stub index fcb21d3..9259ef8 100644 --- a/stubs/.gitattributes.stub +++ b/stubs/.gitattributes.stub @@ -6,6 +6,30 @@ *.md diff=markdown *.php diff=php -/.github export-ignore -CHANGELOG.md export-ignore -.styleci.yml export-ignore +# Ignore all test and documentation with "export-ignore". +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/phpunit.xml.dist export-ignore +/art export-ignore +/docs export-ignore +/tests export-ignore +/workbench export-ignore +/.editorconfig export-ignore +/.php_cs.dist.php export-ignore +/psalm.xml export-ignore +/psalm.xml.dist export-ignore +/testbench.yaml export-ignore +/UPGRADING.md export-ignore +/phpstan.neon.dist export-ignore +/phpstan-baseline.neon export-ignore +.styleci.yml export-ignore +CHANGELOG.md export-ignore + +# Merge ours +*.css merge=ours +*.js merge=ours +package.json merge=ours +package-lock.json merge=ours +composer.json merge=ours +composer.lock merge=ours