|
@@ -11,6 +11,12 @@ use Symfony\Component\Yaml\Yaml;
|
|
|
|
|
|
class Writer
|
|
|
{
|
|
|
+ /**
|
|
|
+ * The "name" of this docs instance. By default, it is "scribe".
|
|
|
+ * Used for multi-docs.
|
|
|
+ */
|
|
|
+ public string $docsName;
|
|
|
+
|
|
|
private DocumentationConfig $config;
|
|
|
|
|
|
private bool $isStatic;
|
|
@@ -36,12 +42,14 @@ class Writer
|
|
|
|
|
|
public function __construct(DocumentationConfig $config = null, $docsName = 'scribe')
|
|
|
{
|
|
|
- // If no config is injected, pull from global. Makes testing easier.
|
|
|
+ $this->docsName = $docsName;
|
|
|
+
|
|
|
+ // If no config is injected, pull from global, for easier testing.
|
|
|
$this->config = $config ?: new DocumentationConfig(config($docsName));
|
|
|
|
|
|
$this->isStatic = $this->config->get('type') === 'static';
|
|
|
$this->markdownOutputPath = ".{$docsName}"; //.scribe by default
|
|
|
- $this->laravelTypeOutputPath = $this->getLaravelTypeOutputPath($docsName);
|
|
|
+ $this->laravelTypeOutputPath = $this->getLaravelTypeOutputPath();
|
|
|
$this->staticTypeOutputPath = rtrim($this->config->get('static.output_path', 'public/docs'), '/');
|
|
|
|
|
|
$this->laravelAssetsPath = $this->config->get('laravel.assets_directory')
|
|
@@ -78,8 +86,8 @@ class Writer
|
|
|
$collectionPath = "{$this->staticTypeOutputPath}/collection.json";
|
|
|
file_put_contents($collectionPath, $collection);
|
|
|
} else {
|
|
|
- Storage::disk('local')->put('scribe/collection.json', $collection);
|
|
|
- $collectionPath = 'storage/app/scribe/collection.json';
|
|
|
+ Storage::disk('local')->put("{$this->docsName}/collection.json", $collection);
|
|
|
+ $collectionPath = "storage/app/{$this->docsName}/collection.json";
|
|
|
}
|
|
|
|
|
|
c::success("Wrote Postman collection to: {$collectionPath}");
|
|
@@ -98,8 +106,8 @@ class Writer
|
|
|
$specPath = "{$this->staticTypeOutputPath}/openapi.yaml";
|
|
|
file_put_contents($specPath, $spec);
|
|
|
} else {
|
|
|
- Storage::disk('local')->put('scribe/openapi.yaml', $spec);
|
|
|
- $specPath = 'storage/app/scribe/openapi.yaml';
|
|
|
+ Storage::disk('local')->put("{$this->docsName}/openapi.yaml", $spec);
|
|
|
+ $specPath = "storage/app/{$this->docsName}/openapi.yaml";
|
|
|
}
|
|
|
|
|
|
c::success("Wrote OpenAPI specification to: {$specPath}");
|
|
@@ -218,11 +226,11 @@ class Writer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- protected function getLaravelTypeOutputPath(string $docsName): ?string
|
|
|
+ protected function getLaravelTypeOutputPath(): ?string
|
|
|
{
|
|
|
if ($this->isStatic) return null;
|
|
|
|
|
|
- return config('view.paths.0', "resources/views")."/$docsName";
|
|
|
+ return config('view.paths.0', "resources/views")."/$this->docsName";
|
|
|
}
|
|
|
|
|
|
}
|