Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make directory recursive #829

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Tools/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Routing\Route;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Knuckles\Scribe\Exceptions\CouldntFindFactory;
use Knuckles\Scribe\Exceptions\CouldntGetRouteDetails;
Expand Down Expand Up @@ -191,6 +192,11 @@ public static function copyDirectory(string $src, string $dest): void
}
}

public static function makeDirectoryRecursive(string $dir): void
{
File::isDirectory($dir) || File::makeDirectory($dir, 0777, true, true);
}

public static function deleteFilesMatching(string $dir, callable $condition): void
{
if (class_exists(LocalFilesystemAdapter::class)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Writing/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Knuckles\Scribe\Writing;

use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Knuckles\Scribe\Tools\ConsoleOutputUtils as c;
use Knuckles\Scribe\Tools\DocumentationConfig;
use Knuckles\Scribe\Tools\Globals;
Expand Down Expand Up @@ -96,6 +95,7 @@ protected function writeOpenAPISpec(array $parsedRoutes): void

$spec = $this->generateOpenAPISpec($parsedRoutes);
if ($this->isStatic) {
Utils::makeDirectoryRecursive($this->staticTypeOutputPath);
$specPath = "{$this->staticTypeOutputPath}/openapi.yaml";
file_put_contents($specPath, $spec);
} else {
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/UtilsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Knuckles\Scribe\Tests\Unit;

use Knuckles\Scribe\Tests\BaseLaravelTest;
use Knuckles\Scribe\Tools\Utils;

class UtilsTest extends BaseLaravelTest
{
/** @test */
public function make_directory_recursive()
{
$dir = __DIR__ . '/test_dir';
Utils::makeDirectoryRecursive($dir);
$this->assertDirectoryExists($dir); // Directory exists

if (rmdir($dir)) { // Remove the directory
dump("Directory deleted successfully: $dir");
} else { // If deletion fails, you can handle the error as needed
dump("Failed to delete directory: $dir");
}
}
}
Loading