Skip to content

Commit 653ac0f

Browse files
authored
Merge 74da97c into c13f3dc
2 parents c13f3dc + 74da97c commit 653ac0f

File tree

6 files changed

+229
-160
lines changed

6 files changed

+229
-160
lines changed

src/Commands/InitCommand.php

Lines changed: 55 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,10 @@ class InitCommand extends Command implements Isolatable
2222

2323
protected $description = 'Initialize required project parameters to run DEV environment';
2424

25-
public const array RESOURCES_ITEMS = [
26-
'issue_tracker' => 'Issue Tracker',
27-
'figma' => 'Figma',
28-
'sentry' => 'Sentry',
29-
'datadog' => 'DataDog',
30-
'argocd' => 'ArgoCD',
31-
'telescope' => 'Laravel Telescope',
32-
'nova' => 'Laravel Nova',
33-
];
34-
35-
public const array CONTACTS_ITEMS = [
36-
'manager' => 'Manager',
37-
];
38-
39-
public const array CREDENTIALS_ITEMS = [
40-
'telescope' => 'Laravel Telescope',
41-
'nova' => 'Laravel Nova',
42-
];
43-
44-
public const array DEFAULT_URLS = [
45-
'telescope',
46-
'nova',
47-
];
48-
49-
protected array $resources = [];
50-
5125
protected array $adminCredentials = [];
5226

27+
protected array $readmeParts = [];
28+
5329
protected array $emptyValuesList = [];
5430

5531
protected array $shellCommands = [
@@ -130,19 +106,17 @@ public function handle(): void
130106
}
131107

132108
if ($shouldGenerateReadme = $this->confirm('Do you want to generate a README file?', true)) {
133-
$this->generateReadme();
109+
$this->configureReadmeParts();
134110
}
135111

136112
if ($this->confirm('Would you use Renovate dependabot?', true)) {
137113
$this->saveRenovateJSON();
138114

139-
if ($shouldGenerateReadme) {
140-
$this->readmeGenerator->fillRenovate();
141-
}
115+
$this->readmeParts[] = 'fillRenovate';
142116
}
143117

