Skip to content

Commit 93a0694

Browse files
authored
Merge pull request #45 from RonasIT/update-clerk-auth-config
feat: update project initialization for Clerk with use of laravel-clerk:install
2 parents 3eec1c2 + 2985325 commit 93a0694

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
@@ -506,41 +506,12 @@ protected function enableClerk(): void
506506
array_push(
507507
$this->shellCommands,
508508
'composer require ronasit/laravel-clerk',
509-
'php artisan vendor:publish --provider="RonasIT\\Clerk\\Providers\\ClerkServiceProvider"',
509+
'php artisan laravel-clerk:install',
510510
);
511511

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

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.development'],
176172
'result' => $this->getFixture('env.development.yml'),
@@ -224,10 +220,6 @@ public function testRunWithAdminAndDefaultReadmeCreation()
224220
$this->mockFilePutContent(
225221
'env.example.yml',
226222
'env.development.yml',
227-
[
228-
'config/auth.php',
229-
$this->getFixture('auth-modified.php'),
230-
],
231223
[
232224
'database/migrations/2018_11_11_111111_users_add_clerk_id_field.php',
233225
$this->getFixture('users_add_clerk_id_field_migration.php'),
@@ -265,7 +257,7 @@ public function testRunWithAdminAndDefaultReadmeCreation()
265257
['arguments' => 'php artisan vendor:publish --provider="RonasIT\AutoDoc\AutoDocServiceProvider" --ansi'],
266258
['arguments' => 'composer require --dev ronasit/laravel-entity-generator --ansi'],
267259
['arguments' => 'composer require ronasit/laravel-clerk --ansi'],
268-
['arguments' => 'php artisan vendor:publish --provider="RonasIT\\Clerk\\Providers\\ClerkServiceProvider" --ansi'],
260+
['arguments' => 'php artisan laravel-clerk:install --ansi'],
269261
['arguments' => 'composer require ronasit/laravel-telescope-extension --ansi'],
270262
['arguments' => 'php artisan telescope:install --ansi'],
271263
);

0 commit comments

Comments
 (0)