Published on 27-12-2019 Latest update on 22-01-2020
A companion application to Dockerhero for easy and quick local development.
As a developer there a quite a few steps to get up and running with a project.
If you start from scratch you might have to clone the repository, create the database, the database user and prepare the .env file.
Next, you might to install the dependencies, migrate the database, run seeders, compile assets and any other custom commands you have for your project.
Sometimes you forget to do a step and run into errors. For example a missing column because you forgot to migrate.
I always enjoy solving my own problems and make my life easier. So I decided to play around with a new project that I discovered, Laravel Zero, to see if I could build something that could solve my need for easy project bootstrapping.
Laravel Zero is a micro-framework for console applications. Built on top of the Laravel components. So perfect for what I am trying to build.
The initial setup
This is the most hard-coded part of Hero CLI. The
setup:project command is used if you are working on a project for the first time. It will prepare the environment file for you, based on the
.env.example and prepare the entire database.
It was a bit tricky to build this command (and it feels like to most "hacky" piece of Hero CLI to be honest). It parses the .env of the project you want to setup using
dotenv and executes a bunch of
mysql commands inside of Dockerhero to realize this.
For the commands, I wanted to make something that was customizable. I wanted to avoid as much hardcoded project logic as possible. Even though, at the time, I was not planning on making the application open source, I just did not want to dive into the code if something changed. So I came up with the idea for a "recipe". A recipe, just like the cooking one, defines what needs to be done. In our case for a certain development task.
For example, if you want to "update" a project you might want to:
- Install composer dependencies
- Migrate the database
- Generate IDE-helpers
- Export translations to a JS file
- Build assets
.yml file made the most sense to me to define how to actually perform those steps. And this is the end result of a Hero CLI recipe:
update: - command: "composer install" environment: docker - command: "./artisan migrate" environment: docker - command: "./artisan ide-helper:generate" environment: docker - command: "./artisan ide-helper:meta" environment: docker - command: "./artisan custom:export-translations-js" environment: docker - command: "yarn dev" environment: local
So when you execute:
hero recipe update my-project it will execute all those tasks for the
Because Hero CLI is tightly integrated with Dockerhero, you only have to tell Hero CLI you want it executed into docker and it will take care of the rest.
You can also make an additional update-fresh recipe that will, instead of a
migrate will perform a
You can add as many recipes as you want to the recipe file.
For more information on how to set everything up and what you can do with Hero CLI, you can visit the project on GitHub.
Subscribe For Updates
Would you like to receive an update when I release something new or when I have something to announce?
Simply fill in the form below with your name and email address, submit it, and I will send you an email!
If you change your mind later, no problem! In each email there will be an unsubscribe link.
I am a full-stack developer (for some reason full-stack developers are called Unicorns...) from the Netherlands and started programming when I was 12 years old. The first programming language I learned was Visual Basic. I have always loved bringing my thoughts and ideas to the computer screen.
After finishing high school I knew that I wanted to make my living by programming. So I choose an "Application Development" study. When I completed my internship, I started working full-time making websites and web applications. The language I was writing in at the time was ASP Classic.
ASP Classic; however, was quickly overshadowed by PHP and I decided to switch to that programming language instead. In the beginning I was making my own "mini frameworks" for projects I was working on, but quickly switched to CodeIgniter.
Luckily, after a few months, I discovered a framework called Laravel. And up until this day I still use Laravel as my PHP framework of choice. It just gives you so much features out of the box, it becomes trivial to quickly set up a proof-of-concept. And is also powerful and flexible enough to transform that proof-of-concept in a future-proof, stable and secure application.