Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenjude committed Feb 25, 2024
1 parent aeaa9da commit 684a4ba
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 109 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ composer require stephenjude/filament-jetstream

Install Jetstream with team, api and email verification.
```php
php artisan filament:jetstream:install --team --api --verification
php artisan filament:jetstream:install --teams --api --verification
```

You can publish the config file with:
Expand Down
83 changes: 42 additions & 41 deletions src/Commands/FilamentJetstreamCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,34 @@

class FilamentJetstreamCommand extends Command
{
public $signature = 'filament:jetstream:install {--dark : Indicate that dark mode support should be installed}
{--teams : Indicates if team support should be installed}
{--api : Indicates if API support should be installed}';
public $signature = 'filament:jetstream:install {--teams : Indicates if team support should be installed}
{--api : Indicates if API support should be installed}
{--verification : Indicates if email verification support should be installed}
{--dark : Indicate that dark mode support should be installed}';

public $description = 'Install the Jetstream component and it\'s filament component';

public function handle(): int
{
$this->callSilently(
sprintf(
'jetstream:install livewire %s %s %s %s',
$this->option('team') ? '--team' : '',
$this->option('api') ? '--api' : '',
$this->option('verification') ? '--verification' : '',
$this->option('dark') ? '--dark' : ''
)
);
$this->callSilently('jetstream:install', [
'stack' => 'livewire',
'--teams' => $this->option('teams'),
'--api' => $this->option('api'),
'--verification' => $this->option('verification'),
'--dark' => $this->option('dark'),
]);

$this->configureUser();

if ($this->option('team')) {
if ($this->option('teams')) {
$this->configureTeam();
}

$this->configureAssets();

$this->comment('All done');
$this->line('');

$this->info('Jetstream scaffolding installed successfully.');

return self::SUCCESS;
}
Expand All @@ -41,9 +42,9 @@ public function configureUser(): void
{
$this->replaceInFile(
search: 'use Laravel\Sanctum\HasApiTokens;',
replace: 'use Filament\Panel;' . PHP_EOL .
'use Filament\Models\Contracts\FilamentUser;' . PHP_EOL .
'use Laravel\Sanctum\HasApiTokens;' . PHP_EOL,
replace: 'use Filament\Panel;'.PHP_EOL.
'use Filament\Models\Contracts\FilamentUser;'.PHP_EOL.
'use Laravel\Sanctum\HasApiTokens;'.PHP_EOL,
path: app_path('Models/User.php'),
);

Expand All @@ -54,9 +55,9 @@ public function configureUser(): void
);

$this->replaceInFile(
search: '}' . PHP_EOL,
replace: 'public function canAccessPanel(Panel $panel): bool' . PHP_EOL . '{' . PHP_EOL .
' return;' . PHP_EOL . '}' . PHP_EOL . '}' . PHP_EOL,
search: '}'.PHP_EOL,
replace: 'public function canAccessPanel(Panel $panel): bool'.PHP_EOL.'{'.PHP_EOL.
' return;'.PHP_EOL.'}'.PHP_EOL.'}'.PHP_EOL,
path: app_path('Models/User.php'),
);

Expand All @@ -73,10 +74,10 @@ public function configureTeam(): void
{
$this->replaceInFile(
search: 'use Laravel\Sanctum\HasApiTokens;',
replace: 'use Illuminate\Support\Collection;' . PHP_EOL .
'use Illuminate\Database\Eloquent\Model;' . PHP_EOL .
'use Filament\Models\Contracts\HasTenants;' . PHP_EOL .
'use Laravel\Sanctum\HasApiTokens;' . PHP_EOL,
replace: 'use Illuminate\Support\Collection;'.PHP_EOL.
'use Illuminate\Database\Eloquent\Model;'.PHP_EOL.
'use Filament\Models\Contracts\HasTenants;'.PHP_EOL.
'use Laravel\Sanctum\HasApiTokens;'.PHP_EOL,
path: app_path('Models/User.php'),
);

Expand All @@ -87,28 +88,28 @@ public function configureTeam(): void
);

$this->replaceInFile(
search: '}' . PHP_EOL . '}' . PHP_EOL,
replace: 'public function canAccessTenant(Model $tenant): bool' . PHP_EOL . '{' . PHP_EOL .
' return $this->belongsToTeam($tenant);' . PHP_EOL . '}' . PHP_EOL . '}' . PHP_EOL,
search: '}'.PHP_EOL.'}'.PHP_EOL,
replace: 'public function canAccessTenant(Model $tenant): bool'.PHP_EOL.'{'.PHP_EOL.
' return $this->belongsToTeam($tenant);'.PHP_EOL.'}'.PHP_EOL.'}'.PHP_EOL,
path: app_path('Models/User.php'),
);

$this->replaceInFile(
search: '}' . PHP_EOL . '}' . PHP_EOL,
replace: 'public function getTenants(Panel $panel): Collection' . PHP_EOL . '{' . PHP_EOL .
' return $this->allTeams();' . PHP_EOL . '}' . PHP_EOL . '}' . PHP_EOL,
search: '}'.PHP_EOL.'}'.PHP_EOL,
replace: 'public function getTenants(Panel $panel): Collection'.PHP_EOL.'{'.PHP_EOL.
' return $this->allTeams();'.PHP_EOL.'}'.PHP_EOL.'}'.PHP_EOL,
path: app_path('Models/User.php'),
);
}

public function configureAssets(): void
{
$this->replaceInFile(
search: 'content: [' . PHP_EOL,
replace: 'content: [' . PHP_EOL .
'./app/Filament/**/*.php' . PHP_EOL .
'./resources/views/filament/**/*.blade.php' . PHP_EOL .
'./vendor/filament/**/*.blade.php' . PHP_EOL,
search: 'content: ['.PHP_EOL,
replace: 'content: ['.PHP_EOL.
'./app/Filament/**/*.php'.PHP_EOL.
'./resources/views/filament/**/*.blade.php'.PHP_EOL.
'./vendor/filament/**/*.blade.php'.PHP_EOL,
path: base_path('Models/User.php'),
);

Expand All @@ -119,16 +120,16 @@ public function configureAssets(): void
);

$this->replaceInFile(
search: '}' . PHP_EOL . '}' . PHP_EOL,
replace: 'public function canAccessTenant(Model $tenant): bool' . PHP_EOL . '{' . PHP_EOL .
' return $this->belongsToTeam($tenant);' . PHP_EOL . '}' . PHP_EOL . '}' . PHP_EOL,
search: '}'.PHP_EOL.'}'.PHP_EOL,
replace: 'public function canAccessTenant(Model $tenant): bool'.PHP_EOL.'{'.PHP_EOL.
' return $this->belongsToTeam($tenant);'.PHP_EOL.'}'.PHP_EOL.'}'.PHP_EOL,
path: app_path('Models/User.php'),
);

$this->replaceInFile(
search: '}' . PHP_EOL . '}' . PHP_EOL,
replace: 'public function getTenants(Panel $panel): Collection' . PHP_EOL . '{' . PHP_EOL .
' return $this->allTeams();' . PHP_EOL . '}' . PHP_EOL . '}' . PHP_EOL,
search: '}'.PHP_EOL.'}'.PHP_EOL,
replace: 'public function getTenants(Panel $panel): Collection'.PHP_EOL.'{'.PHP_EOL.
' return $this->allTeams();'.PHP_EOL.'}'.PHP_EOL.'}'.PHP_EOL,
path: app_path('tailwind.config.js'),
);
}
Expand Down
68 changes: 1 addition & 67 deletions src/FilamentJetstreamServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
namespace FilamentJetstream\FilamentJetstream;

