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

Add --no-progress and --json options to mix:compile and mix:list #1087

Merged
merged 3 commits into from
Apr 4, 2024

Conversation

Nimdoc
Copy link
Contributor

@Nimdoc Nimdoc commented Mar 24, 2024

  • Add --no-progress option to mix:compile

This will suppress the mix progress output while allowing the webpack progress to be output.

  • Add --json to mix:list

This outputs the mix package information in a json format. Also instead of "yes" and "no" for the "active" property, with the --json option the values are true and false.

These additions will be useful for scripts or automation tools that need to parse information about mix packages and information for when they're compiled.

- Add --no-progress to mix:compile to suppress mix progress (not webpack progress)
- Add --json to mix:list to output mix packages in json format
modules/system/console/MixCompile.php Outdated Show resolved Hide resolved
modules/system/console/MixList.php Outdated Show resolved Hide resolved
modules/system/console/MixList.php Outdated Show resolved Hide resolved
modules/system/console/MixList.php Outdated Show resolved Hide resolved
- Update mix:compile command to hide Mixing message on silent option instead
- Update MixList.php to remove ternary for readability
- Update MixList.php to use Laravel output methods for compatibility

Co-authored-by: Ben Thomson <[email protected]>
@Nimdoc
Copy link
Contributor Author

Nimdoc commented Mar 25, 2024

@bennothommo Those are all good suggestions and I've made a commit with them all together.

I was a little worried about the silent option interfering with the output of webpack, because adding the silent option to mix:compile also adds --stats=none to the webpack command, and there are situations where the webpack output is wanted and not the mix output. But with php artisan mix:compile --silent -- stats=normal, the latter option overwrites the preceding one. So we end up with an overall webpack command like

/home/tom/projects/winter/node_modules/.bin/webpack build --stats=none --config=/home/tom/projects/winter/modules/backend/mix.webpack.js --stats=normal --json

And it all works out.

@bennothommo
Copy link
Member

@Nimdoc thanks for making those changes.

Conventionally, a silent flag means suppress all output. In general, this allows scripts and automated systems to use the command and simply check the exit code for success, so yes, we would want that flag to hide both the Mix and Webpack output.

The --no-progress flag, by its definition, should simply suppress the progress bar that shows when compiling the assets. It should still show the final stats.

As long as your PR does both of the above, I'll be happy to merge :)

- Update MixCompile.php and mix.webpack.js.fixture to separate the silent and no-progress flags.
@Nimdoc
Copy link
Contributor Author

Nimdoc commented Mar 27, 2024

@bennothommo I can confirm, that running just php artisan mix:compile --silent produces no output with these changes. The mix:compile command automatically puts --stats=none on the webpack command, and if someone desired they could override that (this was the behavior before, and hasn't changed). So yes, the --silent flag, without anything else to override it, is now completely silent with these changes. Would you prefer that the --silent flag override everything including what users may supply after the -- though? If so then we'd have to change the createCommand method from

    /**
     * Create the command array to create a Process object with
     */
    protected function createCommand(string $mixJsPath): array
    {
        $basePath = base_path();
        $command = $this->argument('webpackArgs') ?? [];
        array_unshift(
            $command,
            $basePath . sprintf('%1$snode_modules%1$s.bin%1$swebpack', DIRECTORY_SEPARATOR),
            'build',
            $this->option('silent') ? '--stats=none' : '--progress',
            '--config=' . $this->getWebpackJsPath($mixJsPath)
        );
        return $command;
    }

To something like

    /**
     * Create the command array to create a Process object with
     */
    protected function createCommand(string $mixJsPath): array
    {
        $basePath = base_path();
        
        $command = [];

        $command[] = $basePath . sprintf('%1$snode_modules%1$s.bin%1$swebpack', DIRECTORY_SEPARATOR);
        $command[] = 'build';
        $command = array_merge($command, $this->argument('webpackArgs') ?? []);
        $command[] = $this->option('silent') ? '--stats=none' : '--progress';
        $command[] = '--config=' . $this->getWebpackJsPath($mixJsPath);

        return $command;
    }

Move the user supply arguments to the middle so that the --stats=none argument overrides the user arguments.

What do you think? I prefer the current behavior with the current changes, letting users silence everything but then let some stuff through by adding webpack options on the end.


Also, I just made a couple changes to MixCompile.php and mix.webpack.js.fixture to suppress just the progress bar, but leave the final stats table output.

@bennothommo
Copy link
Member

@Nimdoc looks good to me! I doubt many people will use the silent flag alongside others that display things, but I don't mind that it would allow people to tailor their output as they see fit, so I have no problems with that at all.

@bennothommo
Copy link
Member

@LukeTowers @jaxwilko do you envisage any problems with the above?

@jaxwilko
Copy link
Member

@bennothommo I don't think there's any issues with it, happy to do some testing in the morning tho if needed :)

@bennothommo
Copy link
Member

That'd be awesome @jaxwilko :)

@LukeTowers
Copy link
Member

Any updates needed for the docs with this PR? Otherwise I'm happy to merge

@LukeTowers
Copy link
Member

nvm, found the PR :)

@LukeTowers LukeTowers changed the title Add -no-progress and --json options to mix:compile and mix:list respectively Add --no-progress and --json options to mix:compile and mix:list Apr 4, 2024
@LukeTowers LukeTowers merged commit 609ad74 into wintercms:develop Apr 4, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants