Tutorial on Using Bash Script for Magento 2 Themes Management

Each Magento developer certainly came up against the situation when he/she wanted to install or change something on Magento and it took a lot of time and efforts. In some cases, he/ she was forced to reproduce the whole process from very beginning. And our developers are not exception. When one of them was creating a custom theme for Magento 2 website, he wanted to simplify somehow this process. He decided to develop a Bash script that will streamline the process. We want to share the information about his work with you and hope that our tutorial on script implementation will help you to cope with all possible challenges:
Script implementation process
Firstly, you need to download the zip or copy it from Github repository into your Magento 2 project root:
git clone git@github.com:dvrgoc/magento2-theme-manager.git |
After that, you have to open terminal from the root of your Magento 2 project and run this command in order to start the script:
bash magento2-theme-manager.sh |
So, when the script is running, you can enter one of these numbers:
Create a new theme
When a user has already selected one time, he/she will be suggested to type in the next order:
- Vendor name;
- Theme name;
- Theme title (you will see it in Admin);
- Local setting;
- User’s password - to set the owner and group of the created files.
The script will generate a small LESS file (sam-ecommerce.less) that will be put together into CSS file during static files will be being deployed. Below, you can see its content:
@sam-ecommerce-green: #79AD36; body { background-color: @sam-ecommerce-green !important; } |
Now, it is time to open Grunts theme.js file and insert the code presented below:
Please, do not forget to open Admin Dashboard and check if the theme is visible under Content -> Themes.
And when you know that everything is ok, it is time to run the next commands. They will allow you to make sure that your theme is compilable by Grunt and deployable by Magento:
grunt clean grunt exec:ParentTheme php bin/magento cache:clean php bin/magento setup:static-content:deploy |
Below, there is an output of:
‘grunt exec’ command
static content deployment
Then, you can find the compiled sam-ecommerce.css file in app/design/frontend/YourVendor/YourTheme/YourLocale/css folder:
body{background-color:#79ad36 !important} |
Create a child theme
In order to do it, user has to enter valid MySql credentials.
A user will be suggested to enter a number of the theme that will become parent theme to his/her theme. Our developer entered number 24 and the process of creating a theme was the same as creating a new theme.
Delete a theme
As with child theme creation, user needs to enter valid MySql credentials, then the script will connect to database. And after, all of the registered themes will be listed. You have to delete all child themes! And if you do not do that, you will see an error.
To sum up, I would like just say that we hope our work experience will help you to prepare your theme for deployment. If you have some additional questions, our team of Magento developers is always ready to help you! Contact us right away, and we will provide you with all information you need! Read more about Magento 2 here: