Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions resources/views/clerk_user_repository.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace App\Support\Clerk;

use App\Models\Role;
use App\Models\User;
use Lcobucci\JWT\Token;
use RonasIT\Clerk\Repositories\UserRepository;

class ClerkUserRepository extends UserRepository
{
public function fromToken(Token $token): User
{
$user = parent::fromToken($token);

return User::firstOrCreate([
'clerk_id' => $user->getAuthIdentifier(),
], [
'role_id' => Role::USER,
]);
}
}
35 changes: 26 additions & 9 deletions src/Commands/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ public function handle(): void
}

$this->createOrUpdateConfigFile('.env.development', '=', $data);
$this->createOrUpdateConfigFile($envFile, '=', $data);
$this->createOrUpdateConfigFile('.env.example', '=', $data);

if ($envFile !== '.env.example') {
$this->createOrUpdateConfigFile('.env.example', '=', $data);
if ($envFile === '.env') {
Copy link
Preview

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic change inverts the previous condition from !== '.env.example' to === '.env'. This appears to be a significant behavioral change that could affect which environment files get updated. Ensure this change is intentional and properly tested.

Suggested change
if ($envFile === '.env') {
if ($envFile !== '.env.example') {

Copilot uses AI. Check for mistakes.

$this->createOrUpdateConfigFile($envFile, '=', $data);
}
}

Expand Down Expand Up @@ -219,7 +219,7 @@ public function handle(): void
protected function setAutoDocContactEmail(string $email): void
{
$config = ArrayFile::open(base_path('config/auto-doc.php'));

$config->set('info.contact.email', $email);

$config->write();
Expand All @@ -245,7 +245,7 @@ protected function createAdminUser(string $kebabName): void

$this->publishMigration(
view: view('initializator::add_default_user')->with($this->adminCredentials),
migrationName: 'add_default_user'
migrationName: 'add_default_user',
);
}
}
Expand Down Expand Up @@ -396,15 +396,26 @@ protected function addQuotes($string): string
return (Str::contains($string, ' ')) ? "\"{$string}\"" : $string;
}

protected function publishClass(View $template, string $fileName, string $filePath): void
{
$fileName = "{$fileName}.php";

if (!is_dir($filePath)) {
mkdir($filePath, 0777, true);
}

$data = $template->render();

file_put_contents("{$filePath}/{$fileName}", "<?php\n\n{$data}");
}

protected function publishMigration(View $view, string $migrationName): void
{
$time = Carbon::now()->format('Y_m_d_His');

$migrationName = "{$time}_{$migrationName}.php";

$data = $view->render();
$migrationName = "{$time}_{$migrationName}";

file_put_contents("database/migrations/{$migrationName}", "<?php\n\n{$data}");
$this->publishClass($view, $migrationName, 'database/migrations');
}

protected function createOrUpdateConfigFile(string $fileName, string $separator, array $data): void
Expand Down Expand Up @@ -543,5 +554,11 @@ protected function enableClerk(): void
view: view('initializator::users_add_clerk_id_field'),
migrationName: 'users_add_clerk_id_field',
);

$this->publishClass(
template: view('initializator::clerk_user_repository'),
fileName: 'ClerkUserRepository',
filePath: 'app/Support/Clerk',
);
}
}
8 changes: 8 additions & 0 deletions tests/InitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ public function testRunWithAdminAndDefaultReadmeCreation()
'database/migrations/2018_11_11_111111_users_add_clerk_id_field.php',
$this->getFixture('users_add_clerk_id_field_migration.php'),
],
[
'app/Support/Clerk/ClerkUserRepository.php',
$this->getFixture('clerk_user_repository.php'),
],
[
'.env.development',
$this->getFixture('env.development_clerk_credentials_added.yml'),
Expand Down Expand Up @@ -794,6 +798,10 @@ public function testRunWithClerkMobileApp(): void
'database/migrations/2018_11_11_111111_users_add_clerk_id_field.php',
$this->getFixture('users_add_clerk_id_field_migration.php'),
],
[
'app/Support/Clerk/ClerkUserRepository.php',
$this->getFixture('clerk_user_repository.php'),
],
[
'.env.development',
$this->getFixture('env.development_clerk_credentials_added_mobile_app.yml'),
Expand Down
22 changes: 22 additions & 0 deletions tests/fixtures/InitCommandTest/clerk_user_repository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Support\Clerk;

use App\Models\Role;
use App\Models\User;
use Lcobucci\JWT\Token;
use RonasIT\Clerk\Repositories\UserRepository;

class ClerkUserRepository extends UserRepository
{
public function fromToken(Token $token): User
{
$user = parent::fromToken($token);

return User::firstOrCreate([
'clerk_id' => $user->getAuthIdentifier(),
], [
'role_id' => Role::USER,
]);
}
}