Skip to content

Some package scripts and styles are missing when retrieving in a command #3506

@atmediauk

Description

@atmediauk
  • Laravel Version: 8.54.0
  • Nova Version: v3.27.0
  • PHP Version: 7.4.11
  • Database Driver & Version: 10.5.6-MariaDB Homebrew
  • Operating System and Version: MacOS 11.5.1
  • Browser type and version: Brave V1.28.105

Description:

When trying to obtain a list of all assets using Nova::allScripts & Nova::allStyles in a console command not all the items are included. Specifically tool assets are not found.

Detailed steps to reproduce the issue on a fresh Nova installation:

  • Create a tool with assets
  • Create a command with something like:
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Http\Request;
use Laravel\Nova\Nova;

use Illuminate\Support\Facades\Auth;

use App\Models\User;

class CombineNovaTools extends Command
{
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Combines all nova package scripts and styles';

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'combine:nova-tools';

    /**
     * Create a new command instance.
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        Auth::login(User::where('role', '=', 'Admin')->first(), true); // change to a user with full access to nova

        $url = config('app.url') . '/dashboard';
        app()->handle(Request::create($url));

        $this->info('Combining nova package js and css');

        $this->combineTools();
    }

    private function combineTools(): void
    {
        $assets = [
            'allScripts' => 'js',
            'allStyles' => 'css',
            // 'themeStyles' => 'css',
        ];

        $list = [];
        foreach ($assets as $method => $type) {
            foreach (Nova::{$method}() as $file) {
                $this->info($file);
                $list[] = [
                    'type' => $type,
                    'file' => $file,
                ];
            }
        }
        
        dd($list);
        \file_put_contents(base_path('novatools.json'), json_encode($list));
    }
}

Most of the assets from cards etc are loaded successfully however neither the css or js are found for a nova tool.

As a test I also tried dd'ing Nova::AllScripts and Nova::AllStyles in a package and the missing tool assets were visible fine so I think this bug occurs within the console commands only.

Thank you for your time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions