Skip to content

Commit

Permalink
Added merge strategies, refactor commands (#7)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
thejmitchener authored Nov 11, 2024
1 parent 1a8cabe commit e0379c2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 58 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 5 additions & 8 deletions src/Commands/ConfigureEnvCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
7 changes: 0 additions & 7 deletions src/Commands/InstallGitDotFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
10 changes: 0 additions & 10 deletions src/Commands/InstallPrettierCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}

Expand Down
20 changes: 0 additions & 20 deletions src/Commands/InstallTailwindCssCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}

Expand All @@ -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.');
}
}

Expand Down
10 changes: 0 additions & 10 deletions src/Commands/InstallViteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}

Expand Down
30 changes: 27 additions & 3 deletions stubs/.gitattributes.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e0379c2

Please sign in to comment.