generated from red-explosion/laravel-package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69ef8ef
commit 0053966
Showing
57 changed files
with
1,363 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
parameters: | ||
paths: | ||
- src/ | ||
|
||
level: max | ||
|
||
ignoreErrors: | ||
|
||
excludePaths: | ||
|
||
checkMissingIterableValueType: false | ||
paths: | ||
- src |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RedExplosion\Fabricate\Actions; | ||
|
||
use Illuminate\Filesystem\Filesystem; | ||
|
||
class ReplaceInFileAction | ||
{ | ||
public function __construct( | ||
protected readonly Filesystem $filesystem, | ||
) { | ||
} | ||
|
||
public function handle(string $search, string $replace, string $path): void | ||
{ | ||
$contents = str_replace($search, $replace, $this->filesystem->get($path)); | ||
|
||
$this->filesystem->put($path, $contents); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RedExplosion\Fabricate\Actions; | ||
|
||
use Symfony\Component\Process\Process; | ||
|
||
class RequireComposerPackagesAction | ||
{ | ||
/** | ||
* @param array<int, string> $packages | ||
* @param bool $asDev | ||
* @return bool | ||
*/ | ||
public function handle(array $packages, bool $asDev = false): bool | ||
{ | ||
$command = array_merge( | ||
['composer', 'require'], | ||
$packages, | ||
$asDev ? ['--dev'] : [], | ||
); | ||
|
||
return (new Process($command, base_path(), ['COMPOSER_MEMORY_LIMIT' => '-1'])) | ||
->setTimeout(null) | ||
->run() === 0; // TODO: log the output | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RedExplosion\Fabricate\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use RedExplosion\Fabricate\Data\InstallData; | ||
use RedExplosion\Fabricate\Install; | ||
|
||
class InstallCommand extends Command | ||
{ | ||
protected $signature = 'fabricate:install'; | ||
|
||
protected $description = 'Install the Fabricate scaffolding'; | ||
|
||
public function handle(Install $install): void | ||
{ | ||
$install->process(new InstallData()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RedExplosion\Fabricate\Data; | ||
|
||
class InstallData | ||
{ | ||
public function __construct( | ||
// | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RedExplosion\Fabricate; | ||
|
||
use Illuminate\Pipeline\Pipeline; | ||
use RedExplosion\Fabricate\Data\InstallData; | ||
|
||
class Install extends Pipeline | ||
{ | ||
public function process(InstallData $data): InstallData | ||
{ | ||
return $this->send($data) | ||
->through([ | ||
Pipes\InstallComposerDependencies::class, | ||
Pipes\InstallYarnDependencies::class, | ||
Pipes\PublishStubs::class, | ||
Pipes\RegisterComposerScripts::class, | ||
Pipes\RunRefactorScript::class, | ||
Pipes\RunLintScript::class, | ||
Pipes\RegisterHelpersFile::class, | ||
Pipes\FixLarastanErrors::class, | ||
Pipes\ConfigureTestingDatabase::class, | ||
Pipes\RemoveDefaultController::class, | ||
Pipes\RemoveMigrationComments::class, | ||
Pipes\RemoveDownMigrations::class, | ||
Pipes\ConfigureEloquentModels::class, | ||
Pipes\RunRefactorScript::class, | ||
Pipes\RunLintScript::class, | ||
]) | ||
->thenReturn(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RedExplosion\Fabricate\Pipes; | ||
|
||
use Closure; | ||
use RedExplosion\Fabricate\Actions\ReplaceInFileAction; | ||
use RedExplosion\Fabricate\Data\InstallData; | ||
|
||
class ConfigureEloquentModels | ||
{ | ||
public function __construct( | ||
protected readonly ReplaceInFileAction $replaceInFile, | ||
) { | ||
} | ||
|
||
public function handle(InstallData $data, Closure $next) | ||
{ | ||
// todo: remove fillable from user model | ||
|
||
$this->replaceInFile->handle( | ||
<<<EOT | ||
use Illuminate\Support\ServiceProvider; | ||
EOT, | ||
<<<EOT | ||
use App\Models\User; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\Relation; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\ServiceProvider; | ||
EOT, | ||
base_path('app/Providers/AppServiceProvider.php'), | ||
); | ||
|
||
$this->replaceInFile->handle( | ||
<<<EOT | ||
public function boot(): void | ||
{ | ||
} | ||
EOT, | ||
<<<EOT | ||
public function boot(): void | ||
{ | ||
Model::unguard(); | ||
Model::preventLazyLoading(! \$this->app->isProduction()); | ||
Model::preventSilentlyDiscardingAttributes(); | ||
Model::preventAccessingMissingAttributes(); | ||
if (\$this->app->isProduction()) { | ||
Model::handleLazyLoadingViolationUsing(function (Model \$model, string \$relation): void { | ||
\$class = \$model::class; | ||
Log::warning("Attempted to lazy load [{\$relation}] on model [{\$class}]."); | ||
}); | ||
} | ||
Relation::enforceMorphMap([ | ||
'user' => User::class, | ||
]); | ||
} | ||
EOT, | ||
base_path('app/Providers/AppServiceProvider.php'), | ||
); | ||
|
||
return $next($data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RedExplosion\Fabricate\Pipes; | ||
|
||
use Closure; | ||
use Illuminate\Filesystem\Filesystem; | ||
use RedExplosion\Fabricate\Actions\ReplaceInFileAction; | ||
use RedExplosion\Fabricate\Data\InstallData; | ||
|
||
class ConfigureTestingDatabase | ||
{ | ||
public function __construct( | ||
protected readonly Filesystem $filesystem, | ||
protected readonly ReplaceInFileAction $replaceInFile, | ||
) { | ||
} | ||
|
||
public function handle(InstallData $data, Closure $next) | ||
{ | ||
$this->filesystem->move( | ||
base_path('phpunit.xml'), | ||
base_path('phpunit.xml.dist'), | ||
); | ||
|
||
$this->replaceInFile->handle( | ||
<<<EOT | ||
<!-- <env name="DB_CONNECTION" value="sqlite"/> --> | ||
<!-- <env name="DB_DATABASE" value=":memory:"/> --> | ||
EOT, | ||
<<<EOT | ||
<env name="DB_DATABASE" value="testing"/> | ||
EOT, | ||
base_path('phpunit.xml.dist'), | ||
); | ||
|
||
return $next($data); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RedExplosion\Fabricate\Pipes; | ||
|
||
use Closure; | ||
use Illuminate\Filesystem\Filesystem; | ||
use RedExplosion\Fabricate\Actions\ReplaceInFileAction; | ||
use RedExplosion\Fabricate\Data\InstallData; | ||
|
||
class FixLarastanErrors | ||
{ | ||
public function __construct( | ||
protected readonly ReplaceInFileAction $replaceInFile, | ||
) { | ||
} | ||
|
||
public function handle(InstallData $data, Closure $next) | ||
{ | ||
$this->replaceInFile->handle( | ||
'use Illuminate\Database\Eloquent\Factories\HasFactory;', | ||
<<<EOT | ||
use Database\Factories\UserFactory; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
EOT, | ||
app_path('Models/User.php'), | ||
); | ||
|
||
$this->replaceInFile->handle( | ||
'use HasFactory;', | ||
<<<EOT | ||
/** @use HasFactory<UserFactory> */ | ||
use HasFactory; | ||
EOT, | ||
app_path('Models/User.php'), | ||
); | ||
|
||
return $next($data); | ||
} | ||
} |
Oops, something went wrong.