Skip to content

Commit

Permalink
Renamed docsname to pathConfig.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArclightHub committed Nov 27, 2023
1 parent b9422ca commit 5cfb911
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
10 changes: 5 additions & 5 deletions src/Extracting/ApiDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ class ApiDetails
private array $lastKnownFileContentHashes = [];

/**
* @param PathConfig $docsName
* @param PathConfig $pathConfig
* @param DocumentationConfig|null $config
* @param bool $preserveUserChanges
*/
public function __construct(
PathConfig $docsName,
PathConfig $pathConfig,
DocumentationConfig $config = null,
bool $preserveUserChanges = true
bool $preserveUserChanges = true
) {
$this->markdownOutputPath = $docsName; //.scribe by default
$this->markdownOutputPath = $pathConfig; //.scribe by default
// If no config is injected, pull from global. Makes testing easier.
$this->config = $config ?: new DocumentationConfig(config($docsName));
$this->config = $config ?: new DocumentationConfig(config($pathConfig));
$this->baseUrl = $this->config->get('base_url') ?? config('app.url');
$this->preserveUserChanges = $preserveUserChanges;

Expand Down
12 changes: 6 additions & 6 deletions src/GroupedEndpoints/GroupedEndpointsFromCamelDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@

class GroupedEndpointsFromCamelDir implements GroupedEndpointsContract
{
protected PathConfig $docsName;
protected PathConfig $pathConfig;

public function __construct(PathConfig $docsName)
public function __construct(PathConfig $pathConfig)
{
$this->docsName = $docsName;
$this->pathConfig = $pathConfig;
}

public function get(): array
{
if (!is_dir(Camel::camelDir($this->docsName))) {
if (!is_dir(Camel::camelDir($this->pathConfig))) {
throw new \InvalidArgumentException(
"Can't use --no-extraction because there are no endpoints in the " . Camel::camelDir($this->docsName) . " directory."
"Can't use --no-extraction because there are no endpoints in the " . Camel::camelDir($this->pathConfig) . " directory."
);
}

return Camel::loadEndpointsIntoGroups(Camel::camelDir($this->docsName));
return Camel::loadEndpointsIntoGroups(Camel::camelDir($this->pathConfig));
}

public function hasEncounteredErrors(): bool
Expand Down
26 changes: 13 additions & 13 deletions src/Writing/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Writer
* The "name" of this docs instance. By default, it is "scribe".
* Used for multi-docs.
*/
public PathConfig $docsName;
public PathConfig $pathConfig;

private DocumentationConfig $config;

Expand All @@ -41,21 +41,21 @@ class Writer

private string $laravelAssetsPath;

public function __construct(DocumentationConfig $config = null, PathConfig $docsName)
public function __construct(DocumentationConfig $config = null, PathConfig $pathConfig)
{
$this->docsName = $docsName;
$this->pathConfig = $pathConfig;

// If no config is injected, pull from global, for easier testing.
$this->config = $config ?: new DocumentationConfig(config($docsName->getScribeConfigFile()));
$this->config = $config ?: new DocumentationConfig(config($pathConfig->getScribeConfigFile()));

$this->isStatic = $this->config->get('type') === 'static';
$this->markdownOutputPath = $docsName; //.scribe by default
$this->markdownOutputPath = $pathConfig; //.scribe by default
$this->laravelTypeOutputPath = $this->getLaravelTypeOutputPath();
$this->staticTypeOutputPath = rtrim($this->config->get('static.output_path', 'public/docs'), '/');

$this->laravelAssetsPath = $this->config->get('laravel.assets_directory')
? '/' . $this->config->get('laravel.assets_directory')
: "/vendor/" . $this->docsName->getScribeConfigFile();
: "/vendor/" . $this->pathConfig->getScribeConfigFile();
}

/**
Expand Down Expand Up @@ -87,8 +87,8 @@ protected function writePostmanCollection(array $groups): void
$collectionPath = "{$this->staticTypeOutputPath}/collection.json";
file_put_contents($collectionPath, $collection);
} else {
Storage::disk('local')->put($this->docsName->getScribeConfigFile() . "/collection.json", $collection);
$collectionPath = Storage::disk('local')->path($this->docsName->getScribeConfigFile() . "/collection.json");
Storage::disk('local')->put($this->pathConfig->getScribeConfigFile() . "/collection.json", $collection);
$collectionPath = Storage::disk('local')->path($this->pathConfig->getScribeConfigFile() . "/collection.json");
}

c::success("Wrote Postman collection to: {$this->makePathFriendly($collectionPath)}");
Expand All @@ -106,8 +106,8 @@ protected function writeOpenAPISpec(array $parsedRoutes): void
$specPath = "{$this->staticTypeOutputPath}/openapi.yaml";
file_put_contents($specPath, $spec);
} else {
Storage::disk('local')->put($this->docsName->getScribeConfigFile() . "/openapi.yaml", $spec);
$specPath = Storage::disk('local')->path($this->docsName->getScribeConfigFile() . "/openapi.yaml");
Storage::disk('local')->put($this->pathConfig->getScribeConfigFile() . "/openapi.yaml", $spec);
$specPath = Storage::disk('local')->path($this->pathConfig->getScribeConfigFile() . "/openapi.yaml");
}

c::success("Wrote OpenAPI specification to: {$this->makePathFriendly($specPath)}");
Expand Down Expand Up @@ -181,8 +181,8 @@ protected function performFinalTasksForLaravelType(): void
// Rewrite asset links to go through Laravel
$contents = preg_replace('#href="\.\./docs/css/(.+?)"#', 'href="{{ asset("' . $this->laravelAssetsPath . '/css/$1") }}"', $contents);
$contents = preg_replace('#src="\.\./docs/(js|images)/(.+?)"#', 'src="{{ asset("' . $this->laravelAssetsPath . '/$1/$2") }}"', $contents);
$contents = str_replace('href="../docs/collection.json"', 'href="{{ route("' . $this->docsName->getScribeConfigFile() . '.postman") }}"', $contents);
$contents = str_replace('href="../docs/openapi.yaml"', 'href="{{ route("' . $this->docsName->getScribeConfigFile() . '.openapi") }}"', $contents);
$contents = str_replace('href="../docs/collection.json"', 'href="{{ route("' . $this->pathConfig->getScribeConfigFile() . '.postman") }}"', $contents);
$contents = str_replace('href="../docs/openapi.yaml"', 'href="{{ route("' . $this->pathConfig->getScribeConfigFile() . '.openapi") }}"', $contents);

file_put_contents("$this->laravelTypeOutputPath/index.blade.php", $contents);
}
Expand Down Expand Up @@ -229,7 +229,7 @@ protected function getLaravelTypeOutputPath(): ?string
{
if ($this->isStatic) return null;

return config('view.paths.0', function_exists('base_path') ? base_path("resources/views") : "resources/views") . "/" . $this->docsName->getScribeConfigFile();
return config('view.paths.0', function_exists('base_path') ? base_path("resources/views") : "resources/views") . "/" . $this->pathConfig->getScribeConfigFile();
}

/**
Expand Down

0 comments on commit 5cfb911

Please sign in to comment.