"Invention is not enough. Tesla invented the electric power we use, but he struggled to get it out to people. You have to combine both things: invention and innovation focus, plus the company that can commercialize things and get them to people"
– Larry Page
In this article written by Fernando J Miguel, author of the book Magento 2 Theme Design Second Edition, you will learn the process of sharing, code hosting, validating, and publishing your subject as well as future components (extensions/modules) that you develop for Magento 2.
(For more resources related to this topic, see here.)
The following topics will be covered in this article:
For every theme you develop for distribution in marketplaces and repositories through the sale and delivery of projects to clients and contractors of the service, you must follow some mandatory requirements for the theme to be packaged properly and consequently distributed to different Magento instances.
Magento uses the composer.json file to define dependencies and information relevant to the developed component. Remember how the composer.json file is declared in the Bookstore theme:
{
"name": "packt/bookstore",
"description": "BookStore theme",
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0",
"magento/theme-frontend-luma": "~100.0",
"magento/framework": "~100.0"
},
"type": "magento2-theme",
"version": "1.0.0",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [ "registration.php" ],
"psr-4": {
"Packt\BookStore\": ""
}
}
}
The main fields of the declaration components in the composer.json file are as follows:
The three main types of Magento 2 component declarations can be described as follows:
Besides the composer.json file that must be declared in the root directory of your theme, you should follow these steps to meet the minimum requirements for packaging your new theme:
From the minimum requirements mentioned, you already are familiar with the composer.json and registration.php files. Now we will look at the packaging process, validation, and publication in sequence.
By default, all themes should be compressed in ZIP format and contain only the root directory of the component developed, excluding any file and directory that is not part of the standard structure.
The following command shows the compression standard used in Magento 2 components:
zip -r vendor-name_package-name-1.0.0.zip package-path/* -x 'package-path/.git/*'
Here, the name of the ZIP file has the following components:
After formatting the component name, it defines which directory will be compressed, followed by the -x parameter, which excludes the git directory from the theme compression.
How about applying ZIP compression on the Bookstore theme? To do this, follow these steps:
Upon successfully executing this command, you will have packed your theme, and your directory will be as follows:
After this, you will validate your new Magento theme using a verification tool.
The Magento developer community created the validate_m2_package script to perform validation of components developed for Magento 2. This script is available on the GitHub repository of the Magento 2 development community in the marketplace-tools directory:
According to the description, the idea behind Marketplace Tools is to house standalone tools that developers can use to validate and verify their extensions before submitting them to the Marketplace.
Here's how to use the validation tool:
This command will validate the package you previously created with the ZIP command. If all goes well, you will not have any response from the command line, which will mean that your package is in line with the minimum requirements for publication.
If you wish, you can use the -d parameter that enables you to debug your component by printing messages during verification. To use this option, run the following command:
php validate_m2_package.php -d packt-bookstore-bookstore.1.0.0.zip
If everything goes as expected, the response will be as follows:
You can share your Magento theme and host your code on different services to achieve greater interaction with your team or even with the Magento development community. Remembering that the standard control system software version used by the Magento development community is Git.
There are some options well used in the market, so you can distribute your code and share your work. Let's look at some of these options.
The most common method of hosting your code/theme is to use GitHub. Once you have created a repository, you can get help from the Magento developer community if you are working on an open source project or even one for learning purposes.
The major point of using GitHub is the question of your portfolio and the publication of your Magento 2 projects developed, which certainly will make a difference when you are looking for employment opportunities and trying to get selected for new projects.
GitHub has a specific help area for users that provides a collection of documentation that developers may find useful. GitHub Help can be accessed directly at https://help.github.com/:
To create a GitHub repository, you can consult the official documentation, available at https://help.github.com/articles/create-a-repo/.
Once you have your project published on GitHub, you can use the Packagist (https://packagist.org/) service by creating a new account and entering the link of your GitHub package on Packagist:
Packagist collects information automatically from the available composer.json file in the GitHub repository, creating your reference to use in other projects.
In some cases, you will be developing your project for private clients and companies. In case you want to keep your version control in private mode, you can use the following procedure:
{
"repositories": [
{
"type": "composer",
"url": [repository url here]
}
]
}
According to Magento, Marketplace (https://marketplace.magento.com/) is the largest global e-commerce resource for applications and services that extend Magento solutions with powerful new features and functionality.
Once you have completed developing the first version of your theme, you can upload your project to be a part of the official marketplace of Magento. In addition to allowing theme uploads, Magento Marketplace also allows you to upload shared packages and extensions (modules).
To learn more about shared packages, visit http://docs.magento.com/marketplace/user_guide/extensions/shared-package-submit.html.
After the compression and validation processes, you can send your project to be distributed to Magento Marketplace.
For this, you should confirm an account on the developer portal (https://developer.magento.com/customer/account/) with a valid e-mail and personal information about the scope of your activities.
After this confirmation, you will have access to the extensions area at https://developer.magento.com/extension/extension/list/, where you will find options to submit themes and extensions:
After clicking on the Add Theme button, you will need to answer a questionnaire:
After the questionnaire, you will need to fill in the details of your extension, as follows:
The submitted theme will be evaluated by a technical review, and you will be able to see the evaluation progress through your e-mail and the control panel of the Magento developer area.
You can find more information about Magento Marketplace at the following link:
http://docs.magento.com/marketplace/user_guide/getting-started.html
In this article, you learned about the theme-packaging process besides validation according to the minimum requirements for its publication on Magento Marketplace.
You are now ready to develop your solutions! There is still a lot of work left, but I encourage you to seek your way as a Magento theme developer by putting a lot of study, research, and application into the area. Participate in events, be collaborative, and count on the community's support.
Good luck and success in your career path!
Further resources on this subject: