Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim-the-Diamond authored and github-actions[bot] committed Mar 7, 2024
1 parent e82a842 commit 2aa4a23
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions packages/builder/src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,61 +103,61 @@ public function run_migrations(): void

public function register_plugins(): void
{
$providerPath = app_path('Providers/Filament/AdminPanelProvider.php');
$providerPath = app_path('Providers/Filament/AdminPanelProvider.php');

if (File::exists($providerPath)) {
if (File::exists($providerPath)) {

$content = File::get($providerPath);
$content = File::get($providerPath);

$intend = ' ';
$intend = ' ';

$namespace = "\Moox\Builder";
$namespace = "\Moox\Builder";

$pluginsToAdd = multiselect(
label: 'These plugins will be installed:',
options: ['BuilderPlugin'],
default: ['BuilderPlugin'],
);
$pluginsToAdd = multiselect(
label: 'These plugins will be installed:',
options: ['BuilderPlugin'],
default: ['BuilderPlugin'],
);

$function = '::make(),';
$function = '::make(),';

$pattern = '/->plugins\(\[([\s\S]*?)\]\);/';
$newPlugins = '';
$pattern = '/->plugins\(\[([\s\S]*?)\]\);/';
$newPlugins = '';

foreach ($pluginsToAdd as $plugin) {
$searchPlugin = '/'.$plugin.'/';
if (preg_match($searchPlugin, $content)) {
warning("$plugin already registered.");
} else {
$newPlugins .= $intend.$namespace.'\\'.$plugin.$function."\n";
}
foreach ($pluginsToAdd as $plugin) {
$searchPlugin = '/'.$plugin.'/';
if (preg_match($searchPlugin, $content)) {
warning("$plugin already registered.");
} else {
$newPlugins .= $intend.$namespace.'\\'.$plugin.$function."\n";
}
}

if ($newPlugins) {

if (preg_match($pattern, $content)) {
info('Plugins section found. Adding new plugins...');
if ($newPlugins) {

$replacement = "->plugins([$1\n$newPlugins\n ]);";
$newContent = preg_replace($pattern, $replacement, $content);
if (preg_match($pattern, $content)) {
info('Plugins section found. Adding new plugins...');

} else {
info('Plugins section created. Adding new plugins...');
$replacement = "->plugins([$1\n$newPlugins\n ]);";
$newContent = preg_replace($pattern, $replacement, $content);

$pluginsSection = " ->plugins([\n$newPlugins\n ]);";
$placeholderPattern = '/(\->authMiddleware\(\[.*?\]\))\s*\;/s';
$replacement = "$1\n".$pluginsSection;
$newContent = preg_replace($placeholderPattern, $replacement, $content, 1);
}
} else {
info('Plugins section created. Adding new plugins...');

File::put($providerPath, $newContent);
$pluginsSection = " ->plugins([\n$newPlugins\n ]);";
$placeholderPattern = '/(\->authMiddleware\(\[.*?\]\))\s*\;/s';
$replacement = "$1\n".$pluginsSection;
$newContent = preg_replace($placeholderPattern, $replacement, $content, 1);
}

} else {

alert('AdminPanelProvider not found. You need to add the plugins manually.');
File::put($providerPath, $newContent);
}

} else {

alert('AdminPanelProvider not found. You need to add the plugins manually.');
}

}

public function finish(): void
Expand Down

0 comments on commit 2aa4a23

Please sign in to comment.