Is there a way to run bin/magento setup:static-content:deploy in a M2 script? or programatically? I have a scenario where in the CSS file is replaced within the admin panel. So I was thinking to automate the running of bin/magento setup:static-content:deploy without going to the terminal and manually running this command. Is there a way to achieve this? It's not only the bin/magento setup:static-content:deploy but also the bin/magento cache:clean
2 Answers
exec('bin/magento setup:di:compile');
exec('bin/magento cache:clean');
should get you what you need
Create Shell script.
Add bin/magento setup:di:compile
... command into shell script.
Then you can run this shell script using php file on any specific event on which you want run.
I hope this will help you.
setup:di:compile
generates php classes and doesn't relate to css. Probably you needsetup:static-content:deploy
. Forsetup:di:compile
you can call\Magento\Setup\Console\Command\DiCompileCommand::run
\Magento\Setup\Console\Command\DeployStaticContentCommand
and\Magento\Backend\Console\Command\CacheCleanCommand
as dependencies in your code and callrun
method to regenerate static files and clear the cache