diff --git a/src/Commands/GenerateDocumentation.php b/src/Commands/GenerateDocumentation.php index f3888ba8..1668dd1a 100644 --- a/src/Commands/GenerateDocumentation.php +++ b/src/Commands/GenerateDocumentation.php @@ -24,8 +24,8 @@ class GenerateDocumentation extends Command {--force : Discard any changes you've made to the YAML or Markdown files} {--no-extraction : Skip extraction of route and API info and just transform the YAML and Markdown files into HTML} {--no-upgrade-check : Skip checking for config file upgrades. Won't make things faster, but can be helpful if the command is buggy} - {--config=scribe : choose which config file to use} - {--cache-dir= : choose which cache directory to use} + {--config=scribe : Choose which config file to use} + {--scribe-dir= : Specify the directory where Scribe stores its intermediate output and cache. Defaults to `.`} "; protected $description = 'Generate API documentation from your Laravel/Dingo routes.'; @@ -106,9 +106,9 @@ public function bootstrap(): void } $this->paths = new PathConfig(configName: $configName); - if ($this->hasOption('cache-dir') && !empty($this->option('cache-dir'))) { + if ($this->hasOption('scribe-dir') && !empty($this->option('scribe-dir'))) { $this->paths = new PathConfig( - configName: $configName, cacheDir: $this->option('cache-dir') + configName: $configName, scribeDir: $this->option('scribe-dir') ); } diff --git a/src/Configuration/PathConfig.php b/src/Configuration/PathConfig.php index c0330054..1c63f4c3 100644 --- a/src/Configuration/PathConfig.php +++ b/src/Configuration/PathConfig.php @@ -9,11 +9,13 @@ class PathConfig { public function __construct( public string $configName = 'scribe', - protected ?string $cacheDir = null + // FOr lack of a better name, we'll call this `scribeDir`. + // It's sort of the cache dir, where Scribe stores its intermediate outputs. + protected ?string $scribeDir = null ) { - if (is_null($this->cacheDir)) { - $this->cacheDir = ".{$this->configName}"; + if (is_null($this->scribeDir)) { + $this->scribeDir = ".{$this->configName}"; } } @@ -37,9 +39,9 @@ public function configFileName(): string public function intermediateOutputPath(string $resolvePath = null, string $separator = '/'): string { if (is_null($resolvePath)) { - return $this->cacheDir; + return $this->scribeDir; } - return "{$this->cacheDir}{$separator}{$resolvePath}"; + return "{$this->scribeDir}{$separator}{$resolvePath}"; } } diff --git a/tests/GenerateDocumentation/OutputTest.php b/tests/GenerateDocumentation/OutputTest.php index 05b8d227..2c8d1130 100644 --- a/tests/GenerateDocumentation/OutputTest.php +++ b/tests/GenerateDocumentation/OutputTest.php @@ -140,81 +140,53 @@ public function generates_laravel_type_output() /** @test */ public function supports_multi_docs_in_laravel_type_output() { - $this->supports_base_test(["--config" => "scribe_admin"], '.scribe_admin'); + $this->generate_with_paths(configName: "scribe_admin"); } /** @test */ - public function supports_separate_hidden_cache_directory() + public function supports_custom_scribe_directory() { - $this->supports_base_test([ - "--config" => "scribe_admin", - "--cache-dir" => ".scribe_admin_dir" - ], '.scribe_admin_dir'); + $this->generate_with_paths(configName: "scribe_admin", intermediateOutputDirectory: '5.5/Apple/26'); } - /** @test */ - public function supports_separate_non_hidden_cache_directory() - { - $this->supports_base_test([ - "--config" => "scribe_admin", - "--cache-dir" => "scribe_admin_dir" - ], 'scribe_admin_dir'); - } - - /** @test */ - public function supports_unrelated_temp_directory() - { - $this->supports_base_test([ - "--config" => "bananas_are_good", - "--cache-dir" => "5.5/Apple/26" - ], '5.5/Apple/26'); - } - - /** - * Base test for - * - supports_multi_docs_in_laravel_type_output - * - supports_separate_hidden_cache_directory - * - supports_separate_non_hidden_cache_directory - * - supports_unrelated_temp_directory - * - * @param $generate - * @param $assertDir - * @return void - */ - private function supports_base_test($generate, $assertDir) + private function generate_with_paths($configName, $intermediateOutputDirectory = null) { RouteFacade::post('/api/withQueryParameters', [TestController::class, 'withQueryParameters']); - config([$generate['--config'] => config('scribe')]); + config([$configName => config('scribe')]); $title = "The Real Admin API"; - config([$generate['--config'] . '.title' => $title]); - config([$generate['--config'] . '.type' => 'laravel']); - config([$generate['--config'] . '.postman.enabled' => true]); - config([$generate['--config'] . '.openapi.enabled' => true]); - - $output = $this->generate($generate); + config(["{$configName}.title" => $title]); + config(["{$configName}.type" => 'laravel']); + config(["{$configName}.postman.enabled" => true]); + config(["{$configName}.openapi.enabled" => true]); + + $pathOptions = ["--config" => $configName]; + if ($intermediateOutputDirectory) { + $pathOptions["--scribe-dir"] = $intermediateOutputDirectory; + } + $output = $this->generate($pathOptions); $this->assertStringContainsString( - "Wrote Blade docs to: vendor/orchestra/testbench-core/laravel/resources/views/" . $generate['--config'], $output + "Wrote Blade docs to: vendor/orchestra/testbench-core/laravel/resources/views/{$configName}", $output ); $this->assertStringContainsString( - "Wrote Laravel assets to: vendor/orchestra/testbench-core/laravel/public/vendor/" . $generate['--config'], $output + "Wrote Laravel assets to: vendor/orchestra/testbench-core/laravel/public/vendor/{$configName}", $output ); $this->assertStringContainsString( - "Wrote Postman collection to: vendor/orchestra/testbench-core/laravel/storage/app/" . $generate['--config'] . "/collection.json", $output + "Wrote Postman collection to: vendor/orchestra/testbench-core/laravel/storage/app/{$configName}/collection.json", $output ); $this->assertStringContainsString( - "Wrote OpenAPI specification to: vendor/orchestra/testbench-core/laravel/storage/app/" . $generate['--config'] . "/openapi.yaml", $output + "Wrote OpenAPI specification to: vendor/orchestra/testbench-core/laravel/storage/app/{$configName}/openapi.yaml", $output ); $paths = collect([ - Storage::disk('local')->path( $generate['--config'] . '/collection.json'), - Storage::disk('local')->path($generate['--config'] . '/openapi.yaml'), - View::getFinder()->find($generate['--config'] . '/index'), + Storage::disk('local')->path("{$configName}/collection.json"), + Storage::disk('local')->path("{$configName}/openapi.yaml"), + View::getFinder()->find("{$configName}/index"), ]); $paths->each(fn($path) => $this->assertFileContainsString($path, $title)); $paths->each(fn($path) => unlink($path)); - $this->assertDirectoryExists($assertDir); - Utils::deleteDirectoryAndContents($assertDir); + $this->assertDirectoryExists($intermediateOutputDirectory ?: ".{$configName}"); + Utils::deleteDirectoryAndContents($intermediateOutputDirectory ?: ".{$configName}"); } /** @test */ diff --git a/tests/Unit/PathConfigurationTest.php b/tests/Unit/PathConfigurationTest.php index 3b1d59b6..4a84e76b 100644 --- a/tests/Unit/PathConfigurationTest.php +++ b/tests/Unit/PathConfigurationTest.php @@ -30,7 +30,7 @@ public function resolves_cache_path_with_subdirectories() /** @test */ public function supports_custom_cache_path() { - $pathConfig = new PathConfig('scribe/bob', cacheDir: 'scribe_cache'); + $pathConfig = new PathConfig('scribe/bob', scribeDir: 'scribe_cache'); $this->assertEquals('scribe_cache', $pathConfig->intermediateOutputPath()); $this->assertEquals('scribe_cache/tim', $pathConfig->intermediateOutputPath('tim')); $this->assertEquals('scribe/bob', $pathConfig->outputPath());