Skip to content

Commit

Permalink
Check for changes in config file after run
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Sep 9, 2021
1 parent c5facda commit 3d451f5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Commands/GenerateDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Knuckles\Scribe\Tools\DocumentationConfig;
use Knuckles\Scribe\Tools\Globals;
use Knuckles\Scribe\Writing\Writer;
use Shalvah\Upgrader\Upgrader;

class GenerateDocumentation extends Command
{
Expand Down Expand Up @@ -47,6 +48,8 @@ public function handle(RouteMatcherInterface $routeMatcher, GroupedEndpointsFact
c::warn('Generated docs, but encountered some errors while processing routes.');
c::warn('Check the output above for details.');
}

$this->upgradeConfigFileIfNeeded();
}

public function isForcing(): bool
Expand Down Expand Up @@ -109,4 +112,32 @@ protected function mergeUserDefinedEndpoints(array $groupedEndpoints, array $use

return $groupedEndpoints;
}

protected function upgradeConfigFileIfNeeded(): void
{
$upgrader = Upgrader::ofConfigFile('config/scribe.php', __DIR__ . '/../../config/scribe.php')
->dontTouch('routes','example_languages', 'database_connections_to_transact', 'strategies');
$changes = $upgrader->dryRun();
if (!empty($changes)) {
$this->newLine();
sleep(0.4);
$this->warn("You're using an updated version of Scribe, which added new items to the config file.");
$this->info("Here are the changes:");
foreach ($changes as $change) {
$this->info($change["description"]);
}

if (!$this->input->isInteractive()) {
$this->info("Run `php artisan scribe:upgrade` from an interactive terminal to update your config file automatically.");
$this->info(sprintf("Or see the full changelog at: https://github.com/knuckleswtf/scribe/blob/%s/CHANGELOG.md,", Globals::SCRIBE_VERSION));
return;
}

if ($this->confirm("Let's help you update your config file. Accept changes?")) {
$upgrader->upgrade();
$this->info(sprintf("✔ Updated. See the full changelog: https://github.com/knuckleswtf/scribe/blob/%s/CHANGELOG.md", Globals::SCRIBE_VERSION));
}
}

}
}

0 comments on commit 3d451f5

Please sign in to comment.