144118
if ($shouldGenerateReadme) {
145-
$this->readmeGenerator->save();
119+
$this->readmeGenerator->generate($this->readmeParts);
146120

147121
$this->info('README generated successfully!');
148122

@@ -364,136 +338,104 @@ protected function publishClass(View $template, string $fileName, string $filePa
364338
file_put_contents("{$filePath}/{$fileName}", "<?php\n\n{$data}");
365339
}
366340

367-
protected function generateReadme(): void
341+
protected function configureReadmeParts(): void
368342
{
369-
$this->readmeGenerator->generate($this->appName, $this->appType->value, $this->appUrl);
343+
$this->readmeGenerator->appInfo = [
344+
'name' => $this->appName,
345+
'type' => $this->appType->value,
346+
'url' => $this->appUrl,
347+
'code_owner_email' => $this->codeOwnerEmail,
348+
];
370349

371350
if ($this->confirm('Do you need a `Resources & Contacts` part?', true)) {
372-
$this->readmeGenerator->fillResourcesAndContacts();
373-
$this->fillResources();
374-
$this->fillContacts();
351+
$this->configureResources();
352+
$this->configureContacts();
353+
354+
$this->readmeParts[] = 'fillResourcesAndContacts';
355+
$this->readmeParts[] = 'fillResources';
356+
$this->readmeParts[] = 'fillContacts';
375357
}
376358

377359
if ($this->confirm('Do you need a `Prerequisites` part?', true)) {
378-
$this->readmeGenerator->fillPrerequisites();
360+
$this->readmeParts[] = 'fillPrerequisites';
379361
}
380362

381363
if ($this->confirm('Do you need a `Getting Started` part?', true)) {
382-
$this->fillGettingStarted();
364+
$this->readmeParts[] = 'fillGettingStarted';
383365
}
384366

385367
if ($this->confirm('Do you need an `Environments` part?', true)) {
386-
$this->readmeGenerator->fillEnvironments();
368+
$this->readmeParts[] = 'fillEnvironments';
387369
}
388370

389371
if ($this->confirm('Do you need a `Credentials and Access` part?', true)) {
390-
$this->fillCredentialsAndAccess();
372+
$this->configureCredentialsAndAccess();
373+
374+
$this->readmeParts[] = 'fillCredentialsAndAccess';
391375

392376
if ($this->authType === AuthTypeEnum::Clerk) {
393-
$this->readmeGenerator->fillClerkAuth();
377+
$this->readmeParts[] = 'fillClerkAuthType';
394378
}
395379
}
396380
}
397381

398-
protected function fillResources(): void
382+
protected function configureResources(): void
399383
{
400-
$filePart = $this->readmeGenerator->loadReadmePart('RESOURCES.md');
401-
$laterText = '(will be added later)';
402-
403-
foreach (self::RESOURCES_ITEMS as $key => $title) {
404-
$defaultAnswer = (in_array($key, self::DEFAULT_URLS)) ? $this->appUrl . "/{$key}" : 'later';
405-
$text = "Are you going to use {$title}? "
406-
. "Please enter a link or select `later` to do it later, otherwise select `no`.";
407-
408-
$link = $this->anticipate(
409-
$text,
410-
['later', 'no'],
411-
$defaultAnswer
412-
);
384+
foreach ($this->readmeGenerator->resourcesItems as $key => $resource) {
385+
$defaultAnswer = (Arr::has($resource, 'default_url')) ? $this->appUrl . "/{$key}" : 'later';
386+
$text = "Are you going to use {$resource['title']}? "
387+
. 'Please enter a link or select `later` to do it later, otherwise select `no`.';
388+
389+
$link = $this->anticipate($text, ['later', 'no'], $defaultAnswer);
413390

414391
if ($link === 'later') {
415-
$this->emptyValuesList[] = "{$title} link";
416-
$this->readmeGenerator->setReadmeValue($filePart, "{$key}_link");
417-
$this->readmeGenerator->setReadmeValue($filePart, "{$key}_later", $laterText);
418-
} elseif ($link !== 'no') {
419-
$this->readmeGenerator->setReadmeValue($filePart, "{$key}_link", $link);
420-
$this->readmeGenerator->setReadmeValue($filePart, "{$key}_later");
392+
$this->emptyValuesList[] = "{$resource['title']} link";
421393
}
422394

423-
$this->resources[$key] = ($link !== 'no');
424-
425-
$this->readmeGenerator->removeTag($filePart, $key, $link === 'no');
395+
$this->readmeGenerator->resourcesItems[$key]['link'] = $link;
396+
$this->readmeGenerator->resourcesItems[$key]['active'] = ($link !== 'no');
426397
}
427-
428-
$this->readmeGenerator->setReadmeValue($filePart, 'api_link', $this->appUrl);
429-
$this->readmeGenerator->updateReadmeFile($filePart);
430398
}
431399

432-
protected function fillContacts(): void
400+
protected function configureContacts(): void
433401
{
434-
$filePart = $this->readmeGenerator->loadReadmePart('CONTACTS.md');
435-
436-
foreach (self::CONTACTS_ITEMS as $key => $title) {
437-
if ($link = $this->ask("Please enter a {$title}'s email", '')) {
438-
$this->readmeGenerator->setReadmeValue($filePart, "{$key}_link", $link);
402+
foreach ($this->readmeGenerator->contactsItems as $key => $value) {
403+
if ($link = $this->ask("Please enter a {$value['title']}'s email", '')) {
404+
$this->readmeGenerator->contactsItems[$key]['email'] = $link;
439405
} else {
440-
$this->emptyValuesList[] = "{$title}'s email";
406+
$this->emptyValuesList[] = "{$value['title']}'s email";
441407
}
442-
443-
$this->readmeGenerator->removeTag($filePart, $key);
444408
}
445-
446-
$this->readmeGenerator->setReadmeValue($filePart, 'team_lead_link', $this->codeOwnerEmail);
447-
448-
$this->readmeGenerator->updateReadmeFile($filePart);
449-
}
450-
451-
protected function fillGettingStarted(): void
452-
{
453-
$gitProjectPath = trim((string) shell_exec('git ls-remote --get-url origin'));
454-
$projectDirectory = basename($gitProjectPath, '.git');
455-
$filePart = $this->readmeGenerator->loadReadmePart('GETTING_STARTED.md');
456-
457-
$this->readmeGenerator->setReadmeValue($filePart, 'git_project_path', $gitProjectPath);
458-
$this->readmeGenerator->setReadmeValue($filePart, 'project_directory', $projectDirectory);
459-
460-
$this->readmeGenerator->updateReadmeFile($filePart);
461409
}
462410

463-
protected function fillCredentialsAndAccess(): void
411+
protected function configureCredentialsAndAccess(): void
464412
{
465-
$filePart = $this->readmeGenerator->loadReadmePart('CREDENTIALS_AND_ACCESS.md');
466-
467-
if (!empty($this->adminCredentials)) {
468-
$this->readmeGenerator->setReadmeValue($filePart, 'admin_email', $this->adminCredentials['email']);
469-
$this->readmeGenerator->setReadmeValue($filePart, 'admin_password', $this->adminCredentials['password']);
470-
}
471-
472-
$this->readmeGenerator->removeTag($filePart, 'admin_credentials', !$this->adminCredentials);
473-
474-
foreach (self::CREDENTIALS_ITEMS as $key => $title) {
475-
if (!Arr::get($this->resources, $key)) {
476-
$this->readmeGenerator->removeTag($filePart, "{$key}_credentials", true);
477-
413+
foreach ($this->readmeGenerator->credentialsItems as $key => &$item) {
414+
if (!Arr::get($this->readmeGenerator->resourcesItems, "{$key}.active")) {
478415
continue;
479416
}
480417

481-
if (!empty($this->adminCredentials) && $this->confirm("Is {$title}'s admin the same as default one?", true)) {
418+
if (!empty($this->adminCredentials) && $this->confirm("Is {$item['title']}'s admin the same as default one?", true)) {
482419
$adminCredentials = $this->adminCredentials;
483420
} else {
484421
if ($this->authType === AuthTypeEnum::Clerk && !$this->isMigrationExists('admins_create_table')) {
485422
$this->publishAdminsTableMigration();
486423
}
487424

488-
$adminCredentials = $this->createAdminUser($key, $title);
425+
$adminCredentials = $this->createAdminUser($key, $item['title']);
489426
}
490427

491-
$this->readmeGenerator->setReadmeValue($filePart, "{$key}_email", $adminCredentials['email']);
492-
$this->readmeGenerator->setReadmeValue($filePart, "{$key}_password", $adminCredentials['password']);
493-
$this->readmeGenerator->removeTag($filePart, "{$key}_credentials");
428+
$item['email'] = $adminCredentials['email'];
429+
$item['password'] = $adminCredentials['password'];
494430
}
495431

496-
$this->readmeGenerator->updateReadmeFile($filePart);
432+
if (!empty($this->adminCredentials)) {
433+
$this->readmeGenerator->credentialsItems['admin'] = [
434+
'title' => 'Default admin',
435+
'email' => $this->adminCredentials['email'],
436+
'password' => $this->adminCredentials['password'],
437+
];
438+
}
497439
}
498440

499441
protected function saveRenovateJSON(): void
@@ -585,6 +527,7 @@ protected function runMigrations(): void
585527
shell_exec('php artisan migrate --ansi --force');
586528
}
587529

530+
588531
protected function publishAdminMigration(array $adminCredentials, ?string $serviceKey): void
589532
{
590533
$migrationName = (empty($serviceKey)) ? 'add_default_admin' : "add_{$serviceKey}_admin";

0 commit comments

Comments
 (0)