Skip to content

Commit

Permalink
Merge pull request #1507 from moonshine-software/fix-command-publisher
Browse files Browse the repository at this point in the history
fix: Publish without sep
  • Loading branch information
lee-to authored Jan 27, 2025
2 parents 58b44a4 + 8b39ae5 commit 0884468
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/Laravel/src/Commands/MoonShineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ public static function addResourceOrPageToProviderFile(string $class, bool $page
class: "$namespace\\$class",
to: app_path('Providers/MoonShineServiceProvider.php'),
between: static fn (Stringable $content): Stringable => $content->betweenFirst("->$method([", ']'),
replace: static fn (Stringable $content, Closure $tab): Stringable => $content->append("{$tab()}$class::class,\n{$tab(3)}"),
replace: static function (Stringable $content, Closure $tab) use ($class): Stringable {
$prefixTab = 1;

if (! $content->rtrim()->endsWith(',')) {
$content = $content->rtrim()->append(",\n");
$prefixTab = 4;
}

return $content->append("{$tab($prefixTab)}$class::class,\n{$tab(3)}");
},
);
}

Expand All @@ -56,7 +65,22 @@ public static function addResourceOrPageToMenu(string $class, string $title, str
class: "$namespace\\$class",
to: $reflector->getFileName(),
between: static fn (Stringable $content): Stringable => $content->betweenFirst("protected function menu(): array", '}'),
replace: static fn (Stringable $content, Closure $tab): Stringable => $content->replace("];", "{$tab()}MenuItem::make('$title', $class::class),\n{$tab(2)}];"),
replace: static function (Stringable $content, Closure $tab) use ($title, $class): Stringable {
if (! $content->rtrim()->squish()->remove(' ')->endsWith('),];')) {
$lines = explode("\n", $content->value());

foreach ($lines as $index => $line) {
$line = rtrim($line);
if ((preg_match('/\)]$/', $line) || preg_match('/\)$/', $line)) && ! str_ends_with($line, ',')) {
$lines[$index] = $line . ',';
}
}

$content = str(implode("\n", $lines));
}

return $content->replace("];", "{$tab()}MenuItem::make('$title', $class::class),\n{$tab(2)}];");
},
use: MenuItem::class
);
}
Expand Down

0 comments on commit 0884468

Please sign in to comment.