Browse Source

Update from v2

shalvah 4 years ago
parent
commit
cc0fe0aca2
2 changed files with 5 additions and 5 deletions
  1. 3 3
      src/Tools/Utils.php
  2. 2 2
      src/Writing/Writer.php

+ 3 - 3
src/Tools/Utils.php

@@ -94,9 +94,9 @@ class Utils
         throw new Exception("Couldn't get class and method names for route " . c::getRouteRepresentation($route) . '.');
     }
 
-    public static function deleteDirectoryAndContents(string $dir): void
+    public static function deleteDirectoryAndContents(string $dir, ?string $workingDir = null): void
     {
-        $adapter = new Local(getcwd());
+        $adapter = new Local($workingDir ?: getcwd());
         $fs = new Filesystem($adapter);
         $dir = ltrim($dir, '/');
         $fs->deleteDir($dir);
@@ -180,7 +180,7 @@ class Utils
 
     public static function getModelFactory(string $modelName, array $states = [])
     {
-        if (!function_exists('factory')) { // Laravel 8 type factory
+        if (method_exists($modelName, 'factory')) { // Laravel 8 type factory
             $factory = call_user_func_array([$modelName, 'factory'], []);
             if (count($states)) {
                 foreach ($states as $state) {

+ 2 - 2
src/Writing/Writer.php

@@ -156,7 +156,7 @@ class Writer
         if (!is_dir($this->laravelTypeOutputPath)) {
             mkdir($this->laravelTypeOutputPath, 0777, true);
         }
-        $publicDirectory = app()->get('public_path');
+        $publicDirectory = app()->get('path.public');
         if (!is_dir("$publicDirectory/vendor/scribe")) {
             mkdir("$publicDirectory/vendor/scribe", 0777, true);
         }
@@ -167,7 +167,7 @@ class Writer
 
         // Move assets from public/docs to public/vendor/scribe
         // We need to do this delete first, otherwise move won't work if folder exists
-        Utils::deleteDirectoryAndContents("$publicDirectory/vendor/scribe/");
+        Utils::deleteDirectoryAndContents("$publicDirectory/vendor/scribe/", "/");
         rename("{$this->staticTypeOutputPath}/", "$publicDirectory/vendor/scribe/");
 
         $contents = file_get_contents("$this->laravelTypeOutputPath/index.blade.php");