use Filament\Events\Auth\Registered;
use Filament\Support\Assets\Asset;
use Filament\Support\Assets\Css;
use Filament\Support\Assets\Js;
use Filament\Support\Facades\FilamentAsset;
use Filament\Support\Facades\FilamentIcon;
use FilamentJetstream\FilamentJetstream\Commands\FilamentJetstreamCommand;
use FilamentJetstream\FilamentJetstream\Listeners\CreatePersonalTeam;
use FilamentJetstream\FilamentJetstream\Testing\TestsFilamentJetstream;
use Illuminate\Support\Facades\Event;
use Livewire\Features\SupportTesting\Testable;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

Expand All @@ -31,12 +25,7 @@ public function configurePackage(Package $package): void
* More info: https://github.com/spatie/laravel-package-tools
*/
$package->name(static::$name)
->hasCommands($this->getCommands())
->hasInstallCommand(function (InstallCommand $command) {
$command
->publishConfigFile()
->askToStarRepoOnGitHub('stephenjude/filament-jetstream');
});
->hasCommands($this->getCommands());

$configFileName = $package->shortName();

Expand Down Expand Up @@ -64,40 +53,10 @@ public function packageBooted(): void
CreatePersonalTeam::class,
);

// Asset Registration
FilamentAsset::register(
$this->getAssets(),
$this->getAssetPackageName()
);

FilamentAsset::registerScriptData(
$this->getScriptData(),
$this->getAssetPackageName()
);

// Icon Registration
FilamentIcon::register($this->getIcons());

// Testing
Testable::mixin(new TestsFilamentJetstream());
}

protected function getAssetPackageName(): ?string
{
return 'stephenjude/filament-jetstream';
}

/**
* @return array<Asset>
*/
protected function getAssets(): array
{
return [
// AlpineComponent::make('filament-jetstream', __DIR__ . '/../resources/dist/components/filament-jetstream.js'),
Css::make('filament-jetstream-styles', __DIR__ . '/../resources/dist/filament-jetstream.css'),
Js::make('filament-jetstream-scripts', __DIR__ . '/../resources/dist/filament-jetstream.js'),
];
}

/**
* @return array<class-string>
Expand All @@ -109,13 +68,6 @@ protected function getCommands(): array
];
}

/**
* @return array<string>
*/
protected function getIcons(): array
{
return [];
}

/**
* @return array<string>
Expand All @@ -124,22 +76,4 @@ protected function getRoutes(): array
{
return [];
}

/**
* @return array<string, mixed>
*/
protected function getScriptData(): array
{
return [];
}

/**
* @return array<string>
*/
protected function getMigrations(): array
{
return [
'create_filament-jetstream_table',
];
}
}

0 comments on commit 684a4ba

Please sign in to comment.