Skip to content

Commit

Permalink
feat: ensure pest php is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
bensherred committed Nov 18, 2024
1 parent edeb11b commit 2f1f791
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/Actions/RemoveComposerPackagesAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace RedExplosion\Fabricate\Actions;

use Symfony\Component\Process\Process;

class RemoveComposerPackagesAction
{
/**
* @param array<int, string> $packages
*/
public function handle(array $packages, bool $asDev = false): bool
{
$command = array_merge(
['composer', 'remove'],
$packages,
$asDev ? ['--dev'] : [],
);

return (new Process($command, base_path(), ['COMPOSER_MEMORY_LIMIT' => '-1']))
->setTimeout(null)
->run() === 0;
}
}
1 change: 1 addition & 0 deletions src/Actions/RequireComposerPackagesAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function handle(array $packages, bool $asDev = false): bool
['composer', 'require'],
$packages,
$asDev ? ['--dev'] : [],
['--with-all-dependencies'],
);

return (new Process($command, base_path(), ['COMPOSER_MEMORY_LIMIT' => '-1']))
Expand Down
2 changes: 2 additions & 0 deletions src/Modules/Default/DefaultModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public static function tasks(): array
{
return [
Tasks\UpdateComposerMeta::class,
Tasks\RemoveComposerDependencies::class,
Tasks\InstallComposerDependencies::class,
Tasks\InstallPest::class,
Tasks\InstallYarnDependencies::class,
Tasks\PublishStubs::class,
Tasks\RegisterComposerScripts::class,
Expand Down
4 changes: 3 additions & 1 deletion src/Modules/Default/Tasks/InstallComposerDependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ public function perform(InstallData $data): void
$this->requireComposerPackages->handle([
'laravel/horizon',
'laravel/pulse',
'league/flysystem-aws-s3-v3:^3.0',
// 'league/flysystem-aws-s3-v3:^3.0',
'red-explosion/laravel-sqids',
'spatie/laravel-data',
]);

$this->requireComposerPackages->handle([
'larastan/larastan',
'pestphp/pest',
'pestphp/pest-plugin-laravel',
'rector/rector',
'red-explosion/pint-config',
], asDev: true);
Expand Down
32 changes: 32 additions & 0 deletions src/Modules/Default/Tasks/InstallPest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace RedExplosion\Fabricate\Modules\Default\Tasks;

use Illuminate\Filesystem\Filesystem;
use RedExplosion\Fabricate\Data\InstallData;
use RedExplosion\Fabricate\Task;
use Symfony\Component\Process\Process;

class InstallPest extends Task
{
public function __construct(
protected readonly Filesystem $filesystem,
) {
}

public function progressLabel(): string
{
return 'Installing Pest';
}

public function perform(InstallData $data): void
{
if ($this->filesystem->exists('tests/Pest.php')) {
return;
}

(new Process(['./vendor/bin/pest', '--init']))->run();
}
}
29 changes: 29 additions & 0 deletions src/Modules/Default/Tasks/RemoveComposerDependencies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace RedExplosion\Fabricate\Modules\Default\Tasks;

use RedExplosion\Fabricate\Actions\RemoveComposerPackagesAction;
use RedExplosion\Fabricate\Data\InstallData;
use RedExplosion\Fabricate\Task;

class RemoveComposerDependencies extends Task
{
public function __construct(
protected readonly RemoveComposerPackagesAction $removeComposerPackages,
) {
}

public function progressLabel(): string
{
return 'Removing Composer dependencies';
}

public function perform(InstallData $data): void
{
$this->removeComposerPackages->handle([
'phpunit/phpunit',
], asDev: true);
}
}

0 comments on commit 2f1f791

Please sign in to comment.