|
| 1 | +<?php |
| 2 | + |
| 3 | +use Filament\Support\Colors\Color; |
| 4 | +use NiftyCo\Skeletor\Skeletor; |
| 5 | + |
| 6 | +return function (Skeletor $skeletor) { |
| 7 | + $skeletor->intro('Welcome to Larament setup! Let\'s get started.'); |
| 8 | + |
| 9 | + $applicationName = $skeletor->text('What is the application name?', 'Laravel', required: true); |
| 10 | + |
| 11 | + $applicationDescription = $skeletor->text('What is the application description?', 'A cool Laravel application'); |
| 12 | + |
| 13 | + $timezone = $skeletor->search( |
| 14 | + 'Which timezone would you like to use?', |
| 15 | + fn (string $query) => collect(timezone_identifiers_list()) |
| 16 | + ->filter(fn (string $timezone) => str_contains(strtolower($timezone), strtolower($query))) |
| 17 | + ->values() |
| 18 | + ->all() |
| 19 | + ); |
| 20 | + |
| 21 | + $adminPanelColor = $skeletor->select('What color would you like to use for the FilamentPHP admin panel?', |
| 22 | + collect(Color::all()) |
| 23 | + ->keys() |
| 24 | + ->map(fn (string $color) => ucfirst($color)) |
| 25 | + ->flatten() |
| 26 | + ->values() |
| 27 | + ->toArray() |
| 28 | + ); |
| 29 | + |
| 30 | + $skeletor->intro('Let\'s setup the default user that will be created.'); |
| 31 | + |
| 32 | + $name = $skeletor->text('What is the demo username?', 'John Doe', required: true); |
| 33 | + |
| 34 | + $email = $skeletor-> text( 'What is the demo email?', '[email protected]', required: true); |
| 35 | + |
| 36 | + $password = $skeletor->password('What is the demo password?', 'password', required: true); |
| 37 | + |
| 38 | + if ($applicationName) { |
| 39 | + $skeletor->pregReplaceInFile('/^APP_NAME=(.*)$/m', 'APP_NAME="'.$applicationName.'"', '.env'); |
| 40 | + } |
| 41 | + |
| 42 | + if ($applicationDescription) { |
| 43 | + $skeletor->pregReplaceInFile( |
| 44 | + '/"description":\s*".*?"/', |
| 45 | + '"description": "'.addslashes($applicationDescription).'"', |
| 46 | + 'composer.json' |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + if ($name) { |
| 51 | + $skeletor->pregReplaceInFile('/^DEFAULT_USER_NAME=(".*?"|[^"\s]*|)$/m', 'DEFAULT_USER_NAME="'.$name.'"', '.env'); |
| 52 | + } |
| 53 | + |
| 54 | + if ($email) { |
| 55 | + $skeletor->pregReplaceInFile('/^DEFAULT_USER_EMAIL=(".*?"|[^"\s]*|)$/m', 'DEFAULT_USER_EMAIL="'.$email.'"', '.env'); |
| 56 | + } |
| 57 | + |
| 58 | + if ($password) { |
| 59 | + $skeletor->pregReplaceInFile('/^DEFAULT_USER_PASSWORD=(".*?"|[^"\s]*|)$/m', 'DEFAULT_USER_PASSWORD="'.$password.'"', '.env'); |
| 60 | + } |
| 61 | + |
| 62 | + if ($timezone) { |
| 63 | + $skeletor->pregReplaceInFile('/^APP_TIMEZONE=(".*?"|[^"\s]*|)$/m', 'APP_TIMEZONE="'.$timezone.'"', '.env'); |
| 64 | + } |
| 65 | + |
| 66 | + if ($adminPanelColor) { |
| 67 | + $skeletor->pregReplaceInFile( |
| 68 | + "/'primary'\s*=>\s*Color::[A-Za-z0-9]+/", |
| 69 | + "'primary' => Color::".$adminPanelColor, |
| 70 | + 'app/Providers/Filament/AdminPanelProvider.php' |
| 71 | + ); |
| 72 | + } |
| 73 | + |
| 74 | + if ($skeletor->exists('README.md')) { |
| 75 | + $skeletor->removeFile('README.md'); |
| 76 | + } |
| 77 | + |
| 78 | + if ($skeletor->exists('resources/images/larament.png')) { |
| 79 | + $skeletor->removeFile('resources/images/larament.png'); |
| 80 | + } |
| 81 | + |
| 82 | + if ($skeletor->exists('resources/images/pest-php.png')) { |
| 83 | + $skeletor->removeFile('resources/images/pest-php.png'); |
| 84 | + } |
| 85 | + |
| 86 | + if ($skeletor->exists('resources/images/user-global-search.jpg')) { |
| 87 | + $skeletor->removeFile('resources/images/user-global-search.jpg'); |
| 88 | + } |
| 89 | + |
| 90 | + if ($skeletor->exists('resources/images/global-search-keybinding.jpg')) { |
| 91 | + $skeletor->removeFile('resources/images/global-search-keybinding.jpg'); |
| 92 | + } |
| 93 | + |
| 94 | + $skeletor->outro('Setup completed! Enjoy your new Laravel and FilamentPHP application.'); |
| 95 | +}; |
0 commit comments