6 minutes reading time (1181 words)

JoRobo: How to professionally manage extension development

Maintaining Extensions

So you created your own Joomla extension, maybe for a client, maybe for general usage, and now you're wondering how to best manage it for the future. You will have to handle bugfixes, store it somehow, create releases and maybe improve it with new features. So how could we do this? There are several ways you can do this, but today I'd like to show you the one possible solution that works good for me.

Track your versions!

First things first: We want to have a proper storage for your extension. I hope I don't tell you something controversial when I point towards a version control system like git. Tracking all your changes is an absolute must, regardless if you are doing this for a customers site or want to publicly distribute your extension. In the most simplest form you can create a git repository just on your computer and track all changes in there, but using an external service with external servers like Github can be a lot more helpfull. First of all, they provide you an easy backup to your files, but they also offer a lot more features, which can be really helpfull. I'm not going to tout the horn for Github here, because you most likely all know the benefits of a tool like Github, but I'd like to ask you to consider Gitlab and maybe even self-hosting a Gitlab instance.

Folder structure

Now that we have a git repository where we can store it, the question remains how our folder structure in the repo should look like. Generally, we have some meta data, which we need to store for the extension, like a README, configurations for services we use, etc. Most often, these additional files are in the root of your repository and we don't exactly want to distribute them with our extension. So our extension code should be in a subfolder. Most commonly, people use a folder named /src for this.
Now, if we were creating a component, we could create a folder /com_foo in there and inside that folder have folders /admin and /site for the two parts and for plugins and modules we could have /plg_system_bar or /mod_fourtytwo, but while that allows for a quick overview of the different extensions in this repo and a minimum of folders to create, it means more work in the future. Instead I would advise to create the folders similar to where the extension would end up in the Joomla installation. For a component it would mean that you have an /administrator/components/com_foobar and a /components/com_foobar folder in your repository. The benefit is, that you can copy your /src folder over a Joomla installation and automatically have everything in the right place. That way you can easily install the extension during development by running "Discover" in the backend.

Make it usable in everyday work

But how do we write our code in the real world now? Yes, we have a good folder structure, but development is still cumbersome, because so far we are copying the files manually from the repository to the Joomla installation, maybe develop in that installation and then copy the files back to the repository. This of course is prone for failures. Did you forget a file completely? Are all your files up-to-date with the repository? The magic word here is "symlink", linking the folders of your extension into a Joomla installation. The benefit is, that you can work on the files directly in your repository folder and they magically show up in your Joomla installation. No need to copy the files from A to B and back. There is just one downside to this and that is that your IDE wont see all the Joomla CMS files when you are developing in your repositories folder directly. To solve this, you can either symlink the /libraries folder of your Joomla into your repository or add the path to your Joomla installation as external dependency in your IDE.

JoRobo setup

We also have to find a way to create releases or installable packages from our extensions. Of course you can do this manually, but how tedious is it to generate maybe 10 installation packages from components, modules and plugins by hand and then packaging all of those again to a pkg extension. Cue the tool which lends this article its title: JoRobo. JoRobo is an addon for Robo.li, a task runner written in PHP. JoRobo brings a bunch of tasks specifically for Joomla development and the whole thing can be easily installed by running "composer require-dev joomla-projects/jorobo" in your repositories folder. Besides installing this tool, we also need a "RoboFile.php" in our repositories root folder, which contains the project-specific tasks or passes through the tasks from JoRobo for this project and a jorobo.ini with the configuration for this project. If you want a good starting point, you might want to use this Robofile.php from the new JED project: https://github.com/joomla-projects/Joomla-Extension-Directory/blob/main/RoboFile.php and the jorobo.ini from that project as well: https://github.com/joomla-projects/Joomla-Extension-Directory/blob/main/jorobo.dist.ini

JoRobo magic!

With that setup, we can now call "vendor/bin/robo map <target>" where <target> is the root folder of our Joomla installation and the script will generate all necessary symlinks for us. This works both on Linux and Windows, however with Windows your command prompt needs administrator privileges to work. JoRobo also allows you to create installable packages from your repository with the command "vendor/bin/robo build". When running that command in your repositories root folder, you will end up with a pkg extension in a /dist folder, ready to be installed the traditional way. That command not only copies files from everywhere, but it also fills out the extensions manifests with the right files when you are using placeholders. An example how this can be used can be seen here in our weblinks repository: https://github.com/joomla-extensions/weblinks/blob/master/src/administrator/components/com_weblinks/weblinks.xml

Even more features

Now that we can easily build installable packages, we might want to release them to the public. For that, we should ensure that we have copyright headers in all files and that we are using the right version in our @since tags. JoRobo has the command "headers" and "bump" for this.
JoRobo actually already has some history behind it and was dormant for some time, but development recently did pick up again and there are some interesting new features in the pipeline. As with all things Joomla, contributions are very welcome and if you are interested, feel free to have a look here: https://github.com/joomla-projects/jorobo

Is there more?

I personally like this collection of scripts very much, because it allowed me to work a lot more professionally. At the same time, this is by far not the end of all tools which you can use to improve the quality of your code. Checks for codestyle, static code analysis, unit- and system-tests are really helpfull if you want to ensure the best code for your customers. However going down that rabbit hole is for another time and until then I hope you have the time and opportunity to test out what has been proposed here.

Updating a Rather Complex Site To Joomla 5.0.0
Thank you George Wilson - the Great Migrator!


Already Registered? Login Here
No comments made yet. Be the first to submit a comment

By accepting you will be accessing a service provided by a third-party external to https://magazine.joomla.org/