Using derry to manage scripts on your Flutter project

Rodrigo Bastos
3 min readOct 29, 2021

--

One of the things I miss while developing in Flutter is somewhere where I can declare my project’s scripts. Something like the “scripts” section of a file like package.json so well known in Javascript projects.

You can even declare some scripts in the “scripts” tag of your pubspec.yaml, but nothing very sophisticated can be done there.

To fill this gap in project script management, an excellent option called derry was created. Derry is a robust script manager that manages all of your project’s scripts. With it, it is possible to configure the execution of all scripts necessary during the project’s life cycle, from linting scripts, code generation, build and deploy.

I’ll show you how to configure derry in your project later on and some great features that derry gives us.

First, you need to install derry. To install it, just run the following command:

pub global activate derry

Once installed you can run derry normally on your terminal. Give a derry -h to confirm that everything worked!

Once installed, you need to add a file called derry.yaml in the root of your project, besides that you need to inform your project that this file will be the one that will declare the possible commands that will be used. All of this can be done by adding the scripts section: derry.yaml to your pubspec.yaml file.

Once this is done, just start declaring the desired commands inside your derry.yaml file.

Let’s start simple, first let’s create a command to run our project. To do this just add:

Once that’s done, we just have to run it in our terminal and the flutter run command will be executed.

derry runFlutter

From that point we can do something more interesting.

Imagine the following scenario, let’s say we need to configure scripts to run our project on several platforms and for several different environments (dev, homolog and prod). It’s from solving scenarios like this that we realize how much derry can help us.

Let’s tackle the problem of configuring for multiple platforms first. Well, we can easily solve this with the following configuration.

After that, we just use derry linux, to run on linux, derry mobile for mobile and derry web, for web. Very simple isn’t it? But the best part is yet to come.

Derry allows us to cascade scripts, so I can configure something like this:

With this, we can easily configure multiple platforms in many different environments. I can for example run flutter mobile, in dev environment.

derry run mobile dev

The above command does just that. Derry is smart enough to understand this syntax and look for the correct command to run. In this scenario you can for example configure your various environments for each specific environment and derry with a command will help you run that.

In addition to these uses already shown, I use derry in another context in my projects. Another interesting example of using derry is in the code generation part. I can create the following configuration:

This way I can easily run the build runner with the desired configuration (build or watch).

derry run codegen watch

We can improve our previous setup. Derry allows us to store commands in variables. So we can improve our previous script as follows:

We store the value of the build_runner run command in a variable and reference this variable later.

Finally, and not least, derry allows us from a script input, to execute several commands. This is very useful in steps like running tests or deploying applications.

The example I bring is the execution of the tests, with the creation of the coverage report. We can do this easily with derry with the following configuration:

And to run:

derry tests

So that’s it for today guys, derry helped me and still helps me a lot in setting up my projects. It came to fill this gap that Flutter in my opinion is not that good yet. I hope you enjoyed it and hope you also use derry :).

The complete example derry file created can be seen below:

See you next time!

--

--

Rodrigo Bastos
Rodrigo Bastos

Written by Rodrigo Bastos

Technology addicted. Flutter advocate!

No responses yet