Giter Site home page Giter Site logo

Laravel type doesn't work about scribe HOT 9 CLOSED

knuckleswtf avatar knuckleswtf commented on August 23, 2024 1
Laravel type doesn't work

from scribe.

Comments (9)

b0rt avatar b0rt commented on August 23, 2024 1

I can confirm for 'dev-master'

/var/www$ php artisan scribe:generate --no-extraction
🔊 info Generating API HTML code

   ErrorException

  file_get_contents(resources/views/scribe/index.blade.php): failed to open stream: No such file or directory

  at vendor/knuckleswtf/scribe/src/Writing/Writer.php:198
    194|         // We need to do this delete first, otherwise move won't work if folder exists
    195|         Utils::deleteDirectoryAndContents("public/vendor/scribe/", getcwd());
    196|         rename("{$this->outputPath}/", "public/vendor/scribe/");
    197|
  > 198|         $contents = file_get_contents("$this->outputPath/index.blade.php");
    199|
    200|         // Rewrite links to go through Laravel
    201|         $contents = preg_replace('#href="css/(.+?)"#', 'href="{{ asset("vendor/scribe/css/$1") }}"', $contents);
    202|         $contents = preg_replace('#src="(js|images)/(.+?)"#', 'src="{{ asset("vendor/scribe/$1/$2") }}"', $contents);

      +18 vendor frames
  19  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

removing / commenting L195 and L196 in Writer.php

   protected function performFinalTasksForLaravelType(): void
    {
        // Make output a Blade view
        if (!is_dir($this->outputPath)) {
            mkdir($this->outputPath);
        }

        rename("{$this->outputPath}/index.html", "$this->outputPath/index.blade.php");
        // 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("public/vendor/scribe/", getcwd());
        // rename("{$this->outputPath}/", "public/vendor/scribe/");

the generation proceeds

/var/www$ php artisan scribe:generate --no-extraction
🔊 info Generating API HTML code
👍 success Wrote HTML documentation to: resources/views/scribe

Another way would be to get contents first and then rename / move the assets
and befor writing the final file create the directory (resources/views/scribe) again

   protected function performFinalTasksForLaravelType(): void
    {
        // Make output a Blade view
        if (!is_dir($this->outputPath)) {
            mkdir($this->outputPath);
        }

        rename("{$this->outputPath}/index.html", "$this->outputPath/index.blade.php");
        $contents = file_get_contents("$this->outputPath/index.blade.php");
        // 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("public/vendor/scribe/", getcwd());
        rename("{$this->outputPath}/", "public/vendor/scribe/");


        // Rewrite links to go through Laravel
        $contents = preg_replace('#href="css/(.+?)"#', 'href="{{ asset("vendor/scribe/css/$1") }}"', $contents);
        $contents = preg_replace('#src="(js|images)/(.+?)"#', 'src="{{ asset("vendor/scribe/$1/$2") }}"', $contents);
        $contents = str_replace('href="./collection.json"', 'href="{{ route("scribe.json") }}"', $contents);

        if (!is_dir($this->outputPath)) {
            mkdir($this->outputPath);
        }

        file_put_contents("$this->outputPath/index.blade.php", $contents);
    }

from scribe.

shalvah avatar shalvah commented on August 23, 2024 1

Thanks for the detailed report! I was able to recognise and fix the actual issue. This means I won't be merging your PR, as the complete fix was more involved than that. You can view it here. Please confirm by switching to version 1.0.0-beta2 and see if it works well.

from scribe.

shalvah avatar shalvah commented on August 23, 2024

Writer paths have errors in them, so generating doesn't work
Config laravel.url should be laravel.docs_url

You definitely need to share more details about these. Also, did you follow the migration guide?

from scribe.

tomcoonen avatar tomcoonen commented on August 23, 2024

I know this is minimal, but I lack the time now. I fixed the issues locally to see what the problem was.

It just misses files at locations in the Writer.

from scribe.

shalvah avatar shalvah commented on August 23, 2024

Have you tried switching to dev-master?

from scribe.

ernst77 avatar ernst77 commented on August 23, 2024

Can confirm :) this issue is happening to me as well...
Blade is being generated in the same folder and then is moved to public dir and then it's trying to access old dir before it was moved.
Please merge the pull request

from scribe.

shalvah avatar shalvah commented on August 23, 2024

Make that 1.0.0-beta3. 🤦‍♂️

from scribe.

b0rt avatar b0rt commented on August 23, 2024

Hey @shalvah I can confirm that 1.0.0-beta3 resolves the issue for the file saving.
Thank you for the fast response!
And thank you for taking the time to explain the closing of the PR.🙏
I suspected the PR would be a sloppy solution and that I was probably missing some complexity.

from scribe.

tomcoonen avatar tomcoonen commented on August 23, 2024

Thanks for fixing!

from scribe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.