Skip to content

Commit f0375c3

Browse files
committed
feat: update project initialization for Clerk with use of laravel-clerk:install
Refs: #34
1 parent 7d538d2 commit f0375c3

File tree

2 files changed

+2
-39
lines changed

2 files changed

+2
-39
lines changed

src/Commands/InitCommand.php

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -502,41 +502,12 @@ protected function enableClerk(): void
502502
array_push(
503503
$this->shellCommands,
504504
'composer require ronasit/laravel-clerk',
505-
'php artisan vendor:publish --provider="RonasIT\\Clerk\\Providers\\ClerkServiceProvider"',
505+
'php artisan laravel-clerk:install',
506506
);
507507

508-
$this->updateAuthClerkConfig();
509-
510508
$this->publishMigration(
511509
view: view('initializator::users_add_clerk_id_field'),
512510
migrationName: 'users_add_clerk_id_field',
513511
);
514512
}
515-
516-
// TODO: try to use package after fixing https://github.com/wintercms/laravel-config-writer/issues/6
517-
protected function updateAuthClerkConfig(): void
518-
{
519-
$filePath = 'config/auth.php';
520-
521-
$content = file_get_contents($filePath);
522-
523-
$content = preg_replace_callback(
524-
pattern: "/('guards'\s*=>\s*\[)(.*?)(^\s{4}],)/sm",
525-
callback: $this->addClerkToAuthConfigCallback(),
526-
subject: $content,
527-
);
528-
529-
file_put_contents($filePath, $content);
530-
}
531-
532-
protected function addClerkToAuthConfigCallback(): callable
533-
{
534-
return function (array $matches): string {
535-
$existing = rtrim($matches[2]);
536-
$newLine = "\n";
537-
$clerkGuard = "{$newLine} 'clerk' => [{$newLine} 'driver' => 'clerk_session',{$newLine} 'provider' => 'users',{$newLine} ],";
538-
539-
return $matches[1] . $existing . $clerkGuard . $newLine . " ],";
540-
};
541-
}
542513
}

tests/InitCommandTest.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,6 @@ public function testRunWithAdminAndDefaultReadmeCreation()
167167
'arguments' => ['.env.development'],
168168
'result' => $this->getFixture('env.development.yml'),
169169
],
170-
[
171-
'arguments' => ['config/auth.php'],
172-
'result' => $this->getFixture('auth.php'),
173-
],
174170
[
175171
'arguments' => ['.env.example'],
176172
'result' => $this->getFixture('env.example.yml'),
@@ -220,10 +216,6 @@ public function testRunWithAdminAndDefaultReadmeCreation()
220216
$this->mockFilePutContent(
221217
'env.example.yml',
222218
'env.development.yml',
223-
[
224-
'config/auth.php',
225-
$this->getFixture('auth-modified.php'),
226-
],
227219
[
228220
'database/migrations/2018_11_11_111111_users_add_clerk_id_field.php',
229221
$this->getFixture('users_add_clerk_id_field_migration.php'),
@@ -257,7 +249,7 @@ public function testRunWithAdminAndDefaultReadmeCreation()
257249
['arguments' => 'php artisan vendor:publish --provider="RonasIT\AutoDoc\AutoDocServiceProvider" --ansi'],
258250
['arguments' => 'composer require --dev ronasit/laravel-entity-generator --ansi'],
259251
['arguments' => 'composer require ronasit/laravel-clerk --ansi'],
260-
['arguments' => 'php artisan vendor:publish --provider="RonasIT\\Clerk\\Providers\\ClerkServiceProvider" --ansi'],
252+
['arguments' => 'php artisan laravel-clerk:install --ansi'],
261253
['arguments' => 'composer require ronasit/laravel-telescope-extension --ansi'],
262254
['arguments' => 'php artisan telescope:install --ansi'],
263255
);

0 commit comments

Comments
 (0)