If you ever published a Magento module as open source, you know that there’s a lot more to it than making its code public. For many small modules making it ready for the public is more work than actually writing the code. At least if you want it to be presentable and as useful as possible.
What am I talking about? An abbreviated checklist:
- Add a license
- Write a readme file with brief documentation, installation instructions and contribution guidelines
- Create a composer.json file with dependencies according to the supported Magento version and required core modules
- Add a changelog
- Add configuration and scripts to run tests and code quality checks automatically, e.g. on Travis CI and Scrutinizer, connect these services
- Add git hooks for automatic code quality checks immediately when a contributor commits code
- Publish the package to packagist.org for composer
- Add a .gitattributes file to exclude test and dev files in releases for composer
Unfortunately this can be a pretty high barrier of entry, especially scripts to run tests automatically which need a fully functional Magento installation (integration tests, API tests, MFTF functional tests). You may have a working example to copy from but then there’s many places to make adjustments and more often than not one ends up with something like a wrong module name in installation instructions or license.
To decrease this barrier of entry as far as possible, I’ve created a GitHub repository template (What’s a repository template?) which not only serves as an example with everything you need to get started, but also contains a script to replace all placeholders in it with actual values for your module.
Here’s how it looks:
You see that most of the values are “guessed” based on the URL of the GitHub repository and your local Git user configuration, you only need to type them in if the guessed defaults are not correct. Next, you specify which Magento versions you want to support, and the script starts to replace all placeholders accordingly:
The next steps are not automated but you will receive clear instructions:
I hope you’re as excited as I am to contribute back to the ecosystem! Finally, here comes the link:Use this template
(click the button to create your own repository based on the template)
And as an example, here’s the first repository that I created based on the template: https://github.com/integer-net/magento2-rewritemap
The template itself is completely open to use (WTFPL license), only the initialization script in the dev directory is under MIT, so you can derivate from it as you want as long as the copyright notice and license is included “in all copies or substantial portions of the Software”. Feel free to use a different license for any module based on the template, for example Beerware or Postcardware!
You don’t want colors in the terminal? Run
You want even more colors? Run
Those options do not affect the generated template.
The initialization script is written in PHP based on Erika Heidi’s awesome MiniCLI, a dependency free CLI framework. If you have ideas how to improve the script, the template itself, or want to contribute code, please create an issue in the template repository.
Author: Fabian Schmengler
Fabian Schmengler is Magento developer and trainer at integer_net. His focus lies in backend development, conceptual design and test automation.
Fabian was repeatedly selected as a Magento Master in 2017 and 2018 based on his engagements, active participation on StackExchange and contributions to the Magento 2 core.